Automake's implicit copying semantics means that many problems can be
worked around by simply adding some make
targets and rules to
Makefile.in
. Automake will ignore these additions.
There are some caveats to doing this. Although you can overload a
target already used by Automake, it is often inadvisable, particularly
in the topmost directory of a package with subdirectories. However,
various useful targets have a -local
version you can specify in
your Makefile.in
. Automake will supplement the standard target
with these user-supplied targets.
The targets that support a local version are all
, info
,
dvi
, ps
, pdf
, check
, install-data
,
install-exec
, uninstall
, installdirs
,
installcheck
and the various clean
targets
(mostlyclean
, clean
, distclean
, and
maintainer-clean
). Note that there are no
uninstall-exec-local
or uninstall-data-local
targets; just
use uninstall-local
. It doesn't make sense to uninstall just
data or just executables.
For instance, here is one way to install a file in /etc
:
install-data-local: $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
Some targets also have a way to run another target, called a hook,
after their work is done. The hook is named after the principal target,
with -hook
appended. The targets allowing hooks are
install-data
, install-exec
, uninstall
, dist
,
and distcheck
.
For instance, here is how to create a hard link to an installed program:
install-exec-hook: ln $(DESTDIR)$(bindir)/program$(EXEEXT) \ $(DESTDIR)$(bindir)/proglink$(EXEEXT)
Although cheaper and more portable than symbolic links, hard links
will not work everywhere (for instance OS/2 does not have
ln
). Ideally you should fall back to cp -p
when
ln
does not work. An easy way, if symbolic links are
acceptable to you, is to add AC_PROG_LN_S
to
configure.in
(see Particular Program Checks) and use $(LN_S)
in
Makefile.am
.
For instance, here is how you could install a versioned copy of a
program using $(LN_S)
:
install-exec-hook: cd $(DESTDIR)$(bindir) && \ mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \ $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
Note that we rename the program so that a new version will erase the
symbolic link, not the real binary. Also we cd
into the
destination directory in order to create relative links.