I originally had two implicit rules(simplified for clarity):
%$(EXESUFFIX) : %.c
$(CC) -o $* $<
%$(EXESUFFIX) : %.cpp
$(CXX) -o $* $<
But the problem is that on OS X and Linux $(EXESUFFIX) is blank which leads the rule to match the wrong things. So I am trying to use the static pattern rule as follows:
$(EXECS) : %$(EXESUFFIX) : %.c
$(CC) -o $* $<
$(EXECS) : %$(EXESUFFIX) : %.cpp
$(CXX) -o $* $<
Where $(EXECS) is the target and therefore devoid of the extension. But now, the top rule is being run for sources which end in .cpp. How do I fix this?
For a complete example:
Makefile:
EXESUFFIX =
EXECS = test
$(EXECS) : %$(EXESUFFIX) : %.c
$(CC) -o $* $<
$(EXECS) : %$(EXESUFFIX) : %.cpp
$(CXX) -o $* $<
test.cpp:
#include <stdio.h>
int main(int argc, char *argv[]){
printf("Hello World\n");
return 0;
}
This prints out the errors:
Makefile:8: warning: overriding commands for target `test' Makefile:5: warning: ignoring old commands for target `test' make: *** No rule to make target `test.c', needed by `test'. Stop.
lsof your source dir..cppand the filename without the extension is in the$(EXECS)list do the bottom rule, if it ends with.cppdo the top rule. That idea holds in the top case (without the static pattern rule), but not with the static pattern rule.test, with two prerequisites, buttest.cdoes not exist and make doesn't know how to create it. Why do you need separate rules fortestin the first place?