Reputation: 1891
In the following makefile snippet:
common.o :
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MF "[email protected]" -c miwt_os/dispatcher/common.cpp
-include commono.o.d
array_safe.o :
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MF "[email protected]" -c miwt_os/dispatcher/array_safe.cpp
-include array_safe.o.d
tstamp.o :
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MF "[email protected]" -c miwt_os/dispatcher/tstamp.cpp
-include tstamp.o.d
cbor_encoder.o :
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MF "[email protected]" -c miwt_os/coap/cbor_encoder.cpp
-include cbor_encoder.o.d
cbor_encoder_test.o :
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MF "[email protected]" -c miwt_os/coap/unittest/cbor_encoder_test.cpp
-include cbor_encoder_test.o.d
cbor_encoder_test : array_safe.o tstamp.o cbor_encoder_test.o cbor_encoder.o \
common.o gmock_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
Notice how the dependency file name is auto-generated by "[email protected]", but then when it is included, I have to manually enter the name of dependency the file. Any way to automatically generate the dependency file name?
Upvotes: 0
Views: 30
Reputation: 100926
If you had a variable containing the list of object files, instead of inlining them, then it would be trivial:
OBJS = array_safe.o tstamp.o cbor_encoder_test.o cbor_encoder.o common.o
-include $(addsuffix .d,$(OBJS))
cbor_encoder_test : $(OBJS) gmock_main.a
...
I should point out that this method of dealing with auto-generated header files is suboptimal; there are better ways.
Upvotes: 2