### Typical DESTDIR usage for staged installation Source: https://www.gnu.org/software/automake/manual/html_node/Staged-Installs.html Example of creating a staging directory and running make install with the DESTDIR variable to relocate installation objects. ```bash mkdir /tmp/staging && make DESTDIR=/tmp/staging install ``` -------------------------------- ### Custom directory prefix example (xmldir) Source: https://www.gnu.org/software/automake/manual/html_node/Uniform.html Defines a custom installation directory prefix 'xml' by setting xmldir, then uses it to install file.xml into $(datadir)/xml. ```makefile xmldir = $(datadir)/xml xml_DATA = file.xml ``` -------------------------------- ### Staged installation and packaging with DESTDIR Source: https://www.gnu.org/software/automake/manual/html_node/DESTDIR.html Use this workflow to create a binary package from a staged installation. Configure with --prefix /usr, then run make and make DESTDIR=$HOME/inst install. After installation, list installed files and create a tar archive. Using cat ../files.lst instead of '.' avoids restoring modification times of directories. ```shell ~/amhello-1.0 % `./configure --prefix /usr` ... ~/amhello-1.0 % `make` ... ~/amhello-1.0 % `make DESTDIR=$HOME/inst install` ... ~/amhello-1.0 % `cd ~/inst` ~/inst % `find . -type f -print > ../files.lst` ~/inst % `tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`` ./usr/bin/hello ./usr/share/doc/amhello/README ``` -------------------------------- ### Create hard link with install-exec-hook Source: https://www.gnu.org/software/automake/manual/html_node/Extending.html Example of using an install-exec-hook to create a hard link to an installed program after the main installation is complete. ```makefile install-exec-hook: ln $(DESTDIR)$(bindir)/program$(EXEEXT) \ $(DESTDIR)$(bindir)/proglink$(EXEEXT) ``` -------------------------------- ### Typical Makefile.am setup for distributing and installing Java classes Source: https://www.gnu.org/software/automake/manual/html_node/Java.html Shows a typical Automake setup for distributing .java files and installing the resulting .class files. Uses the dist_ prefix to include .java files in the distribution and sets javadir to $(datadir)/java. ```makefile javadir = $(datadir)/java dist_java_JAVA = a.java b.java ... ``` -------------------------------- ### Configure, make, and install with --program-prefix test- Source: https://www.gnu.org/software/automake/manual/html_node/Renaming.html Commands to install hello as /usr/local/bin/test-hello. Run ./configure --program-prefix test-, then make, then sudo make install. ```shell ~/amhello-1.0 % `./configure --program-prefix test-` ... ~/amhello-1.0 % `make` ... ~/amhello-1.0 % `sudo make install` ... ``` -------------------------------- ### EXTRA_PROGRAMS and bin/sbin_PROGRAMS example Source: https://www.gnu.org/software/automake/manual/html_node/Uniform.html Shows how to list programs that may or may not be built (EXTRA_PROGRAMS) and how to assign programs to different installation directories (bin_PROGRAMS, sbin_PROGRAMS). The sbin_PROGRAMS variable uses a configure-time variable $(MORE_PROGRAMS). ```makefile EXTRA_PROGRAMS = mt rmt bin_PROGRAMS = cpio pax sbin_PROGRAMS = $(MORE_PROGRAMS) ``` -------------------------------- ### Install package with custom prefix using configure, make, and make install Source: https://www.gnu.org/software/automake/manual/html_node/Standard-Directory-Variables.html Shows how to install a package into a user's home directory by passing --prefix to configure. The commands are run in the amhello-1.0 source directory and result in installation under ~/usr. ```shell ~/amhello-1.0 % `./configure --prefix ~/usr` ... ~/amhello-1.0 % `make` ... ~/amhello-1.0 % `make install` ... ``` -------------------------------- ### Install versioned program with install-exec-hook Source: https://www.gnu.org/software/automake/manual/html_node/Extending.html Example of using an install-exec-hook to rename an installed program and create a symbolic link to it using $(LN_S). ```makefile install-exec-hook: cd $(DESTDIR)$(bindir) && \ mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \ $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT) ``` -------------------------------- ### Install programs with bin_PROGRAMS Source: https://www.gnu.org/software/automake/manual/html_node/Basics-of-Installation.html Files named in a primary are installed by copying the built file into the appropriate directory, using the base name. Here, both 'hello' and 'goodbye' will be installed in '$(bindir)'. ```makefile bin_PROGRAMS = hello subdir/goodbye ``` -------------------------------- ### autoreconf --install - instantiate build system Source: https://www.gnu.org/software/automake/manual/html_node/Creating-amhello.html Run autoreconf --install to generate the build system files. The output shows the installation of install-sh, missing, compile, and depcomp. ```shell ~/amhello % `autoreconf --install` configure.ac: installing './install-sh' configure.ac: installing './missing' configure.ac: installing './compile' src/Makefile.am: installing './depcomp' ``` -------------------------------- ### Install headers with include_HEADERS Source: https://www.gnu.org/software/automake/manual/html_node/Headers.html Installs foo.h and bar/bar.h into $(includedir) as $(includedir)/foo.h and $(includedir)/bar.h. Use this for headers that accompany installed libraries. ```makefile include_HEADERS = foo.h bar/bar.h ``` -------------------------------- ### Standard GNU Build System Installation Workflow Source: https://www.gnu.org/software/automake/manual/html_node/Basic-Installation.html The sequence of commands to unpack, configure, build, test, and install a package. Note that 'make install' typically requires root privileges to write to system directories. ```bash ~ % tar zxf amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % ./configure ... config.status: creating Makefile config.status: creating src/Makefile ... ~/amhello-1.0 % make ... ~/amhello-1.0 % make check ... ~/amhello-1.0 % su Password: /home/adl/amhello-1.0 # make install ... /home/adl/amhello-1.0 # exit ~/amhello-1.0 % make installcheck ... ``` -------------------------------- ### Install on first host with shared /usr/share Source: https://www.gnu.org/software/automake/manual/html_node/Two_002dPart-Install.html Commands to build and install the package on the first host, which installs both architecture-dependent and architecture-independent files. The directory /usr/share is shared with the second host. ```shell [HOST1] ~ % `mkdir /tmp/amh && cd /tmp/amh` [HOST1] /tmp/amh % `/nfs/src/amhello-1.0/configure --prefix /usr` ... [HOST1] /tmp/amh % `make && sudo make install` ... ``` -------------------------------- ### Build multiple configurations from one source Source: https://www.gnu.org/software/automake/manual/html_node/VPATH-Builds.html Shows how to create separate build directories for different compiler flags to build the same source with multiple configurations. ```bash ~ % `tar zxf ~/amhello-1.0.tar.gz` ~ % `cd amhello-1.0` ~/amhello-1.0 % `mkdir debug optim && cd debug` ~/amhello-1.0/debug % `../configure CFLAGS='-g -O0'` ... ~/amhello-1.0/debug % `make` ... ~/amhello-1.0/debug % cd ../optim ~/amhello-1.0/optim % `../configure CFLAGS='-O3 -fomit-frame-pointer'` ... ~/amhello-1.0/optim % `make` ... ``` -------------------------------- ### Distribute and install man pages with dist_man_MANS Source: https://www.gnu.org/software/automake/manual/html_node/Man-Pages.html Uses the dist_ prefix to include man pages in the distribution and install them. Example shows distributing cpio.1 and mt.1. ```makefile dist_man_MANS = cpio.1 mt.1 ``` -------------------------------- ### Python command with prefix substitution Source: https://www.gnu.org/software/automake/manual/html_node/Hard_002dCoded-Install-Paths.html Passes '${exec_prefix}' as the third argument to 'sysconfig.get_python_lib()' to get a path that respects the installation prefix, e.g., '${exec_prefix}/lib/python2.5/site-packages'. This allows non-root users to install. ```shell % `python -c 'from distutils import sysconfig; print sysconfig.get_python_lib(1,0,"${exec_prefix}")'` ${exec_prefix}/lib/python2.5/site-packages ``` -------------------------------- ### Merging Libtool convenience libraries into a main library Source: https://www.gnu.org/software/automake/manual/html_node/Libtool-Convenience-Libraries.html Example setup showing a top-level Makefile.am merging sublibraries from subdirectories, alongside the corresponding Makefile.am configurations for the subdirectories. ```makefile # -- Top-level Makefile.am -- SUBDIRS = sub1 sub2 ... lib_LTLIBRARIES = libtop.la libtop_la_SOURCES = libtop_la_LIBADD = \ sub1/libsub1.la \ sub2/libsub2.la \ ... # -- sub1/Makefile.am -- noinst_LTLIBRARIES = libsub1.la libsub1_la_SOURCES = ... # -- sub2/Makefile.am -- # showing nested convenience libraries SUBDIRS = sub2.1 sub2.2 ... noinst_LTLIBRARIES = libsub2.la libsub2_la_SOURCES = libsub2_la_LIBADD = \ sub21/libsub21.la \ sub22/libsub22.la \ ... ``` -------------------------------- ### Combine notrans_ and dist_ prefixes for man pages Source: https://www.gnu.org/software/automake/manual/html_node/Man-Pages.html Shows the correct order: notrans_ must come before dist_ or nodist_. This example distributes and installs bar.3 without renaming. ```makefile notrans_dist_man3_MANS = bar.3 ``` -------------------------------- ### Create a VPATH build directory Source: https://www.gnu.org/software/automake/manual/html_node/VPATH-Builds.html Demonstrates how to extract a package and run configure from a separate build subdirectory to keep the source tree uncluttered. ```bash ~ % `tar zxf ~/amhello-1.0.tar.gz` ~ % `cd amhello-1.0` ~/amhello-1.0 % `mkdir build && cd build` ~/amhello-1.0/build % `../configure` ... ~/amhello-1.0/build % `make` ... ``` -------------------------------- ### Python command to get site-packages directory Source: https://www.gnu.org/software/automake/manual/html_node/Hard_002dCoded-Install-Paths.html Runs Python's 'sysconfig.get_python_lib(1,0)' to output the absolute site-packages path, e.g., '/usr/lib/python2.5/site-packages'. Using this absolute path directly breaks non-root installs. ```shell % `python -c 'from distutils import sysconfig; print sysconfig.get_python_lib(1,0)'` /usr/lib/python2.5/site-packages ``` -------------------------------- ### First Try: Makefile.am with bindir.h (failing) Source: https://www.gnu.org/software/automake/manual/html_node/Built-Sources-Example.html This Makefile.am attempts to build bindir.h but fails because Automake doesn't know foo.c includes bindir.h. The build fails with 'bindir.h: No such file or directory'. ```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)"' >$@ ``` -------------------------------- ### Default header installation with directory stripping Source: https://www.gnu.org/software/automake/manual/html_node/Alternative.html By default, the directory name is stripped from the installed file, resulting in the file being installed directly into the target directory. ```makefile include_HEADERS = inc/stdio.h ``` -------------------------------- ### Manual configure command with variables Source: https://www.gnu.org/software/automake/manual/html_node/config_002esite.html An example of manually passing configuration variables to the configure script. ```bash ~/amhello-1.0 % `./configure --prefix ~/usr CC=gcc-3 \ CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib` ``` -------------------------------- ### ./configure - configure the build system Source: https://www.gnu.org/software/automake/manual/html_node/Creating-amhello.html Run ./configure to generate Makefile, src/Makefile, and config.h. The output shows the system probing and file creation. ```shell ~/amhello % `./configure` checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for style of include used by make... GNU checking dependency style of gcc... gcc3 configure: creating ./config.status config.status: creating Makefile config.status: creating src/Makefile config.status: creating config.h config.status: executing depfiles commands ``` -------------------------------- ### Install and distribute a script with dist_bin_SCRIPTS Source: https://www.gnu.org/software/automake/manual/html_node/Scripts.html Lists a script in the final installable form using the SCRIPTS primary with a dist_ prefix to ensure it is distributed and installed in $(bindir). ```makefile # Install my_script in $(bindir) and distribute it. dist_bin_SCRIPTS = my_script ``` -------------------------------- ### Avoid byte-compilation with lisp_DATA Source: https://www.gnu.org/software/automake/manual/html_node/Emacs-Lisp.html Recommended since Automake 1.8 to avoid byte-compilation. Note that _LISP will not install files if Emacs is not installed, while _DATA always installs. ```makefile lisp_DATA = file1.el file2.el ``` -------------------------------- ### Build a script with explicit Makefile rules (automake example) Source: https://www.gnu.org/software/automake/manual/html_node/Scripts.html Shows how to build a script from a source file using sed substitutions and a custom rule. Requires CLEANFILES to delete the built script and EXTRA_DIST to distribute the source. ```makefile bin_SCRIPTS = automake CLEANFILES = $(bin_SCRIPTS) EXTRA_DIST = automake.in do_subst = sed -e 's,[@]datadir[@],$(datadir),g' \ -e 's,[@]PERL[@],$(PERL),g' \ -e 's,[@]PACKAGE[@],$(PACKAGE),g' \ -e 's,[@]VERSION[@],$(VERSION),g' \ ... automake: automake.in Makefile $(do_subst) < $(srcdir)/automake.in > automake chmod +x automake ``` -------------------------------- ### make, src/hello, and make distcheck - build and distribute Source: https://www.gnu.org/software/automake/manual/html_node/Creating-amhello.html Commands to build the package, run the hello program, and create a distribution archive. The output shows the program output and the archive creation. ```shell ~/amhello % `make` ... ~/amhello % `src/hello` Hello World! This is amhello 1.0. ~/amhello % `make distcheck` ... ============================================= amhello-1.0 archives ready for distribution: amhello-1.0.tar.gz ============================================= ``` -------------------------------- ### TAP driver setup and test run commands Source: https://www.gnu.org/software/automake/manual/html_node/TAP-setup-and-examples.html Commands to copy the TAP driver script, run autoreconf, configure, and make check, and then check the exit status. ```shell % `cp PREFIX/share/automake-APIVERSION/tap-driver.sh .` % `autoreconf -vi && ./configure && make check` ``` ```shell % `echo exit status: $?` exit status: 1 ``` -------------------------------- ### TAP driver setup: Makefile.am Source: https://www.gnu.org/software/automake/manual/html_node/TAP-setup-and-examples.html The Makefile.am file that configures the TAP driver as the test log driver and lists the test scripts. ```makefile TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \ $(top_srcdir)/build-aux/tap-driver.sh TESTS = foo.test bar.test baz.test EXTRA_DIST = $(TESTS) ``` -------------------------------- ### Correct sysconf_DATA assignment for configuration files Source: https://www.gnu.org/software/automake/manual/html_node/Hard_002dCoded-Install-Paths.html Replaces the hard-coded install rule with a 'sysconf_DATA' variable, which installs to '$(sysconfdir)' (default '$(prefix)/etc'). Installers can override with '--sysconfdir'. ```makefile sysconf_DATA = afile ``` -------------------------------- ### Execute configure with config.site Source: https://www.gnu.org/software/automake/manual/html_node/config_002esite.html Running the configure script after creating the config.site file, showing the automatic loading of the site script. ```bash ~/amhello-1.0 % `./configure --prefix ~/usr` configure: loading site script /home/adl/usr/share/config.site ... ```