3 ms·
One other dependency often forgotten is on the Makefile itself. This way if the Makefile changes, everything gets rebuilt: DEPS = Makefile %.o: %.c $(
by pdq 12y ago
One other dependency often forgotten is on the Makefile itself. This way if the Makefile changes, everything gets rebuilt:
DEPS = Makefile
%.o: %.c $(DEPS)
$(CC) $(CCFLAGS) -o $@ -c $<
- exDM69 12y agoThis may or may not be what you want, depending on the use case. If you change an important variable in the Makefile (e.g. CFLAGS), you might want to recompile everything. However, if you're just adding a new source file to the Makefile, you definitely do not want to rebuild everything. I prefer to run `make clean` manually when necessary rather than adding a rule to rebuild everything "just in case". But I can imagine that this might be useful in some cases.
- atrn 12y agoI like to put CFLAGS/CXXFLAGS et al in separate files that just define the corresponding macro. These get included in the makefile which has dependencies added to rules that reference such a macro on the file that defines the macro. E.g. the .o rule for C++ has a dependency on the CXXFLAGS which defines CXXFLAGS. Change CXXFLAGS and things rebuild, mess with LDFLAGS and you re-link etc... Handy if you need it but you can end up with lots of little files.