program.mak 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 library 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. TYPE = src
  22. include $(PODOMAIN_H)
  23. # Make Directories
  24. MKDIRS += $(OBJ) $(DEP) $(BIN)
  25. # The clean rules
  26. .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
  27. clean/$(LOCAL):
  28. -rm -f $($(@F)-OBJS) $($(@F)-DEP)
  29. veryclean/$(LOCAL): clean/$(LOCAL)
  30. -rm -f $($(@F)-BIN)
  31. # The convience binary build rule
  32. .PHONY: $(PROGRAM)
  33. $(PROGRAM): $($(LOCAL)-BIN)
  34. # The binary build rule
  35. $($(LOCAL)-BIN): $($(LOCAL)-OBJS) $($(LOCAL)-MKS)
  36. echo Building program $@
  37. $(CXX) $(CXXSTD) $(CXXFLAGS) $(LDFLAGS) $(LFLAGS) -o $@ $(filter %.o,$^) $($(@F)-SLIBS) $(LEFLAGS)
  38. # Compilation rules
  39. vpath %.cc $(SUBDIRS)
  40. $(OBJ)/%.o: %.cc
  41. echo Compiling $< to $@
  42. $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXSTD) $(CXXFLAGS) -o $@ '$(abspath $<)'
  43. $(DoDep)
  44. # Include the dependencies that are available
  45. The_DFiles = $(wildcard $($(LOCAL)-DEP))
  46. ifneq ($(words $(The_DFiles)),0)
  47. include $(The_DFiles)
  48. endif