1 CONFIGURING PACKAGES TO WORK WITH GTK
2 -------------------------------------
4 Compiling a program succesfully against the GTK, GDK, and GLIB
5 libraries can require a large number of command line options
6 to your compiler and linker that are hard to guess correctly.
7 The additional libraries required may, for example, depend on the
8 manner which GTK was configured
10 Several tools are included in this package to make process
13 First, there is the shell script 'gtk-config' (installed in
19 gtk-config can be invoked in one of three forms:
22 Prints out the version of GTK installed
25 Prints '-I' flags pointing to the installed d
28 Prints out the linker flags necessary to link a program against GTK
31 Example of using gtk-config
32 ---------------------------
34 Typically, gtk-config will be used within a configure script,
35 as described below. It, however, can also be used directly
36 from the command line to compile a simple program. For example:
38 cc -o simple `gtk-config --cflags` simple.c `gtk-config --libs`
40 This command line might expand to (for example):
42 cc -o simple -I/usr/local/lib/glib/include -I/usr/local/include \
43 -I/usr/X11R6/include simple.c -L/usr/local/lib -L/usr/X11R6/lib \
44 -lgtk -lgdk -lglib -lXi -lXext -lX11 -lm
46 Not only is the form using gtk-config easier to type, it will
47 work on any system, no matter how GTK was configured.
53 For packages configured using GNU automake, GTK also provides
54 a macro to automate the process of running GTK.
56 AM_PATH_GTK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
60 * Determines the location of GTK using gtk-config, which is either
61 found in the user's path, or from the environment variable
64 * Tests the installed libraries to make sure that there version
65 is later than MINIMUM-VERSION. (A default version will be used
68 * If the required version was found, sets the GTK_CFLAGS variable to
69 the output of `gtk-config --cflags` and the GTK_LIBS variable to
70 the output of `gtk-config --libs`, and calls AC_SUBST() for these
71 variables so they can be used in generated makefiles, and then
72 executes ACTION-IF-FOUND.
74 * If the required version was not found, sets GTK_CFLAGS and GTK_LIBS
75 to empty strings, and executes ACTION-IF-NOT-FOUND.
77 This macro is in file 'gtk.m4' which is installed in $datadir/aclocal.
78 Note that if automake was installed with a different --prefix than
79 GTK, you will either have to manually move gtk.m4 to automake's
80 $datadir/aclocal, or give aclocal the -I option when running it.
83 Configuring a package that uses AM_PATH_GTK
84 -------------------------------------------
86 Simply make sure that gtk-config is in your path, and run
91 * You can also specify a gtk-config not in your path by
92 setting the GTK_CONFIG environment variable to the
93 name of the executable
95 * If you move the GTK package from its installed location,
96 you will need either need to modify gtk-config script
97 manually to point to the new location or rebuild GTK.
99 [ As a future enhancement AM_PATH_GTK should support options
100 to override the default locations found in gtk-config ]
103 Example of a package using AM_PATH_GTK
104 --------------------------------------
106 The following shows how to build a simple package using automake
107 and the AM_PATH_GTK macro. The program used here is the testinput.c
109 You should first read the introductory portions of the automake
110 Manual, if you are not already familiar with it.
112 Two files are needed, 'configure.in', which is used to build the
116 dnl Process this file with autoconf to produce a configure script.
119 AM_INIT_AUTOMAKE(testinput.c, 1.0.0)
126 [LIBS="$LIBS $GTK_LIBS"
127 CFLAGS="$CFLAGS $GTK_CFLAGS"],
128 AC_MSG_ERROR(Cannot find GTK: Is gtk-config in path?))
133 The only command in this which is not standard for automake
134 is the AM_PATH_GTK() macro.
136 That command does the following:
138 If a GTK version greater than 0.99.5 is found, adds $GTK_LIBS to
139 $LIBS and $GTK_CFLAGS to $CFLAGS. Otherwise, dies with the error
140 message "Cannot find GTK: Is gtk-config in path?"
142 And the 'Makefile.am', which will be used to build the Makefile.
145 bin_PROGRAMS = testinput
146 testinput_SOURCES = testinput.c
149 This Makefile.am, says that we are building a single executable,
150 from a single sourcefile 'testinput.c'. Since every program
151 we are building uses GTK we simply added the GTK options
152 to $LIBS and $CFLAGS, but in other circumstances, we might
153 want to specify them on a per-program basis: for instance by
156 testinput_LDADD = $(GTK_LIBS)
157 INCLUDES = $(GTK_CFLAGS)
161 To try this example out, create a new directory, add the two
162 files above two it, and copy the testinput.c file from
163 the gtk/ subdirectory to the new directory. Edit the line:
167 in testgtk.c, to read:
172 Now execute the following commands:
174 automake --add-missing
178 You now have a package that can be built in the normal fashion
187 * If you are converting a package that used a pre-1.0 version of
188 GTK, you should remove the autoconf tests for X. The results
189 of these tests are included in gtk-config and will be added
190 to GTK_LIBS and GTK_CFLAGS by the AM_PATH_GTK macro.