### Installing programs with bin_PROGRAMS Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Lists programs to install into $(bindir). The base name of each file is used, so both hello and goodbye are installed in the bindir. ```makefile bin_PROGRAMS = hello subdir/goodbye ``` -------------------------------- ### DESTDIR staging install command Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Shows how to use DESTDIR to stage install objects into a temporary directory. The command prefixes all install paths with /tmp/staging, so files like /gnu/bin/foo become /tmp/staging/gnu/bin/foo. This is commonly used for building install images and packages. ```makefile make DESTDIR=/tmp/staging install ``` -------------------------------- ### Man page installation with man1_MANS Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Declares man pages for section 1. Files with a valid suffix are installed as-is; others are renamed to match the section (e.g., rename.man becomes rename.1). ```makefile man1_MANS = rename.man thesame.1 alsothesame.1c ``` -------------------------------- ### Define bin_PROGRAMS for a program Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html The PROGRAMS primary is used to build programs. This example defines a program named hello. ```makefile bin_PROGRAMS = hello ``` -------------------------------- ### Installing headers with nobase_include_HEADERS Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Uses the nobase_ prefix to install header files without stripping directory components, preserving the source layout in the install directory. ```makefile nobase_include_HEADERS = stdio.h sys/types.h ``` -------------------------------- ### install-exec-hook to install a versioned copy using $(LN_S) Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Uses install-exec-hook with $(LN_S) to install a versioned copy of a program. Renames the program so a new version erases the symbolic link, not the real binary, and cd's into the destination directory to create relative links. ```makefile install-exec-hook: cd $(DESTDIR)$(bindir) && \ mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \ $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT) ``` -------------------------------- ### Custom installation directory with htmldir Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Defines a custom installation directory (htmldir) and installs HTML data files using the html_DATA primary. This is used when Automake does not natively support HTML installation. ```makefile htmldir = $(prefix)/html html_DATA = automake.html ``` -------------------------------- ### EXTRA_PROGRAMS and prefixed primaries example Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Shows how to use EXTRA_PROGRAMS and prefixed primaries (bin_PROGRAMS, sbin_PROGRAMS) to conditionally build programs based on configure decisions. The variable @MORE_PROGRAMS@ is substituted by configure. ```makefile EXTRA_PROGRAMS = mt rmt bin_PROGRAMS = cpio pax sbin_PROGRAMS = @MORE_PROGRAMS@ ``` -------------------------------- ### install-exec-hook to create a hard link to an installed program Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Uses the install-exec-hook to create a hard link to an installed program. Hard links are cheaper and more portable than symbolic links but may not work everywhere (e.g., OS/2 lacks ln). ```makefile install-exec-hook: ln $(DESTDIR)$(bindir)/program$(EXEEXT) \ $(DESTDIR)$(bindir)/proglink$(EXEEXT) ``` -------------------------------- ### Install custom aclocal macros in Makefile.am Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Shows how to install custom .m4 macro files into $(datadir)/aclocal by setting aclocaldir and aclocal_DATA in a Makefile.am. ```makefile aclocaldir = $(datadir)/aclocal aclocal_DATA = mymacro.m4 myothermacro.m4 ``` -------------------------------- ### Install header with nobase_ prefix to preserve directory Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html The nobase_ prefix prevents path stripping, so sys/types.h is installed as $(includedir)/sys/types.h. ```makefile nobase_include_HEADERS = sys/types.h ``` -------------------------------- ### Building a library with noinst_LIBRARIES Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Creates a library named libcpio.a but does not install it. The library name is canonicalized, so the _SOURCES variable would be liblob_a_SOURCES for liblob.a. ```makefile noinst_LIBRARIES = libcpio.a ``` -------------------------------- ### Top-level Makefile.am from GNU Hello Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Example of a short top-level Makefile.am using EXTRA_DIST and SUBDIRS. The SUBDIRS variable lists subdirectories to build; directories must be direct children of the current directory. ```makefile EXTRA_DIST = BUGS ChangeLog.O README-alpha SUBDIRS = doc intl po src tests ``` -------------------------------- ### configure.in setting HELLO_SYSTEM substitution Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Sets HELLO_SYSTEM to the appropriate object file based on the host system, then substitutes it with AC_SUBST. This is used with the previous Makefile.am example. ```autoconf ... case $host in *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;; *) HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;; esac AC_SUBST([HELLO_SYSTEM]) ... ``` -------------------------------- ### Conditional Libtool Sources using Automake conditional Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Alternative to the previous example using an Automake conditional LINUX to choose between hello-linux.c and hello-generic.c. Uses _SOURCES with += inside if/else. ```makefile lib_LTLIBRARIES = libhello.la libhello_la_SOURCES = hello-common.c if LINUX libhello_la_SOURCES += hello-linux.c else libhello_la_SOURCES += hello-generic.c endif ``` -------------------------------- ### ETAGS_ARGS example for automake source and Texinfo Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Shows how to set ETAGS_ARGS to generate tags for Automake's own source and Texinfo nodes. Uses --lang=none and a regex to match @node lines. ```makefile ETAGS_ARGS = automake.in --lang=none \ --regex='/^@node[ \t]+\([^,]+\)/\1/' automake.texi ``` -------------------------------- ### Install header with stripped directory using include_HEADERS Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html By default, installable files in subdirectories have their directory name stripped. This example installs inc/stdio.h as $(includedir)/stdio.h. ```makefile include_HEADERS = inc/stdio.h ``` -------------------------------- ### Combine nobase_ with dist_ prefix Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html When using nobase_ with dist_ or nodist_, nobase_ must be specified first. This example installs images/vortex.pgm as $(pkgdatadir)/images/vortex.pgm. ```makefile nobase_dist_pkgdata_DATA = images/vortex.pgm ``` -------------------------------- ### Using BUILT_SOURCES: Makefile.am (working) Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html A working Makefile.am that uses BUILT_SOURCES = bindir.h to ensure bindir.h is built before other targets. This solves the bootstrap issue. ```makefile bin_PROGRAMS = foo foo_SOURCES = foo.c BUILT_SOURCES = bindir.h CLEANFILES = bindir.h bindir.h: Makefile echo '#define bindir "$(bindir)"' >$@ ``` -------------------------------- ### Using BUILT_SOURCES: make output showing success Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html The make output when using the BUILT_SOURCES solution. It shows bindir.h being built first, then foo.o and foo. ```shell % make echo '#define bindir "/usr/local/bin"' >bindir.h make all-am make[1]: Entering directory `/home/adl/tmp' source='foo.c' object='foo.o' libtool=no \ depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \ depmode=gcc /bin/sh ./depcomp \ gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c gcc -g -O2 -o foo foo.o make[1]: Leaving directory `/home/adl/tmp' ``` -------------------------------- ### AM_INIT_AUTOMAKE with options Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Shows the preferred form of AM_INIT_AUTOMAKE with a space-separated list of options, including no-define to avoid defining PACKAGE and VERSION. ```autoconf AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2]) ``` -------------------------------- ### GNU Hello configure.in Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html The configure.in from GNU Hello, using deprecated AC_INIT and AM_INIT_AUTOMAKE syntax. It includes checks for programs, headers, functions, and internationalization macros. ```autoconf dnl Process this file with autoconf to produce a configure script. AC_INIT(src/hello.c) AM_INIT_AUTOMAKE(hello, 1.3.11) AM_CONFIG_HEADER(config.h) dnl Set of available languages. ALL_LINGUAS="de fr es ko nl no pl pt sl sv" dnl Checks for programs. AC_PROG_CC AC_ISC_POSIX dnl Checks for libraries. dnl Checks for header files. AC_STDC_HEADERS AC_HAVE_HEADERS(string.h fcntl.h sys/file.h sys/param.h) dnl Checks for library functions. AC_FUNC_ALLOCA dnl Check for st_blksize in struct stat AC_ST_BLKSIZE dnl internationalization macros AM_GNU_GETTEXT AC_OUTPUT([Makefile doc/Makefile intl/Makefile po/Makefile.in \ src/Makefile tests/Makefile tests/hello], [chmod +x tests/hello]) ``` -------------------------------- ### install-data-local target to install a file in /etc Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Adds a custom install-data-local target to Makefile.in to install a file into /etc. Automake supplements the standard install-data target with this user-supplied target. ```makefile install-data-local: $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile ``` -------------------------------- ### Automake Makefile.am for building hello program Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Shows a minimal Makefile.am that compiles each .c file into .o and links them to produce the hello program. If hello_SOURCES is omitted, it defaults to hello.c. ```makefile bin_PROGRAMS = hello hello_SOURCES = hello.c ``` -------------------------------- ### Using .foo file in bin_PROGRAMS Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Shows how to use a .foo source file in a program's _SOURCES variable after defining a suffix rule for .foo. ```makefile bin_PROGRAMS = doit doit_SOURCES = doit.foo ``` -------------------------------- ### bin_PROGRAMS = liver Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Example of a bin_PROGRAMS definition that Automake rewrites internally to include $(EXEEXT) for platforms requiring executable extensions. ```makefile bin_PROGRAMS = liver ``` -------------------------------- ### First try: Makefile.am with nodist_foo_SOURCES (failing) Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html A tentative Makefile.am that fails because Automake doesn't know foo.c includes bindir.h. The rule builds bindir.h but it is not built before foo.o, causing a compilation error. ```makefile # This won't work. bin_PROGRAMS = foo foo_SOURCES = foo.c nodist_foo_SOURCES = bindir.h CLEANFILES = bindir.h bindir.h: Makefile echo '#define bindir "$(bindir)"' >$@ ``` -------------------------------- ### Declare a libtool library with lib_LTLIBRARIES Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html Declares a libtool library named libgettext.la to be installed in libdir. The SOURCES variable lists the source files for the library. ```makefile lib_LTLIBRARIES = libgettext.la libgettext_la_SOURCES = gettext.c gettext.h ... ``` -------------------------------- ### First try: make output showing failure Source: http://gnu.ist.utl.pt/software/automake/manual/html_mono/automake.html The make output when running the failing Makefile.am. It shows the compilation of foo.c failing because bindir.h is not found. ```shell % make source='foo.c' object='foo.o' libtool=no \ depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \ depmode=gcc /bin/sh ./depcomp \ gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c foo.c:2: bindir.h: No such file or directory make: *** [foo.o] Error 1 ```