JJC
JJC

Reputation: 10023

Adding GLib to an existing application with gnu toolchain (configure, Makefile, etc.)

I've added code to an existing large application and need to make GLib a requirement, as my code relies on it. For development, I just manually edited the Makefile to add

-lglib-2.0

To the LIBS= variable and

-I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include $<

to the line starting with ${CC}.

However, I am at a loss for how to make this permanent/portable in the app -- i.e. when someone executes ./configure in the future, the resulting Makefile should also include the above (as appropriate, since these depend on pkg-config output, I've learned). The codebase I updated includes the following files from the gnu tool chain:

Makefile.in
Makefile.manual
config.h.in
configure
configure.in

I only have a handful of CS degrees and a few years of development experience, so the GNU toolchain remains utterly impenetrable to me. :-/ From googling around, I'm under the impression there should also be a configure.ac file or something where I should add a macro for requiring glib, but no such file is included in the package and I'm at the point of learned helplessness with the whole automake/autoconf/configure/makefile business. Thanks in advance for any advice or pointers!

Upvotes: 0

Views: 1052

Answers (1)

matthias
matthias

Reputation: 2181

  1. You should not edit any generated files manually. This includes the final Makefile used to build the application.
  2. In configure.ac, every dependency is listed, thus checking for GLib should go in there. From this file, your final configure shell script is generated.
  3. GLib provides a pkgconfig description so you almost always want to use this to get the correct compile and link flags.
  4. Combining pkgconfig and Autotools is just a matter of calling the PKG_CHECK_MODULES macro. The Autotools Mythbuster is an excellent source that describes how to do it.
  5. In the end it boils down to adding these lines to your configure.ac:

    PKG_PROG_PKG_CONFIG
    PKG_CHECK_MODULES([GLIB], [glib-2.0])
    

    and these lines to your Makefile.am:

    foo_CXXFLAGS = $(GLIB_CFLAGS)
    foo_LIBS = $(GLIB_LIBS)
    

Upvotes: 2

Related Questions