Tool listed as dependency, how to run
09:30 05 Sep 2026

I have a rule in an (automake-processed, but that should not matter here) Makefile:

output: $(srcdir)/tool.sed input
    $^ >$@

The output should be regenerated when the sed script is changed, or the input is changed, so both are listed as dependencies.

The srcdir variable is the relative path to the unpacked source, which is either . if we're doing an in-place build, or something like ../../src if it is an out-of-tree build.

Now if srcdir is ., Make is helpful and normalizes the file path to tool.sed, which cannot be called (even though it is executable) because . is not in PATH.

I'd like to avoid writing sed -f in front into the Makefile, since some of the scripts also use sed's -n option, so they start with #! /usr/bin/sed -nf.

Is there a good, ideally portable, way to invoke a program that may be in the current directory?

makefile gnu-make automake