Distributing your code in such a way that everybody may use it, can be difficult on unix systems. The tools needed to make an executable out of the code must be called in the right way. For this reason, the GNU autotools have been developed. KDE uses these tools and there are scripts that make it easier to use these tools. It is possible to use these scripts for applications that do not use the KDE libraries, but only the Qt libraries. This howto is intended to help developers use the KDE scripts with the GNU autotools to package their code.
The KDE scripts are placed in a directory admin
in the top directory of your project. They can be obtained via anonymous cvs:
export CVSROOT=:pserver:anonymous@anoncvs.kde.org:/home/kde
The variable CVSROOT must be set to the address of a CVS server. There are other anonymous CVS servers than the one mentioned here (see links section below).
cvs login
cvs co kde-common/admin
mv kde-common/admin .
rm -r kde-common
In the top directory, we need two files: configure.in.in
and Makefile.am
. A nice starting point for the configure.in.in file is in the admin
directory: configure.in.min
. Copy this file to the top directory. The file configure.in.in
is used to make the file configure.in
, which is needed for autoconf
. The KDE scripts copy this file into configure.in
and append automatically generated data to it. For KDE development one can simply put #MIN_CONFIG
in the file and the file configure.in.min
is used. For a Qt only app, we need different setting, so we write our own configure.in.in
starting from the file configure.in.min
.
There are a few things that need to be changed to remove KDE dependancies.
AM_INIT_AUTOMAKE(projectname, versionnumber)
.KDE_SET_PREFIX
must be removed. You might want to place the macro AC_PREFIX_DEFAULT(prefix)
in its place if you don't like autoconf's default of /usr/local
.KDE_PROG_LIBTOOL
is a wrapper for a few macro calls, some of which are KDE specific. It can be replaced with AC_PROG_LIBTOOL
. This macro is needed for generating a libtool script.AM_KDE_WITH_NLS
can be commented out.AC_PATH_KDE
must be changed to AC_PATH_QT
.A nice feature that encourages modularity is the fact that you can place a configure.in.in
file in each subdirectory. The KDE scripts copy all of them into the configure.in
file. For example, if you use C++ exceptions in your code, you can place a line CXXFLAGS="$CXXFLAGS $USE_EXCEPTIONS"
in the directory with that code.
There are two different type of Makefile.am
files. There's one in the top directory of the project an one for each subdirectory.
Unless you want to have a true GNU project, you should add the line
AUTOMAKE_OPTIONS = foreign 1.5
which relaxes the number of necessary files such as INSTALL
and ChangeLog
. It is, however, useful to have these files and you can generate them by calling automake --add-missing
. The number arguments specifies the minimal version of automake
that is accepted.
The top level file should contain information on how to create the acinclude.m4
and configure.in
files from the acinclude.m4.in
and the configure.in.in
files.
$(top_srcdir)/acinclude.m4: $(top_srcdir)/admin/acinclude.m4.in $(top_srcdir)/admin/libtool.m4.in @cd $(top_srcdir) && cat admin/acinclude.m4.in admin/libtool.m4.in > acinclude.m4 $(top_srcdir)/configure.in: $(top_srcdir)/configure.files $(shell test -f $(top_srcdir)/configure.files && sed -e "s%^%\$(top_srcdir)/%" $(top_srcdir)/configure.files) cd $(top_srcdir) && $(MAKE) -f admin/Makefile.common configure.in $(top_srcdir)/subdirs: cd $(top_srcdir) && $(MAKE) -f admin/Makefile.common subdirs $(top_srcdir)/configure.files: cd $(top_srcdir) && $(MAKE) -f admin/Makefile.common configure.files
It should also contain information on which subdirectories to process:
SUBDIRS=$(TOPSUBDIRS)
The other Makefile.am
files are usually used to compile C++ files. Here's an example:
bin_PROGRAMS = someqtprogram someqtprogram_SOURCES = program.cpp \ mainclass.cpp someqtprogram_LDFLAGS = $(QT_LDFLAGS) $(X_LDFLAGS) someqtprogram_LDADD = $(LIB_QT) $(LIB_X11) AM_CPPFLAGS = $(QT_INCLUDES) METASOURCES = AUTO
If you want to generate .cpp
files from .ui
files, you need to give the line KDE_OPTIONS = qtonly
, so that the internationalisation support is Qt specific.
You can find more information on writing a Makefile.am
in the KDE specific manual and in the automake manual.
Now the files are prepared, we can configure the autotools with the command:
make -f admin/Makefile.common cvs
./configure
make
To distribute your project, run these commands:
make distclean
cd ..
tar czf project.tgz projectdir
If you have any question or comments, you can reach me at jos at vandenoever dot info.
KDE_OPTIONS = qtonly