Note that there are some explanatory texts on larger screens.

plurals
  1. POEnsuring a prerequisite exists for a pattern rule
    primarykey
    data
    text
    <p>I understand that an "explicit" pattern rule will take precedence on its implicit counterpart when its prerequisites can be made.</p> <pre><code>all: src/foo.o src/%.o: makefile my_haeder.h src/%.c echo Do something with those source files</code></pre> <p>If there is a typo for "my_header.h", the implicit rule for %.o will take precedence. Not only my recipe will not be executed, but touching the prerequisites will not trigger the rule. Actually it is the second point which is of interest for me.</p> <p>The make documentation offers a verification using static pattern rules:</p> <pre><code>SET_OF_FILES=src/foo.o all: src/foo.o $(SET_OF_FILES): src/%.o: makefile my_haeder.h src/%.c echo Do something with those source files</code></pre> <p>This results in:</p> <pre><code>gmake: *** No rule to make target `src/my_haeder.h', needed by `src/foo.o'. Stop.</code></pre> <p>Though a larger rule, that solution is nice, as long as I don't have to add a rule for which the stem could overlap:</p> <pre><code>SET_OF_FILES=src/foo.o src/subsrc/bar.o all: src/foo.o $(SET_OF_FILES): src/%.o: makefile my_header.h src/%.c echo Do something with those source files $(SET_OF_FILES): src/subsrc/%.o: makefile my_header.h src/subsrc/%.c echo Do something with those other source files</code></pre> <p>Which results in:</p> <pre><code>makefile:8: target `src/foo.o' doesn't match the target pattern makefile:9: warning: overriding commands for target `src/foo.o' makefile:6: warning: ignoring old commands for target `src/foo.o' makefile:9: warning: overriding commands for target `src/subsrc/bar.o' makefile:6: warning: ignoring old commands for target `src/subsrc/bar.o'</code></pre> <p>The first message is here because I didn't bother $(filter)ing SET_OF_FILES. I don't know how to solve the next warnings, which for any reviewer would mean "something's wrong".</p> <p>Is there another (more elegant) way to verify that the prerequisites are actually feasible, in order to avoid dropping the explicit pattern rule?</p> <p>(using GNU Make 3.79.1 win32)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload