Creating KDE Applications: The Build System
Introduction
A build system manages the source file dependencies, and solves the problems of linking all compiled files and libraries manually. It is the essential component to create large software packages.
GNU Build System
Most software projects use the build system originally invented by GNU; the magic ./configure, make, make install steps. To make software easy to compile, package and install it's recommended to use the GNU Build System.
From a tool like KDevelop, most requires files are automatically generated. Using a few commands, the complex This is configure script can be generated automatically. There are several files involved in the building process.
Admin folder
The admin
folder contains a lot of magic files,
and should not be touched. It also contains the KDE extensions
to Automake, to make the development of KDE applications easier.
For newer KDE versions, the admin
folder should be updated
with the contents of $KDEDIR/share/apps/kdelibs/admin/
.
Makefile.am
The Makefile.am
file contains the build instructions
and list the files to be compiled.
Each folder in a project may include such file.
If a Makefile.am
file is updated,
the Makefile.in
files should be re-generated
using the command make -f Makefile.dist.
configure.in
The configure.in
file is the template for the configure script.
The final configure script is generated using the macro language M4.
With KDE applications, this file is created automatically from
multiple configure.in.in
files located in the project subfolders.
configure.in.in
The configure.in.in
files contain additional code
for the configure script.
New parameters and new configure checks can be added here.
The code is written in an old UNIX macro language called M4.
Each subfolder may include a configure.in.in
file.
If a configure.in.in
file is updated,
the configure
script should be re-generated
using the command make -f Makefile.dist.
configure.in.bot
The configure.in.bot
may contain addition shell code
that will be added at the end of the final configure script.
It can be used to print a final message, or configure status report.
Makefile.in
The Makefile.in
files are generated
from the Makefile.am
files.
They contain the template for the final Makefile
code.
This template includes placeholders for the settings configure detects later.
Makefile
As the configure script runs, it performs all checks
and generates the Makefile
in each directory.
These files contain the exact instructions to build the software.
Each Makefile
file is generated from a template Makefile.in
file.
The configure script simply replaces the placeholders with the detected values.
config.h
The configure script also generates the file config.h
.
This file contains all results of the configure script.
This can be included by C++ code to enable certain features in #if .. #endif blocks.
Generated intermediate files
Many files are generated on the fly, or act as template for the final compilation. These templates are used to make the source more portable. Only developers are required to have Automake, Autoconf and M4 installed. Before a new source package is released, a developer runs make -f Makefile.dist to generate all template files and the configure script. At the end user system, configure only has to replace the placeholders in each template file to generate the final files.
Code examples
Makefile.am for a subfolder
For a library (subfolder) in a project,
a Makefile.am
file may look like:
- Sample Makefile.am for a library:
####### kdevelop will overwrite this part!!! (begin)##########
noinst_LIBRARIES = libsettings.a libsettings_a_METASOURCES = AUTO libsettings_a_SOURCES = imagewidgetinterface.ui imagewidget.cpp \ settingsdialog.cpp INCLUDES = $(all_includes) EXTRA_DIST = settingsdialog.h imagewidget.h
The libraryname_SOURCES section
contains a list of all files that should be compiled.
The imagewidgetinterface.ui
file will be translated
to C++ code automatically by the KDE extensions of Automake.
Makefile.am for a rootfolder
The top src
folder often has a Makefile.am
file line this one:
- Sample Makefile.am for a binary:
####### kdevelop will overwrite this part!!! (begin)##########
# Define the program to compile
bin_PROGRAMS = kmess# Define which source files and libraries this program needs
kmess_SOURCES = kmess.cpp kmessinterface.cpp kmess_LDADD = $(top_builddir)/kmess/settings/libsettings.a \ $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_KIO) $(LIB_QT) kmess_LDFLAGS = $(KDE_RPATH) $(all_libraries)# Define the subdirs to look into
SUBDIRS = settings pics sounds# Define the icon
# AUTO requires the "<theme><size><type><name>png" file naming convension
KDE_ICON = AUTO# Define the KDE menu entry
xdg_apps_DATA = kmess.desktop# Define another target for the 'eventsrc' file (for KNotify)
generaldatadir = $(kde_datadir)/kmess generaldata_DATA = eventsrc# Define another target for header files that should not be installed
noinst_HEADERS = kmess.h kmessinterface.h# Define another target to use KDE´s XML GUI builing
rcdir = $(kde_datadir)/kmess rc_DATA = kmessui.rc# Define the include path for the g++ compiler command.
# (set to X, qt and KDE here)
INCLUDES = $(all_includes)# Make sure the program can be debugged
AM_CXXFLAGS = -ggdb# Define how 'moc' should use the Qt .moc.cpp, .moc.h files
METASOURCES = AUTO# Define a Makefile target to generate the translation template
# This is po/kmess.pot here, a template to create new translations
# The rc.cpp dependency contains all messages from the .ui files
messages: rc.cpp $(EXTRACTRC) `find . -name \*.ui -o -name \*.rc ` > rc.cpp LIST=`find . -name \*.h -o -name \*.cpp -o -name \*.cc`; \ if test -n "$$LIST"; then \ $(XGETTEXT) $$LIST -o $(podir)/kmess.pot; \ fi
The bin_PROGRAMS line defines the program kmess. This name reoccurs in the kmess_SOURCES, kmess_LDADD and kmess_LDFLAGS lines.
The SUBDIRS section also lists the settings
where the previous example Makefile.am
is listed.
The remaining part of the file is quite self-explanatory.
Makefile.am for the pics folder
The example above also lists the pics
and sounds
folders.
Their code is displayed below.
- Sample Makefile.am for the pics folder:
####### kdevelop will overwrite this part!!! (begin)##########
# Define a new target for pics
generalpicsdir = $(kde_datadir)/kmess/pics generalpics_DATA = away.png \ berightback.png \ blocked.png \ busy.png \ invisible.png \ lunch.png \ offline.png \ online.png \ onthephone.png
Makefile.am for the sounds folder
This is an example Makefile.am
for a sounds
folder.
- Sample Makefile.am for the sounds folder:
####### kdevelop will overwrite this part!!! (begin)##########
# Leave it up to KDE where these files are installed
kde_sound_DATA = kmess_chat.ogg kmess_logoff.ogg kmess_logon.ogg EXTRA_DIST = $(kde_sound_DATA)
The top Makefile.am
defines the general targets to
initialize the build system, and it's SUBDIRS
line
lists the subfolders
src, po, doc.
This file is identical for most projects.
External Links
blog comments powered by Disqus