automake: Scripts

1 
1 9.1 Executable Scripts
1 ======================
1 
1 It is possible to define and install programs that are scripts.  Such
1 programs are listed using the ‘SCRIPTS’ primary name.  When the script
1 is distributed in its final, installable form, the ‘Makefile’ usually
1 looks as follows:
1 
1      # Install my_script in $(bindir) and distribute it.
1      dist_bin_SCRIPTS = my_script
1 
1    Scripts are not distributed by default; as we have just seen, those
1 that should be distributed can be specified using a ‘dist_’ prefix as
1 with other primaries.
1 
1    Scripts can be installed in ‘bindir’, ‘sbindir’, ‘libexecdir’,
1 ‘pkglibexecdir’, or ‘pkgdatadir’.
1 
1    Scripts that need not be installed can be listed in ‘noinst_SCRIPTS’,
1 and among them, those which are needed only by ‘make check’ should go in
1 ‘check_SCRIPTS’.
1 
1    When a script needs to be built, the ‘Makefile.am’ should include the
1 appropriate rules.  For instance the ‘automake’ program itself is a Perl
1 script that is generated from ‘automake.in’.  Here is how this is
1 handled:
1 
1      bin_SCRIPTS = automake
1      CLEANFILES = $(bin_SCRIPTS)
1      EXTRA_DIST = automake.in
1 
1      do_subst = sed -e 's,[@]datadir[@],$(datadir),g' \
1                  -e 's,[@]PERL[@],$(PERL),g' \
1                  -e 's,[@]PACKAGE[@],$(PACKAGE),g' \
1                  -e 's,[@]VERSION[@],$(VERSION),g' \
1                  ...
1 
1      automake: automake.in Makefile
1              $(do_subst) < $(srcdir)/automake.in > automake
1              chmod +x automake
1 
1    Such scripts for which a build rule has been supplied need to be
1 deleted explicitly using ‘CLEANFILES’ (⇒Clean), and their sources
11 have to be distributed, usually with ‘EXTRA_DIST’ (⇒Basics of
 Distribution).
1 
1    Another common way to build scripts is to process them from
1 ‘configure’ with ‘AC_CONFIG_FILES’.  In this situation Automake knows
1 which files should be cleaned and distributed, and what the rebuild
1 rules should look like.
1 
1    For instance if ‘configure.ac’ contains
1 
1      AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
1 
1 to build ‘src/my_script’ from ‘src/my_script.in’, then a
1 ‘src/Makefile.am’ to install this script in ‘$(bindir)’ can be as simple
1 as
1 
1      bin_SCRIPTS = my_script
1      CLEANFILES = $(bin_SCRIPTS)
1 
1 There is no need for ‘EXTRA_DIST’ or any build rule: Automake infers
1 them from ‘AC_CONFIG_FILES’ (⇒Requirements).  ‘CLEANFILES’ is
1 still useful, because by default Automake will clean targets of
1 ‘AC_CONFIG_FILES’ in ‘distclean’, not ‘clean’.
1 
1    Although this looks simpler, building scripts this way has one
1 drawback: directory variables such as ‘$(datadir)’ are not fully
1 expanded and may refer to other directory variables.
1