staticlibrary.mak 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # -*- make -*-
  2. # This creates a static library.
  3. # Input
  4. # $(SOURCE) - The source code to use
  5. # $(HEADERS) - Exported header files and private header files
  6. # $(LIBRARY) - The name of the library without lib or .so
  7. # All output is writtin to .o files in the build directory
  8. # See defaults.mak for information about LOCAL
  9. # Some local definitions
  10. LOCAL := lib$(LIBRARY).a
  11. $(LOCAL)-OBJS := $(addprefix $(OBJ)/,$(addsuffix .o,$(notdir $(basename $(SOURCE)))))
  12. $(LOCAL)-DEP := $(addprefix $(DEP)/,$(addsuffix .o.d,$(notdir $(basename $(SOURCE)))))
  13. $(LOCAL)-HEADERS := $(addprefix $(INCLUDE)/,$(HEADERS))
  14. $(LOCAL)-LIB := $(LIB)/lib$(LIBRARY).a
  15. # Install the command hooks
  16. headers: $($(LOCAL)-HEADERS)
  17. library: $($(LOCAL)-LIB)
  18. clean: clean/$(LOCAL)
  19. veryclean: veryclean/$(LOCAL)
  20. # Make Directories
  21. MKDIRS += $(OBJ) $(DEP) $(LIB) $(dir $($(LOCAL)-HEADERS))
  22. # The clean rules
  23. .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
  24. clean/$(LOCAL):
  25. -rm -f $($(@F)-OBJS) $($(@F)-DEP)
  26. veryclean/$(LOCAL): clean/$(LOCAL)
  27. -rm -f $($(@F)-HEADERS) $($(@F)-LIB)
  28. # Build rules for the two symlinks
  29. .PHONY: $($(LOCAL)-LIB)
  30. # The binary build rule
  31. $($(LOCAL)-LIB): $($(LOCAL)-HEADERS) $($(LOCAL)-OBJS)
  32. echo Building library $@
  33. -rm $@ > /dev/null 2>&1
  34. $(AR) cq $@ $(filter %.o,$^)
  35. ifneq ($(words $(RANLIB)),0)
  36. $(RANLIB) $@
  37. endif
  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