bugmake - Bugs: bug #48970, unclear which prerequisites...


bug #48970: unclear which prerequisites included in $? for intermediate targets

Submitted by:  Sam Fok <fragapanagos>
Submitted on:  Thu 01 Sep 2016 07:22:48 PM UTC  
Severity:  3 - Normal Item Group:  Documentation
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open
Component Version:  3.81 Operating System:  POSIX-Based
Fixed Release:  None Triage Status:  None

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Thu 01 Sep 2016 07:22:48 PM UTC, original submission:

I have the following Makefile with intermediate target ${LIST}.


TGT := tgt
LIST := list

all: ${TGT}

${TGT}: ${LIST}
touch `cat ${LIST}`
touch $@

${LIST}: foo1.in foo2.in
echo $(?:in=out) > ${LIST}

touch foo$*.in

rm -f foo*
rm -f ${LIST}
rm -f ${TGT}

.PHONY: all clean


When any of ${LIST}'s prerequisite's is newer than ${TGT}, the ${LIST} recipe is executed. However, if .INTERMEDIATE file ${LIST} does not exist, it is unclear from the documentation which ${LIST} prerequisite would be included in ${?} in the ${LIST} recipe. Would it be only the prerequisites that were newer than ${TGT} or all prerequisites because ${LIST} does not exist? The following shell session illustrates the confusion.

$ ls # to show directory state.
$ make
touch foo1.in
touch foo2.in
echo foo1.out foo2.out > list
touch `cat list`
touch tgt
rm list
$ make # to show that make ran successfully
make: Nothing to be done for `all'.
$ touch foo1.in # update foo1.in to be newer than tgt
$ make
echo foo1.out foo2.out > list
touch `cat list`
touch tgt


Since list's prerequisite foo1.in was newer than tgt, list's recipe was executed. However, I expected only foo1.in to be included in ${?} because foo1.in alone was newer than tgt and so foo1.in alone caused list's recipe to be executed.

On intermediate files, the documentation states that

The first difference is what happens if the intermediate file does not exist. If an ordinary file b does not exist, and make considers a target that depends on b, it invariably creates b and then updates the target from b. But if b is an intermediate file, then make can leave well enough alone. It won’t bother updating b, or the ultimate target, unless some prerequisite of b is newer than that target or there is some other reason to update that target.

There is no mention of which prerequisites of b will be considered to be newer than b. The documentation for $? also does not mention intermediate targets.

Sam Fok <fragapanagos>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by fragapanagos (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    No changes have been made to this item

    Back to the top

    Powered by Savane 3.3