Difference between revisions of "Getting Started/Build/Distributions/Debian/Source"

Jump to: navigation, search
(Getting started)
m (Text replace - "<code bash n>" to "<syntaxhighlight lang="bash" line>")
 
(22 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
== Introduction ==
 
== Introduction ==
  
This tutorial is intented for people who are using Debian, and want to check out or test some idea on KDE code without much setting up to do.
+
This tutorial is intented for people who are using Debian, and want to check out or test some idea on existing KDE code without much hassle.
  
This tutorial shows a way of easily downloading and compiling and running the necessary software.
+
This tutorial shows a way of easily downloading and compiling and running the KDE software that is used on your Debian system.
  
 
== Getting started ==
 
== Getting started ==
  
 
First you need to add the source repositories to your installation. This is normally done by editing {{Path | /etc/apt/sources.list}} as user root and adding a line starting with <tt>deb-src</tt>:
 
First you need to add the source repositories to your installation. This is normally done by editing {{Path | /etc/apt/sources.list}} as user root and adding a line starting with <tt>deb-src</tt>:
<code bash>
+
<syntaxhighlight lang="bash">
 
kdesudo kwrite /etc/apt/sources.list
 
kdesudo kwrite /etc/apt/sources.list
</code>  
+
</syntaxhighlight>  
  
 
The easy way is to copy your existing <tt>deb</tt> line onto a new line, and change <tt>deb</tt> to <tt>deb-src</tt>:  
 
The easy way is to copy your existing <tt>deb</tt> line onto a new line, and change <tt>deb</tt> to <tt>deb-src</tt>:  
  
<code bash n>
+
<syntaxhighlight lang="bash" line>
 
deb http://ftp.belnet.be/debian testing main contrib non-free
 
deb http://ftp.belnet.be/debian testing main contrib non-free
 
deb-src http://ftp.belnet.be/debian testing main contrib non-free #almost a copy of line 1
 
deb-src http://ftp.belnet.be/debian testing main contrib non-free #almost a copy of line 1
</code>
+
</syntaxhighlight>
 
   
 
   
 
In most(all?) of the cases this will work.  
 
In most(all?) of the cases this will work.  
Line 23: Line 23:
 
Then you must let this change know to the package manager, so do as root:
 
Then you must let this change know to the package manager, so do as root:
  
<code bash>aptitude update</code>
+
<syntaxhighlight lang="bash">aptitude update</syntaxhighlight>
  
 
== Setting up the dependencies ==
 
== Setting up the dependencies ==
  
Now you want to be able to build a certain package, and in this example we will build kcontrol and systemsettings so we can fix some bug in the "Display" configuration module, which is called "randr". In debian the package is "systemsettings", so we get the build dependencies of that package, so do as root "aptitude build-dep systemsettings". This will download and install all needed dependencies which are mostly packages with "-dev" at the end of them, which are a bunch of header files most of the time.
+
Now you want to be able to build a certain package, and in this example we will build the kcontrol configuration modules(aka KCM modules) and the application containing them called systemsettings. Let's say we want to see if we can maybe fix some bug in the Display configuration module, which is called <tt>randr</tt> actually. In debian the package is <tt>systemsettings</tt>, so first we will get the build dependencies of that package, so do as root:
  
== Getting the source ==
+
<syntaxhighlight lang="bash">aptitude build-dep systemsettings</syntaxhighlight>
  
Now in your home directory, make a new directory, and go into it:
+
This will download and install all needed dependencies which are some build tools and otherwise mostly packages with <tt>-dev</tt> at the end of them, which are in most cases a bunch of header files.
  
karel@pc:/home/karel # mkdir kde4devel
+
== Getting the source ==
karel@pc:/home/karel # cd kde4devel
+
  
Now we get the sources in this directory, as root, do:
+
As a regular user, create a new directory, and fetch the sources for the package:
 +
<syntaxhighlight lang="bash">
 +
mkdir ~/kde4devel
 +
cd ~/kde4devel
 +
apt-get source systemsettings
 +
</syntaxhighlight>
  
karel@pc:/home/karel/kde4devel # su
+
This downloads the source and applies all the debian patches for you. In this case, it downloads <tt>kdebase-workspace</tt> because the systemsettings code is only a small part of the kdebase-workspace package. Now go into the newly extracted directory. This is {{Path|kdebase-workspace-4.3.2}} in my case.
root@pc:/home/karel/kde4devel # apt-get source systemsettings
+
  
This downloads the source and applies all the debian patches. In this case, it downloads "kdebase-workspace" because the systemsettings code is only a small part of the kdebase-workspace package. Now go into the newly extracted directory . This is now "kdebase-workspace-4.3.2" in my case.
+
<syntaxhighlight lang="bash">
 +
cd kdebase-workspace-4.3.2
 +
</syntaxhighlight>
  
 
== Building the source ==
 
== Building the source ==
  
Now we go into the source directory, and let "cmake" generate the Makefiles, which are then used by the "make" command to build the code. But first we change the owner from root back to our user "karel". This is done like this:  
+
Now we go into the source directory, and let <tt>cmake</tt> generate the Makefiles, which are then used by the <tt>make</tt> command to build the code. This is done like this:  
  
root@pc:/home/karel/kde4devel/kdebase-workspace-4.3.2 # chown -R karel.karel ../*
+
<syntaxhighlight lang="bash">
root@pc:/home/karel/kde4devel/kdebase-workspace-4.3.2 # exit
+
cmake .     # don't forget the extra space+point!
karel@pc:/home/karel/kde4devel/kdebase-workspace-4.3.2 # cmake .
+
</syntaxhighlight>
karel@pc:/home/karel/kde4devel/kdebase-workspace-4.3.2 # cmake-gui .
+
  
Now select only the components starting with "BUILD_" you want. In my case it was rather the components I'm sure of that I don't want :). So I ended up with only BUILD_kcontrol and systemsettings. Then click on the "Configure" button and then on the "Generate" button. Close the program now. Now we have makefiles for everything we want to build. So now do the make command to build what we have selected:
+
Later we'll have to install the built files, you probably don't want to do this as root. So it is better to call <tt>cmake</tt> like this:
  
