0
votes

Say there are a bunch of (e.g. nearly 200) modules that all depend on a core module. All are using Autotools.

The core module installs a core.m4 file which the dependents already use for various things.

All the dependents also have some lines in their install-data-local rule to generate some scripts and install them, e.g.

core_stuffdir=$(prefix)/share/core/stuff/

install-data-local:
        generate-stuff stuff.xml
        test -d $(DESTDIR)$(core_stuffdir) || mkdir $(DESTDIR)$(core_stuffdir)
        stuff=`xmllint --xpath '//stuff[@install="yes"]/@name' stuff.xml`; \
            $(INSTALL_DATA) $$stuff $(DESTDIR)$(core_stuffdir); \
            rm $$stuff
        …
        $(INSTALL_DATA) other-module-specific-stuff …
        …

I would like to remove those five lines which are currently redundantly duplicated over ~200 files, and instead define the lines in the core.m4. The dependents should be able to say something like SOMEVAR: somevalue (or something similarly short, at worst a one-line thing in install-data-local) and have those lines executed during make install.

Is there a nice way to do define these lines in core.m4 and make them available to Makefile.am? I can't find any similar examples on the net.

The only solution I can think of now is that the m4 spits out a shell script that I can call from install-data-local, but I'm not sure that's the best (or most autotoolish) way.

Alternatively, is there a simple way to distribute an automake fragment.am file from my core module? (This seems to be the way e.g. Python compilation rules are defined.)

1

1 Answers

2
votes

After some digging, I found http://thread.gmane.org/gmane.comp.sysutils.automake.general/5704/focus=5708 which has a solution to a similar problem (I couldn't get the AC_CONFIG_FILES solution mentioned there to work).

So core.m4 now defines CORE_MKINCLUDE:

AC_DEFUN([CORE_MKINCLUDE],
[
  AC_SUBST_FILE(core_include)
  core_include=$srcdir/core_include.am

  cat >$srcdir/core_include.am <<EOF

core_stuffdir=\$(prefix)/share/core/stuff/
install-stuff:
        generate-stuff stuff.xml
        test -d \$(DESTDIR)\$(core_stuffdir) || mkdir \$(DESTDIR)\$(core_stuffdir)
        stuff=\`xmllint --xpath '//stuff@<:@@install="yes"@:>@/@name' stuff.xml`; \\
                \$(INSTALL_DATA) \$\$stuff \$(DESTDIR)\$(core_stuffdir); \\
                rm \$\$stuff

EOF

])

Ie. the goal is now printed to the file core_include.am, and has its own name. Each module's configure.ac calls CORE_MKINCLUDE, and each Makefile.am just has

@core_include@
install-data-local: install-stuff

An improvement at least.