0
votes

I have this rule in my Makefile:

%: ${OBJ}/%.o ${OBJ}/AgentProgram.o ${LIB}
    $(CXX) $^ ${LDFLAGS} ${LIB_DIRS} ${LIBS} $(OUTPUT_OPTION)

If obj/Foo.o exists, make will use this rule. However, if the object doesn't already exist, it will use the built-in rule and attempt to directly compile from my .cpp.

Is there some way to define this rule as the default, or turn off the built-in rule?

My workaround is to modify my make bins target to produce all .o files first. It wasn't that hard in this case, I altered:

bins: ${BINS}

and turned it into this: (I already had ${OBJECTS} available)

bins: ${OBJECTS} ${BINS}
1

1 Answers

1
votes

You can cancel pattern rules, including built-in pattern rules, by defining them without a recipe:

%: %.c
%: %.cpp

will remove the pattern rule for creating binaries from a .c and a .cpp.

Or, with a sufficiently new version of GNU make, you can disable ALL builtin rules by adding this to your makefile:

MAKEFLAGS += -r

(see the manual for the meaning of the -r option).