karel@pc:/home/karel/kde4devel/kdebase-workspace-4.3.2 # make
+
<syntaxhighlight lang="bash">
 +
cmake -DCMAKE_INSTALL_PREFIX=$HOME/kde4devel/root .
 +
</syntaxhighlight>
  
Now it is built!
+
<tt>cmake</tt> supports a nice Qt GUI to configure your build process.  If you have the package <tt>cmake-qt-gui</tt> installed, you can replace <tt>cmake</tt> with <tt>cmake-gui</tt>.  More information on <tt>cmake</tt> is available in the [http://techbase.kde.org/Development/Tutorials/CMake CMake Tutorial].
 +
 
 +
With <tt>cmake-gui</tt> it is easy to select only the components starting with <tt>BUILD_</tt> you want. In my case it was rather the components I'm sure of that I didn't want :). So I ended up with only <tt>BUILD_kcontrol</tt> and <tt>systemsettings</tt> and didn't touch any of the other settings below. Then click on the <tt>Configure</tt> button and, if successful, then on the <tt>Generate</tt> button. Close the program now.
 +
 
 +
Now we have makefiles that will only build what we chose to build in the <tt>cmake-gui</tt> program. So now you can execute the <tt>make</tt> command to start:
 +
 
 +
<syntaxhighlight lang="bash">
 +
make
 +
</syntaxhighlight>
 +
 
 +
Now it is building!
 +
 
 +
 
 +
== Changing the source ==
 +
 
 +
We will now go to the directory of the randr module we want to develop on:
 +
 
 +
<syntaxhighlight lang="bash">
 +
cd kcontrol/randr
 +
</syntaxhighlight>
 +
 
 +
Edit some file, and then rebuild simply by running <tt>make</tt> again in this directory:
 +
 
 +
<syntaxhighlight lang="bash">
 +
make
 +
</syntaxhighlight>
 +
 
 +
The module is now being rebuilt.
 +
Likewise we can change something in a source file in the <tt>systemsettings</tt> source directory, and rebuild it using <tt>make</tt>
 +
 
 +
<syntaxhighlight lang="bash">
 +
cd ~/kde4devel/kdebase-workspace-4.3.2/systemsettings
 +
make
 +
</syntaxhighlight>
 +
 
 +
To have a full rebuild of the code, first do <tt>make clean</tt> before the <tt>make</tt> command.
  
 
== Running the program ==
 
== Running the program ==
  
To run our module, we go to the directory of the randr module. There we tell it to do a "make install" as root. This will install the needed files to /usr/local.  
+
This may be somewhat difficult, but we start easy ;)
 +
 +
