program.mak 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # $(LIB_MAKES) - Shared libary make files to depend on - to ensure we get
  8. # remade when the shared library version increases.
  9. # See defaults.mak for information about LOCAL
  10. # Some local definitions
  11. LOCAL := $(PROGRAM)
  12. $(LOCAL)-OBJS := $(addprefix $(OBJ)/,$(addsuffix .o,$(notdir $(basename $(SOURCE)))))
  13. $(LOCAL)-DEP := $(addprefix $(DEP)/,$(addsuffix .o.d,$(notdir $(basename $(SOURCE)))))
  14. $(LOCAL)-BIN := $(BIN)/$(PROGRAM)
  15. $(LOCAL)-SLIBS := $(SLIBS)
  16. $(LOCAL)-MKS := $(addprefix $(BASE)/,$(LIB_MAKES))
  17. # Install the command hooks
  18. program: $(BIN)/$(PROGRAM)
  19. clean: clean/$(LOCAL)
  20. veryclean: veryclean/$(LOCAL)
  21. # The clean rules
  22. .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
  23. clean/$(LOCAL):
  24. -rm -f $($(@F)-OBJS) $($(@F)-DEP)
  25. veryclean/$(LOCAL): clean/$(LOCAL)
  26. -rm -f $($(@F)-BIN)
  27. # The binary build rule
  28. $($(LOCAL)-BIN): $($(LOCAL)-OBJS) $($(LOCAL)-MKS)
  29. echo Building program $@
  30. $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LFLAGS) -o $@ $(filter %.o,$^) $($(@F)-SLIBS) $(LEFLAGS)
  31. # Compilation rules
  32. vpath %.cc $(SUBDIRS)
  33. $(OBJ)/%.o: %.cc
  34. echo Compiling $< to $@
  35. $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
  36. $(DoDep)
  37. # Include the dependencies that are available
  38. The_DFiles = $(wildcard $($(LOCAL)-DEP))
  39. ifneq ($(words $(The_DFiles)),0)
  40. include $(The_DFiles)
  41. endif