### Define and install a script with bin_SCRIPTS Source: http://web.mit.edu/gnu/doc/html/automake.html Example of defining and installing a script using the SCRIPTS primary name in Makefile.am. Automake does not define dependencies for scripts, so the Makefile.am should include the appropriate rules. ```makefile bin_SCRIPTS = automake ``` -------------------------------- ### Use DESTDIR for staged installation Source: http://web.mit.edu/gnu/doc/html/automake.html Example of typical DESTDIR usage during the make install step to relocate install objects into a staging area. Each object and path is prefixed with the value of DESTDIR before being copied into the install area. ```shell make DESTDIR=/tmp/staging install ``` -------------------------------- ### install-exec-hook: create hard link to installed program Source: http://web.mit.edu/gnu/doc/html/automake.html Defines a hook target that runs after the install-exec target. The example creates a hard link from an installed program to a new name using the bindir variable. ```makefile install-exec-hook: ln $(bindir)/program $(bindir)/proglink ``` -------------------------------- ### Declare program with bin_PROGRAMS Source: http://web.mit.edu/gnu/doc/html/automake.html Declares a program named hello to be built and installed in bindir using the PROGRAMS primary. ```makefile bin_PROGRAMS = hello ``` -------------------------------- ### doc/Makefile.am Source: http://web.mit.edu/gnu/doc/html/automake.html The doc/Makefile.am for GNU Hello. It is sufficient to build, install, and distribute the GNU Hello manual. ```makefile info_TEXINFOS = hello.texi hello_TEXINFOS = gpl.texi ``` -------------------------------- ### Top-level Makefile.am with SUBDIRS Source: http://web.mit.edu/gnu/doc/html/automake.html Example top-level Makefile.am from GNU Hello showing the SUBDIRS variable listing subdirectories to build and EXTRA_DIST for extra files. ```makefile EXTRA_DIST = BUGS ChangeLog.O README-alpha SUBDIRS = doc intl po src tests ``` -------------------------------- ### Automake: EXTRA_PROGRAMS and prefixed PROGRAMS variables Source: http://web.mit.edu/gnu/doc/html/automake.html Shows how to list programs that may or may not be built (EXTRA_PROGRAMS) and how to assign programs to installation directories using prefixed primary variables. The sbin_PROGRAMS value is substituted at configure time via @PROGRAMS@. ```makefile EXTRA_PROGRAMS = mt rmt bin_PROGRAMS = cpio pax sbin_PROGRAMS = @PROGRAMS@ ``` -------------------------------- ### Specify sources with hello_SOURCES Source: http://web.mit.edu/gnu/doc/html/automake.html Specifies the source files that get built into the hello executable. ```makefile hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h ``` -------------------------------- ### Write Makefile.am for zardoz Source: http://web.mit.edu/gnu/doc/html/automake.html Makefile.am for the zardoz program: installs the binary, lists its sources, links against @LIBOBJS@, and includes Texinfo documentation. ```makefile bin_PROGRAMS = zardoz zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c zardoz_LDADD = @LIBOBJS@ info_TEXINFOS = zardoz.texi ``` -------------------------------- ### install-data-local target to install a file into /etc Source: http://web.mit.edu/gnu/doc/html/automake.html Adds a custom rule to install a file into /etc. Automake supplements the standard install-data target with this user-supplied -local version. ```makefile install-data-local: $(INSTALL_DATA) $(srcdir)/afile /etc/afile ``` -------------------------------- ### Automake: custom htmldir and html_DATA Source: http://web.mit.edu/gnu/doc/html/automake.html Defines a custom installation directory (htmldir) and installs a data file into it using the html_DATA primary variable. This is useful when the standard directories are insufficient, such as for raw HTML documentation. ```makefile htmldir = $(prefix)/html html_DATA = automake.html ``` -------------------------------- ### Declare Texinfo and man pages in Makefile.am Source: http://web.mit.edu/gnu/doc/html/automake.html Example from GNU cpio showing how to declare Texinfo documentation and man pages. Man pages are not automatically included in the distribution, so they are added to EXTRA_DIST. ```makefile info_TEXINFOS = cpio.texi man_MANS = cpio.1 mt.1 EXTRA_DIST = $(man_MANS) ``` -------------------------------- ### Build uninstalled library: noinst_LIBRARIES Source: http://web.mit.edu/gnu/doc/html/automake.html Builds a library without installing it, using the LIBRARIES primary. ```makefile noinst_LIBRARIES = libcpio.a ``` -------------------------------- ### Declare shared library with lib_LTLIBRARIES Source: http://web.mit.edu/gnu/doc/html/automake.html Declares a shared library target using the LTLIBRARIES primary. Automake uses Libtool to build the library and its shared counterparts, installing them in libdir. ```makefile lib_LTLIBRARIES = libgettext.la ``` -------------------------------- ### Rules supporting de-ANSI-fication for etags and ctags Source: http://web.mit.edu/gnu/doc/html/automake.html Rules that support the de-ANSI-fication feature, using ._o and ._c suffixes. Requires additional work beyond the previous examples. ```makefile etags._o: etags._c ctags.o $(COMPILE) -DETAGS_REGEXPS -c etags.c ctags._o: etags._c $(COMPILE) -DCTAGS -c etags.c && mv etags._o ctags.o ``` -------------------------------- ### GNU Hello configure.in Source: http://web.mit.edu/gnu/doc/html/automake.html The configure.in file for GNU Hello, processed by autoconf to produce a configure script. It uses AM_ macros from Automake (or Gettext) and standard Autoconf macros, and outputs several Makefiles plus a test script. ```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]) ``` -------------------------------- ### Initialize Automake with AM_INIT_AUTOMAKE Source: http://web.mit.edu/gnu/doc/html/automake.html Add this call to configure.in after AC_INIT to initialize Automake for the zardoz program. The arguments specify the package name and version. ```autoconf AM_INIT_AUTOMAKE(zardoz, 1.0) ``` -------------------------------- ### Multiple programs with per-program LDADD: bin_PROGRAMS, EXTRA_PROGRAMS Source: http://web.mit.edu/gnu/doc/html/automake.html Shows how to build multiple programs in one directory with different link-time requirements, using per-program LDADD overrides and EXTRA_PROGRAMS for conditionally built programs. ```makefile bin_PROGRAMS = cpio pax @MT@ libexec_PROGRAMS = @RMT@ EXTRA_PROGRAMS = mt rmt LDADD = ../lib/libcpio.a @INTLLIBS@ rmt_LDADD = cpio_SOURCES = ... pax_SOURCES = ... mt_SOURCES = ... rmt_SOURCES = ... ``` -------------------------------- ### tests/Makefile.am Source: http://web.mit.edu/gnu/doc/html/automake.html The tests/Makefile.am for GNU Hello. The script hello is generated by configure and is the only test case; make check will run it. ```makefile TESTS = hello EXTRA_DIST = hello.in testdata ``` -------------------------------- ### Top-level Makefile.am Source: http://web.mit.edu/gnu/doc/html/automake.html The top-level Makefile.am for GNU Hello. It lists extra distribution files and subdirectories where the real work is done. ```makefile EXTRA_DIST = BUGS ChangeLog.O SUBDIRS = doc intl po src tests ``` -------------------------------- ### src/Makefile.am Source: http://web.mit.edu/gnu/doc/html/automake.html The src/Makefile.am for GNU Hello, where all the real work is done. It defines the hello program, its sources, link dependencies, and include flags. ```makefile bin_PROGRAMS = hello hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h hello_LDADD = @INTLLIBS@ @ALLOCA@ localedir = $(datadir)/locale INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\" ``` -------------------------------- ### Set SUBDIRS in configure.in with AC_SUBST Source: http://web.mit.edu/gnu/doc/html/automake.html In configure.in, sets SUBDIRS to a quoted list and uses AC_SUBST to substitute it into Makefile.am, enabling configure to control the build subdirectories. ```autoconf SUBDIRS = "src doc lib po" AC_SUBST(SUBDIRS) ``` -------------------------------- ### Configure LIBOBJS for de-ANSI-fication Source: http://web.mit.edu/gnu/doc/html/automake.html Place this code in configure.in just before the AC_OUTPUT call to ensure that .o files in LIBOBJS are built via the ANSI2KNR-filtering rules. Without it, de-ANSI-fication may fail because configure generates object names like regex.o while make looks for regex_.o. ```shell # This is necessary so that .o files in LIBOBJS are also built via # the ANSI2KNR-filtering rules. LIBOBJS=`echo $LIBOBJS|sed 's/\.o /\$U.o /g;s/\.o$/\$U.o/'` ``` -------------------------------- ### dist-hook target to add files to distribution Source: http://web.mit.edu/gnu/doc/html/automake.html Use this target to add files to the distribution before it is packaged. It runs after the distribution directory is filled but before the tar or shar file is created, allowing you to copy files from subdirectories into the distribution. ```makefile dist-hook: mkdir $(distdir)/random cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random ``` -------------------------------- ### Alternative rules for compilers without -c and -o support Source: http://web.mit.edu/gnu/doc/html/automake.html Alternative rules that work when the compiler does not accept both -c and -o. Introduces a bogus dependency to avoid problems with parallel make. ```makefile etags.o: etags.c ctags.o $(COMPILE) -DETAGS_REGEXPS -c etags.c ctags.o: etags.c $(COMPILE) -DCTAGS -c etags.c && mv etags.o ctags.o ``` -------------------------------- ### Declare Texinfo sources with info_TEXINFOS and texi_TEXINFOS Source: http://web.mit.edu/gnu/doc/html/automake.html Declares the main Texinfo file and additional included Texinfo files for Automake. The first line sets the primary info file, and the second line lists extra .texi files that the main file includes, so Automake knows about the dependency. ```makefile info_TEXINFOS = hello.texi hello_TEXINFOS = gpl.texi ``` -------------------------------- ### Generate etags and ctags from same source with different cpp flags Source: http://web.mit.edu/gnu/doc/html/automake.html Shows how to generate two programs (ctags and etags) from the same source file etags.c, with each compilation requiring different cpp flags. ctags_SOURCES is empty to avoid implicit substitution, and ctags_LDADD adds ctags.o to the link line. ```makefile bin_PROGRAMS = etags ctags ctags_SOURCES = ctags_LDADD = ctags.o etags.o: etags.c $(COMPILE) -DETAGS_REGEXPS -c etags.c ctags.o: etags.c $(COMPILE) -DCTAGS -o ctags.o -c etags.c ``` -------------------------------- ### Regenerate configure with aclocal and autoconf Source: http://web.mit.edu/gnu/doc/html/automake.html Rename an existing aclocal.m4 to acinclude.m4 so aclocal can generate a new one, then run aclocal and autoconf to regenerate configure. ```shell mv aclocal.m4 acinclude.m4 aclocal autoconf ``` -------------------------------- ### Mixing Fortran 77 with C and C++ in Makefile.am Source: http://web.mit.edu/gnu/doc/html/automake.html Shows a Makefile.am that mixes Fortran 77 with C and C++. It requires AC_F77_LIBRARY_LDFLAGS in configure.in and that $(FLIBS) or @FLIBS@ appear in the appropriate _LDADD or _LIBADD variables. ```makefile bin_PROGRAMS = foo foo_SOURCES = main.cc foo.f foo_LDADD = libfoo.la @FLIBS@ pkglib_LTLIBRARIES = libfoo.la libfoo_la_SOURCES = bar.f baz.c zardoz.cc libfoo_la_LIBADD = $(FLIBS) ``` -------------------------------- ### Include file from top-level directory Source: http://web.mit.edu/gnu/doc/html/automake.html Includes a file from the top-level directory using $(top_srcdir). Use this when the file to include is located at the top of the source tree. ```makefile include $(top_srcdir)/filename ``` -------------------------------- ### Include files from current directory Source: http://web.mit.edu/gnu/doc/html/automake.html Shows two ways to include files from the current directory: using $(srcdir) to reference a file in the source directory, and including a file directly by name. Both are valid forms of the include directive. ```makefile include $(srcdir)/Makefile.extra ``` ```makefile include Makefile.generated ``` -------------------------------- ### Conditionally built source: EXTRA_hello_SOURCES Source: http://web.mit.edu/gnu/doc/html/automake.html Lists a source file that is only conditionally built, so Automake knows about it even when it is not compiled in every circumstance. ```makefile EXTRA_hello_SOURCES = hello-linux.c ``` -------------------------------- ### Recursive macro expansion in Makefile.am Source: http://web.mit.edu/gnu/doc/html/automake.html Shows how Automake recursively expands macros referenced in a definition. When examining foo_SOURCES, it uses a.c, b.c, and c.c as the contents. ```makefile xs = a.c b.c foo_SOURCES = c.c $(xs) ``` -------------------------------- ### Set AUTOMAKE_OPTIONS to ansi2knr path Source: http://web.mit.edu/gnu/doc/html/automake.html Set the AUTOMAKE_OPTIONS variable in src/Makefile.am to the relative path to the ansi2knr support files located in the lib subdirectory. This enables de-ANSI-fication for the source files in the current directory. ```makefile AUTOMAKE_OPTIONS = ../lib/ansi2knr ``` -------------------------------- ### Customary first line of Makefile.am Source: http://web.mit.edu/gnu/doc/html/automake.html Customary first line of a Makefile.am file. Lines beginning with ## are ignored by Automake and not copied into the output. ```makefile ## Process this file with automake to produce Makefile.in ``` -------------------------------- ### Add configure-determined objects: library_LIBADD Source: http://web.mit.edu/gnu/doc/html/automake.html Adds extra objects determined by configure to a library, using the canonicalized library name. ```makefile libcpio_a_LIBADD = @LIBOBJS@ @ALLOCA@ ``` -------------------------------- ### Check for required programs with AM_MISSING_PROG Source: http://web.mit.edu/gnu/doc/html/automake.html Use this in configure.in to check for the presence of aclocal, autoconf, automake, autoheader, and makeinfo in the build environment. The missing_dir variable is set to the auxiliary directory before calling AM_MISSING_PROG for each program. ```shell missing_dir=`cd $ac_aux_dir && pwd` AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir) AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir) ``` -------------------------------- ### Set ETAGS_ARGS for custom etags generation Source: http://web.mit.edu/gnu/doc/html/automake.html Defines ETAGS_ARGS to generate tags for Automake's own source and Texinfo nodes. The --lang=none flag and regex pattern target @node lines in the .texi file. Adding filenames here likely requires setting TAGS_DEPENDENCIES as well. ```makefile ETAGS_ARGS = automake.in --lang=none \ --regex='/^@node[ \t]+\([^,]+\)/\1/' automake.texi ``` -------------------------------- ### Override SUBDIRS with configure substitution Source: http://web.mit.edu/gnu/doc/html/automake.html Overrides SUBDIRS in Makefile.am to use a configure substitution, allowing the subdirectory list to be determined at configure time. ```makefile SUBDIRS = @SUBDIRS@ ``` -------------------------------- ### Set TEXINFO_TEX variable Source: http://web.mit.edu/gnu/doc/html/automake.html Sets the relative path to the canonical texinfo.tex file for packages with Texinfo files in multiple directories. The value should be the relative path from the current Makefile.am to texinfo.tex. ```makefile TEXINFO_TEX = ../doc/texinfo.tex ``` -------------------------------- ### Define DEBUG conditional with AM_CONDITIONAL Source: http://web.mit.edu/gnu/doc/html/automake.html Defines a conditional DEBUG that is true when the user passes --enable-debug to configure. The AC_ARG_ENABLE macro handles the option and sets debug to true or false, with an error for invalid values. AM_CONDITIONAL then creates the conditional based on the shell test. ```m4 AC_ARG_ENABLE(debug, [ --enable-debug Turn on debugging], [case "${enableval}" in yes) debug=true ;; no) debug=false ;; *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;; esac],[debug=false]) AM_CONDITIONAL(DEBUG, test x$debug = xtrue) ``` -------------------------------- ### Use DEBUG conditional in Makefile.am Source: http://web.mit.edu/gnu/doc/html/automake.html Uses the DEBUG conditional in Makefile.am to set DBG to 'debug' when the conditional is true, or empty otherwise. The variable is then used in noinst_PROGRAMS to conditionally build the program. ```makefile if DEBUG DBG = debug else DBG = endif noinst_PROGRAMS = $(DBG) ``` -------------------------------- ### Add new suffixes to SUFFIXES for custom rules Source: http://web.mit.edu/gnu/doc/html/automake.html Adds new suffixes to the SUFFIXES variable so GNU Make recognizes the new implicit rule for .java and .class files. Required when introducing a custom rule for a file type Automake does not know about. ```makefile SUFFIXES = .java .class ``` -------------------------------- ### Rename yacc symbols for multiple parsers Source: http://web.mit.edu/gnu/doc/html/automake.html Renaming hack used in gdb to allow linking multiple yacc parsers into the same executable. The output of yacc always uses the same symbol names internally, so this renames the symbols to avoid conflicts. ```c #define yymaxdepth c_maxdepth #define yyparse c_parse #define yylex c_lex #define yyerror c_error #define yylval c_lval ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.