Is there a way to direct make/gmake to act upon conditional dependencies?
I have this rule in place:
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CPPC) -c $(FLAGS_DEV) $< -o $@
In the general case, every .cpp file has a corresponding .h file; however there are a few exceptions. Is there a way to achieve "depend on this if it exists" with gmake? Failing that, is there a best practice for this type of setup?
Thanks in advance; Cheers!
Update: I'm using GCC
A better way to do this, is to actually determine the dependencies of the cpp files with gcc -MM and include them in the makefile.
SRCS = main.cpp other.cpp
DEPS = $(SRCS:%.cpp=$(DEP_DIR)/%.P)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CPPC) -c $(FLAGS_DEV) $< -o $@
$(DEP_DIR)/%.P: $(SRC_DIR)/%.cpp
$(CPPC) -MM $(FLAGS_DEV) -MT $(OBJ_DIR)/$*.o -MP -MF $@ $<
-include $(DEPS)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With