program.mak 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- make -*-
  2. # This creates a program
  3. # Input
  4. # $(SOURCE) - The source code to use
  5. # $(PROGRAM) - The name of the program
  6. # $(SLIBS) - Shared libs to link against
  7. # See defaults.mak for information about LOCAL
  8. # Some local definitions
  9. LOCAL := $(PROGRAM)
  10. $(LOCAL)-OBJS := $(addprefix $(OBJ)/,$(addsuffix .o,$(notdir $(basename $(SOURCE)))))
  11. $(LOCAL)-DEP := $(addprefix $(DEP)/,$(addsuffix .d,$(notdir $(basename $(SOURCE)))))
  12. $(LOCAL)-BIN := $(BIN)/$(PROGRAM)
  13. $(LOCAL)-SLIBS := $(SLIBS)
  14. # Install the command hooks
  15. program: $(BIN)/$(PROGRAM)
  16. clean: clean/$(LOCAL)
  17. veryclean: veryclean/$(LOCAL)
  18. # The clean rules
  19. .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
  20. clean/$(LOCAL):
  21. -rm -f $($(@F)-OBJS) $($(@F)-DEP)
  22. veryclean/$(LOCAL): clean/$(LOCAL)
  23. -rm -f $($(@F)-BIN)
  24. # The binary build rule
  25. $($(LOCAL)-BIN): $($(LOCAL)-OBJS)
  26. echo Building program $@
  27. $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LFLAGS) $($(LOCAL)-SLIBS) -o $@ $(filter %.o,$^)
  28. # Compilation rules
  29. vpath %.cc $(SUBDIRS)
  30. $(OBJ)/%.o: %.cc
  31. echo Compiling $< to $@
  32. $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
  33. $(DoDep)
  34. # Include the dependencies that are available
  35. The_DFiles = $(wildcard $($(LOCAL)-DEP))
  36. ifneq ($(words $(The_DFiles)),0)
  37. include $(The_DFiles)
  38. endif