Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

Makefile.am

automake processes Makefile.am to produce a standards-compliant Makefile.in. automake does a lot of work for you: it keeps up with dependencies between source files, for example. It creates all the standard targets, such as install and clean. It also creates more complex targets: simply typing make dist creates a standard .tar.gz file if your Makefile.am is correct.

The Makefile.am in the top source directory is generally very simple; here is an example:


SUBDIRS = macros po intl src pixmaps doc

## We dist autogen.sh since this is an example program
## Real-world programs do not need to distribute autogen.sh
EXTRA_DIST = \
        gnome-hello.desktop \
    autogen.sh

Applicationsdir = $(datadir)/gnome/apps/Applications
Applications_DATA = gnome-hello.desktop


The SUBDIRS line instructs automake to recursively look for Makefile.am files in the given subdirectories. (the section called .desktop Entries describes the remainder of the file, ignore it for now.) The Makefile.am in the src directory is a little more interesting:


INCLUDES = -I$(top_srcdir) -I$(includedir) $(GNOME_INCLUDEDIR) \
         -DG_LOG_DOMAIN=\"GnomeHello\" -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
    -I../intl -I$(top_srcdir)/intl

bin_PROGRAMS = gnome-hello

gnome_hello_SOURCES =         \
        app.c           \
        hello.c         \
        menus.c     \
    app.h       \
    hello.h     \
    menus.h

gnome_hello_LDADD = $(GNOMEUI_LIBS) $(GNOME_LIBDIR) $(INTLLIBS)


automake understands a number of "magic variables" and can use them to create Makefile.in. In the small example above, the following variables are used:

  • INCLUDES specifies flags to pass to the C compiler during the compile phase (as opposed to the link phase). The variables used in this line come from the configure.in shown in the previous section.

  • bin_PROGRAMS lists the programs to be compiled.

  • hello_SOURCES lists the files to be compiled and linked to create the program called hello; hello must be listed in bin_PROGRAMS. All files in this variable are automatically included in the distribution.

  • hello_LDADD lists flags to be passed to the linker. In this case, Gnome library flags determined by configure.

Several elements of the INCLUDES line should be used in all Gnome programs. G_LOG_DOMAIN should always be defined; error messages from checks and assertions will report this value, so you can determine where the error occurred (in your code, or in a library). GNOMELOCALEDIR is used to locate translation files. The intl directory is added to the header search path so the application can find the intl headers.

There are many more complex things one can do in Makefile.am; in particular, you can add @-bounded variables to be substituted by configure, you can conditionally include portions of the Makefile based on configure checks, and you can build libraries. The automake manual gives more details.

Table 1 summarizes the most interesting targets generated by automake. Of course the default target is all, which compiles the program. The GNU Coding Standards (https://www.gnu.org/prep/standards_toc.html) have more information about these targets and GNU makefiles in general.

Table 1. Standard make targets

Target Description
dist Builds a tarball (.tar.gz) for distribution
distcheck Builds a tarball, then tries to compile it
clean Deletes the results of compilation (object files and executables), but may not delete some generated files that come with the distribution.
install Creates installation directories if needed, and copies the software into them.
uninstall Reverses the install (deletes installed files).
distclean Reverse the effects of the configure script and the all target; that is, revert a tarball to its pristine state.
mostlyclean Nearly the same as clean, but leaves some object files that most likely don't need to be rebuilt.
maintainer-clean More thorough than clean; may delete some files that require special tools to rebuild, such as machine-generated source code.
TAGS Creates a tag table, for use with Emacs.
check Runs a test suite if you have one
Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire