Hello,

thank you very much for your response!  It helped me a lot.

Nick Bowler <nbow...@draconx.ca> writes:

> On Fri, Jul 18, 2025 at 05:24:31PM +0200, Tomas Volf wrote:
>> I am looking into how to add a dependency tracking into the build
>> process of my project.  The project is written in GNU Guile, so it does
>> not track them out of the box.  GNU Automake has a feature to track
>> dependencies -- described in (automake)Dependencies -- however I did not
>> manage to find any documentation on whether it is possible to add user
>> provided tooling for new languages.
>
> There is unfortunately no documented or "officially supported" way to
> do this.
>
> That being said, while Automake's dependency tracking internals are not
> part of the public documented interface it works in a very simple way
> and it is relatively straightforward to extend it.
>
> There are basically three steps:
>
>  (a) Update your makefile rules to write dependency information,
>  (b) Extend config.status am-depfiles to create stub depfiles,
>  (c) Add the needed include directives to Makefile.am.
>
> For (a) this is all your own code so there is no real problem, although
> you might want to use the (undocumented) AMDEP conditional in order to
> not waste time generating dependency information when the package is
> configured with --disable-dependency-tracking.

Well, after more time than it should have taken, I have something that
works well enough.  Most of the time.  Turned out it can get bit finicky
in flexible interpreted languages without support from the compiler.

I still have few bugs I need to address and more testing to do.

>
> For (b), current versions of Automake generate the stubs using the
> am--depfiles make rule.  You can extend this by adding your own rule as
> a prerequisite, which will then be run by ./config.status am-depfiles.
>
> depfiles_rule = am--depfiles
> $(depfiles_rule): generate-depfile-stubs
> generate-depfile-stubs:
>       [create stubs here]
>
> For (c), write into Makefile.am (changing $(DEPDIR)/file.P as appropriate):
>
> @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/file.P@am__quote@ # 
> am--include-marker
>
> one line for each dependency file that will be generated.

(b) and (c) are where I got a bit stuck though.  I really wanted to
avoid having to add a line per file, I have a lot of them.

In the end I figured out it *seems* to be possible to do it by just
generating a new Makefile for the rules and include them that way:

--8<---------------cut here---------------start------------->8---
depfileguild = $(top_srcdir)/build-aux/depfileguild
EXTRA_DIST += build-aux/depfileguild

depfiles_rule = am--depfiles
$(depfiles_rule): $(DEPDIR)/guild.P
$(DEPDIR)/guild.P:
        @$(MKDIR_P) $(@D)
        @DEPDIR=$(DEPDIR) $(depfileguild) $(GO_FILES) $(GO_FILES_TEST) >$@
CLEANFILES += $(DEPDIR)/guild.P
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/guild.P@am__quote@ # 
am--include-marker
--8<---------------cut here---------------end--------------->8---

With the script being quite simple:

--8<---------------cut here---------------start------------->8---
file2dep() {
        printf '%s/%s/%s.Pgo\n' \
               "$(dirname "$1")" "$DEPDIR" "$(basename "$1" .go)"
}

for go in "$@"; do
        dep=$(file2dep "$go")
        mkdir -p "$(dirname "$dep")"
        touch "$dep"

        cat <<EOF
include $dep
clean-local: clean-Pgo-$dep
clean-Pgo-$dep:
        -rm -rf $dep
EOF
done
--8<---------------cut here---------------end--------------->8---

I am not using the @am__include@ here, but I am fine with targeting only
Makes supporting literal `include' statement.

As I wrote, this *seems* to work, but I wonder in what issues I will
run.

Maybe a bit easier option would be to use:

--8<---------------cut here---------------start------------->8---
-include $(GO_FILES:.go=.Pgo)
-include $(GO_FILES_TEST:.go=.Pgo)
--8<---------------cut here---------------end--------------->8---

Which is now POSIX, but I am unsure how widely is this syntax actually
supported.  Another downside is that the files would not be in the
$(DEPDIR), I did not figure out how to do that.

Thanks once more,
Tomas

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

Reply via email to