4

I was reading the POSIX 7 Make definition, and I've noticed that prerequisites are almost always described as “files”:

The make utility examines time relationships and shall update those derived files (called targets) that have modified times earlier than the modified times of the files (called prerequisites) from which they are derived.

Does that mean that a POSIX-compliant make should interpret rules like

binary.bin: src/main.c src/1.dir/*.c src/2.dir/*.c
    $(CC) -o binary.bin src/main.c src/1.dir/*.c src/2.dir/*.c

As literally looking for files named *.c in src/1.dir/ and src/2.dir/?

Does this also mean that, when using a POSIX-compliant make, the users have to enumerate every file in a project in the makefile?

1

I don't think there's any "lean" implementation of make which implements only the features required by the POSIX spec, and which could be used to validate makefiles for POSIX compliance. The POSIX make spec is pretty poor, leaving a lot of stuff underspecified, but including dubious and useless features.

FWIW, all Unix make implementations (including GNU make, BSD make, the dmake from solaris, etc) will expand glob patterns in both the target and the prerequisites. And this dates back to the very first implementation of make from Unix v7. Quoting from the original documentation:

Other lines give information about target files. The general form of an entry is:

target1 [target2 . . .] :[:] [dependent1 . . .] [; commands] [# . . .]
[(tab) commands] [# . . .]
 . . .

Items inside brackets may be omitted. Targets and dependents are strings of letters, digits, periods, and slashes. (Shell metacharacters * and ? are expanded.)

And tested in practice:

# touch foo.bar zoo.bar

# echo 'foo: *.bar; echo "($?)"' | make -f -
echo "(zoo.bar foo.bar)"
(zoo.bar foo.bar)

# echo 'foo: [zf]oo.bar; echo "($?)"' | make -f -
echo "(zoo.bar foo.bar)"
(zoo.bar foo.bar)
  • Wikipedia says that the first make was actually from PWB/UNIX 1, which was based on UNIX V6. This make's manpage doesn't seem to mention globs, although maybe it does in Make - A Program for Maintaining Computer Programs, which I cannot find. Anyway, thank you for your answer. I guess POSIX simply lacks here. – Ainar-G Apr 21 at 19:58
  • 1
    that "Make - A Program ..." paper is in the link from my answer (there was a site with all those docs processed into *.pdfs, but I don't remember it). But FWIW, the make from that pwb1 tape is newer than that from v7, and it certainly does globbing. Look at the amatch() function from files.c. – Uncle Billy Apr 21 at 20:16
  • The source code, duh. Why didn't I think of looking at it? I am extra sloppy today. Thanks again! – Ainar-G Apr 21 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.