You go into the {{Path|systemsettings/app}} directory, and there start that self-compiled code like this:
 +
<syntaxhighlight lang="bash">
 +
cd ~/kde4devel/kdebase-workspace-4.3.2/systemsettings/app
 +
./systemsettings
 +
</syntaxhighlight>
 +
 
 +
This will indeed run your new code. But it is better to first install it into your {{path|~/kde4devel/root}} directory so everything is setup correctly in a certain hierarchy, because the systemsettings program might need to find or access certain files to function properly. You do this with the simple command <tt>make install</tt> in the main directory of the application or module you just built:
 +
 
 +
<syntaxhighlight lang="bash">
 +
cd ~/kde4devel/kdebase-workspace-4.3.2/systemsettings
 +
make install
 +
cd ~/kde4devel/kdebase-workspace-4.3.2/kcontrol/randr
 +
make install
 +
</syntaxhighlight>
 +
 
 +
However! '''Here is the difficult part...''' We already have a systemsettings program installed: the one installed by the Debian system in {{path|/usr/bin/systemsettings}}. So you will now find that we have a second one of our own in {{path|~/kde4devel/root/bin/systemsettings}}.
 +
 
 +
{{note|'''So remember this''': Debian installs everything under {{path|/usr}} and your programs end up under {{path|~/kde4devel/root/local}} }}
  
root@pc:/home/karel/kde4devel/kdebase-workspace-4.3.2/kcontrol/randr# make install
+
The <tt>make install</tt> command copied more than only the executable file! It also copied e.g. {{path|~/kde4devel/root/lib/kde4/kcm_randr.so}}. So when we start our "local" systemsettings program, we want to make sure it first finds the files it installed under {{path|~/kde4devel/root}}, and not first the files installed by Debian under {{path|/usr}}.
  
We need to tell our current session the additional KDE path where it needs to look for services and libraries and programs. This is done by filling in the KDEDIRS environment variable like this:
+
We need to tell our current console session the additional KDE path where it needs to look for services and libraries and programs. This is done by filling in the <tt>KDEDIRS</tt> environment variable like this:
  
karel@pc:/home/karel/kde4devel/kdebase-workspace-4.3.2/kcontrol/randr # export KDEDIRS=/usr/local
+
<syntaxhighlight lang="bash">
 +
export KDEDIRS=$HOME/kde4devel/root
 +
</syntaxhighlight>
  
Then we start the randr module like this:
+
Now when we start the systemsettings module in this console session it will find the kcontrol configuration module located in {{path|~/kde4devel/root/lib/kde4/kcm_randr.so}} before the one in {{path|~/kde4devel/root/kde4/kcm_randr.so}}:
  
karel@pc:/home/karel/kde4devel/kdebase-workspace-4.3.2/kcontrol/randr # ./krandrtray
+
<syntaxhighlight lang="bash">
 +
cd ~/kde4devel/root
 +
./systemsettings
 +
</syntaxhighlight>
  
This starts the tray icon which find the kcm module "randr" first in the KDEDIRS location, so this one is loaded. If you start the systemsettings program, it also loads in the same way the kcm config module in /usr/local. So this depends on the KDEDIRS variable, without it, the randr module found in the default debian location is used!
+
And you will now see your own compiled code in action!  
  
== Testing ==
+
== Conclusion ==
  
So now you can change something in the code, run "make" and then "make install" as root(or "sudo make install") in the correct directory, and you can test the program out.
+
Now you have completed compiling and running your own compiled code, you are ready to check out the other tutorials here and gain some deeper insights!

Latest revision as of 22:03, 29 June 2011

Contents

[edit] Introduction

This tutorial is intented for people who are using Debian, and want to check out or test some idea on existing KDE code without much hassle.

This tutorial shows a way of easily downloading and compiling and running the KDE software that is used on your Debian system.

[edit] Getting started

First you need to add the source repositories to your installation. This is normally done by editing /etc/apt/sources.list as user root and adding a line starting with deb-src:

kdesudo kwrite /etc/apt/sources.list

The easy way is to copy your existing deb line onto a new line, and change deb to deb-src:

  1. deb http://ftp.belnet.be/debian testing main contrib non-free
  2. deb-src http://ftp.belnet.be/debian testing main contrib non-free #almost a copy of line 1

In most(all?) of the cases this will work.

Then you must let this change know to the package manager, so do as root:

