Simple header dependency generation
Posted: Wed Jul 04, 2012 2:41 pm
Here's an example I thought may be useful to some. It took me the last two years of trying and giving up and trying again to finally come up with this.
As you may notice, I don't support C or asm files. This isn't a kernel makefile. I haven't felt like messing with kernel programming for a while now. But, the automatic header dependency generation is still useful.
If anyone wants help extending it to support C and asm files, I can help with that. I intend to do it anyway, whenever I get back in the mood to do some kernel programming.
Code: Select all
BINDIR =
OBJDIR =obj
HEADERS =$(wildcard *.hpp)
SOURCES =$(wildcard *.cpp)
OBJECTS =$(foreach SOURCE, $(SOURCES), $(patsubst %.cpp, %.o, $(SOURCE)))
TARGETS =number-theory
CXX =clang++
CXXFLAGS =-ggdb -std=c++0x -Wall
LD =clang++
LDFLAGS =-ggdb -lgmpxx
.PHONY : all
all : $(TARGETS)
.PHONY : clean
clean :
$ rm -f -r $(OBJECTS)
number-theory : $(OBJECTS)
$(LD) $(LDFLAGS) -o nt $(OBJECTS)
define cxx-rule
$(subst \,, $(OBJDIR)/$(strip $(shell $(CXX) -MM $(1))))
$(CXX) $(CXXFLAGS) -c -o $(OBJDIR)/$(strip $(patsubst %.cpp, %.o, $(1))) $(1)
endef
$(foreach SOURCE, $(filter %.cpp, $(SOURCES)), $(info $(call cxx-rule, $(SOURCE))))
If anyone wants help extending it to support C and asm files, I can help with that. I intend to do it anyway, whenever I get back in the mood to do some kernel programming.