automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Automatic dependency tracking when using non-depcomp tools


From: Hans Ulrich Niedermann
Subject: Automatic dependency tracking when using non-depcomp tools
Date: Sat, 19 Nov 2022 23:23:54 +0100

I have not found any documentation about hooking recipes with custom
(non-depcomp) tools into Automake's automatic dependency tracking,
so this describes what I have done to achieve that along with a few
questions.

If you want the complete code example, see the git branch at
https://github.com/ndim/xnec2c/tree/buildsystem-cleanups which
is part of the Pull Request https://github.com/KJ7LNW/xnec2c/pull/17.

The following text describes a simplified version of the xnec2c case.

The glib-compile-resources tool generates a *.c file from an *.xml
file and possibly some files included from that *.xml file.

Fortunately, the glib-compile-resources tool can also create a
dependency file for inclusion into Makefile as a side-effect of
compilation, but obviously Automake/depcomp do not know about
glib-compile-resources and therefore I need to hook that into
Makefile.am myself.

Automake does automatic dependency tracking via one
./$(DEPDIR)/*.Po file listed in the am__depfiles_remade make var
per *.c source file, and then one include line per *.Po file and
a recipe with $(am__depfiles_remade) target and no dependencies
which creates a dummy no-op *.Po file to be used before the first
actual compilation. (The first compilation will later create the
*.Po file containing actual file dependencies.)

    include ./$(DEPDIR)/bar.Po # am--include-marker
    include ./$(DEPDIR)/main.Po # am--include-marker

    $(am__depfiles_remade):
            @$(MKDIR_P) $(@D)
            @echo '# dummy' >$@-t && $(am__mv) $@-t $@

Mimicking what the depcomp-based automatic dependency tracking does
without relying on its internals, I "include" my own dependency
file and provide an explicit recipe to create a dummy dep file to
use before the first compilation happens, and also make sure that it
is removed at "make distclean" like the *.Po files are:

    DISTCLEANFILES += ./$(DEPDIR)/foo-resources.cdep
    include ./$(DEPDIR)/foo-resources.cdep
    ./$(DEPDIR)/foo-resources.cdep:
            @$(MKDIR_P) $(@D)
            @echo '# dummy' >$@-t && $(am__mv) $@-t $@

Luckily, the "include" line is copied verbatim from Makefile.am
to Makefile.in and Makefile and not evaluated by Automake, so this
works.

Then I must write the recipe which does the actual compilation with
the side effect of generating the dependency file:

    foo_SOURCES += foo-resources.c
    CLEANFILES  += foo-resources.c
    foo-resources.c: $(srcdir)/foo.gresource.xml
            $(GLIB_COMPILE_RESOURCES) \
              --sourcedir=$(srcdir) \
              --dependency-file=./$(DEPDIR)/foo-resources.cdep \
              --target=foo-resources.c \
              --generate-source \
              $(srcdir)/foo.gresource.xml

As foo-resources.c is listed in foo_SOURCES, I do not need to list
it in BUILT_SOURCES. Also, the generated file should be cleaned.

Then the recipe both creates the *.c file from *.xml (and whatever
that *.xml includes internally), and creates the dependency file
from the internal includes.

  Question: Is it OK for me to hook into ./$(DEPDIR)/ at all?
            I could use just some file in $(builddir), after all.

  Question: Is *.cdep a good name? I want to avoid name collisions.

  Question: Is it ok for me to use $(am__mv)?

Documentation used:

  2.2.12 Automatic Dependency Tracking
  https://www.gnu.org/software/automake/manual/automake.html#Dependency-Tracking

  8.19 Automatic dependency tracking
  https://www.gnu.org/software/automake/manual/automake.html#Dependencies



reply via email to

[Prev in Thread] Current Thread [Next in Thread]