aptitude update

[edit] Setting up the dependencies

Now you want to be able to build a certain package, and in this example we will build the kcontrol configuration modules(aka KCM modules) and the application containing them called systemsettings. Let's say we want to see if we can maybe fix some bug in the Display configuration module, which is called randr actually. In debian the package is systemsettings, so first we will get the build dependencies of that package, so do as root:

aptitude build-dep systemsettings

This will download and install all needed dependencies which are some build tools and otherwise mostly packages with -dev at the end of them, which are in most cases a bunch of header files.

[edit] Getting the source

As a regular user, create a new directory, and fetch the sources for the package:

mkdir ~/kde4devel
cd ~/kde4devel
apt-get source systemsettings

This downloads the source and applies all the debian patches for you. In this case, it downloads kdebase-workspace because the systemsettings code is only a small part of the kdebase-workspace package. Now go into the newly extracted directory. This is kdebase-workspace-4.3.2 in my case.

cd kdebase-workspace-4.3.2

[edit] Building the source

Now we go into the source directory, and let cmake generate the Makefiles, which are then used by the make command to build the code. This is done like this:

cmake .      # don't forget the extra space+point!

Later we'll have to install the built files, you probably don't want to do this as root. So it is better to call cmake like this:

cmake -DCMAKE_INSTALL_PREFIX=$HOME/kde4devel/root .

cmake supports a nice Qt GUI to configure your build process. If you have the package cmake-qt-gui installed, you can replace cmake with cmake-gui. More information on cmake is available in the CMake Tutorial.

With cmake-gui it is easy to select only the components starting with BUILD_ you want. In my case it was rather the components I'm sure of that I didn't want :). So I ended up with only BUILD_kcontrol and systemsettings and didn't touch any of the other settings below. Then click on the Configure button and, if successful, then on the Generate button. Close the program now.

Now we have makefiles that will only build what we chose to build in the cmake-gui program. So now you can execute the make command to start:

make

Now it is building!


[edit] Changing the source

We will now go to the directory of the randr module we want to develop on:

cd kcontrol/randr

Edit some file, and then rebuild simply by running make again in this directory:

make

The module is now being rebuilt. Likewise we can change something in a source file in the systemsettings source directory, and rebuild it using make

cd ~/kde4devel/kdebase-workspace-4.3.2/systemsettings
make

To have a full rebuild of the code, first do make clean before the make command.

[edit] Running the program

This may be somewhat difficult, but we start easy ;)

You go into the systemsettings/app directory, and there start that self-compiled code like this:

cd ~/kde4devel/kdebase-workspace-4.3.2/systemsettings/app
./systemsettings

This will indeed run your new code. But it is better to first install it into your ~/kde4devel/root directory so everything is setup correctly in a certain hierarchy, because the systemsettings program might need to find or access certain files to function properly. You do this with the simple command make install in the main directory of the application or module you just built:

cd ~/kde4devel/kdebase-workspace-4.3.2/systemsettings
make install
cd ~/kde4devel/kdebase-workspace-4.3.2/kcontrol/randr
make install

However! Here is the difficult part... We already have a systemsettings program installed: the one installed by the Debian system in /usr/bin/systemsettings. So you will now find that we have a second one of our own in ~/kde4devel/root/bin/systemsettings.

noframe
 
Note
So remember this: Debian installs everything under /usr and your programs end up under ~/kde4devel/root/local

The make install command copied more than only the executable file! It also copied e.g. ~/kde4devel/root/lib/kde4/kcm_randr.so. So when we start our "local" systemsettings program, we want to make sure it first finds the files it installed under ~/kde4devel/root, and not first the files installed by Debian under /usr.

We need to tell our current console session the additional KDE path where it needs to look for services and libraries and programs. This is done by filling in the KDEDIRS environment variable like this:

export KDEDIRS=$HOME/kde4devel/root

Now when we start the systemsettings module in this console session it will find the kcontrol configuration module located in ~/kde4devel/root/lib/kde4/kcm_randr.so before the one in ~/kde4devel/root/kde4/kcm_randr.so:

cd ~/kde4devel/root
./systemsettings

And you will now see your own compiled code in action!

[edit] Conclusion

Now you have completed compiling and running your own compiled code, you are ready to check out the other tutorials here and gain some deeper insights!


This page was last modified on 29 June 2011, at 22:03. This page has been accessed 11,163 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal