staticlibrary.mak 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. # The clean rules
  21. .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
  22. clean/$(LOCAL):
  23. -rm -f $($(@F)-OBJS) $($(@F)-DEP)
  24. veryclean/$(LOCAL): clean/$(LOCAL)
  25. -rm -f $($(@F)-HEADERS) $($(@F)-LIB)
  26. # Build rules for the two symlinks
  27. .PHONY: $($(LOCAL)-LIB)
  28. # The binary build rule
  29. $($(LOCAL)-LIB): $($(LOCAL)-HEADERS) $($(LOCAL)-OBJS)
  30. echo Building library $@
  31. -rm $@ > /dev/null 2>&1
  32. $(AR) cq $@ $(filter %.o,$^)
  33. # Compilation rules
  34. vpath %.cc $(SUBDIRS)
  35. $(OBJ)/%.o: %.cc
  36. echo Compiling $< to $@
  37. $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
  38. $(DoDep)
  39. # Include the dependencies that are available
  40. The_DFiles = $(wildcard $($(LOCAL)-DEP))
  41. ifneq ($(words $(The_DFiles)),0)
  42. include $(The_DFiles)
  43. endif