library.mak 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- make -*-
  2. # This creates a shared 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. # $(MAJOR) - The major version number of this library
  8. # $(MINOR) - The minor version number of this library
  9. # All output is writtin to .opic files in the build directory to
  10. # signify the PIC output.
  11. # See defaults.mak for information about LOCAL
  12. # Some local definitions
  13. LOCAL := lib$(LIBRARY).so.$(MAJOR).$(MINOR)
  14. $(LOCAL)-OBJS := $(addprefix $(OBJ)/,$(addsuffix .opic,$(notdir $(basename $(SOURCE)))))
  15. $(LOCAL)-DEP := $(addprefix $(DEP)/,$(addsuffix .d,$(notdir $(basename $(SOURCE)))))
  16. $(LOCAL)-HEADERS := $(addprefix $(INCLUDE)/,$(HEADERS))
  17. $(LOCAL)-SONAME := lib$(LIBRARY).so.$(MAJOR)
  18. $(LOCAL)-SLIBS := $(SLIBS)
  19. # Install the command hooks
  20. headers: $($(LOCAL)-HEADERS)
  21. library: $(LIB)/lib$(LIBRARY).so $(LIB)/lib$(LIBRARY).so.$(MAJOR)
  22. clean: clean/$(LOCAL)
  23. veryclean: veryclean/$(LOCAL)
  24. # The clean rules
  25. .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
  26. clean/$(LOCAL):
  27. -rm -f $($(@F)-OBJS) $($(@F)-DEP)
  28. veryclean/$(LOCAL): clean/$(LOCAL)
  29. -rm -f $($(@F)-HEADERS) $(LIB)/lib$(LIBRARY).so*
  30. # Build rules for the two symlinks
  31. .PHONY: $(LIB)/lib$(LIBRARY).so.$(MAJOR) $(LIB)/lib$(LIBRARY).so
  32. $(LIB)/lib$(LIBRARY).so.$(MAJOR): $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR)
  33. ln -sf $(<F) $@
  34. $(LIB)/lib$(LIBRARY).so: $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR)
  35. ln -sf $(<F) $@
  36. # The binary build rule
  37. $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR): $($(LOCAL)-HEADERS) $($(LOCAL)-OBJS)
  38. echo Building shared library $@
  39. $(CXX) $(CXXFLAGS) $(LDFLAGS) $(PICFLAGS) $(LFLAGS) -o $@ \
  40. -Wl,-soname -Wl,$($(@F)-SONAME) -shared $(filter %.opic,$^) \
  41. $($(@F)-SLIBS)
  42. # Compilation rules
  43. vpath %.cc $(SUBDIRS)
  44. $(OBJ)/%.opic: %.cc
  45. echo Compiling $< to $@
  46. $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXFLAGS) $(PICFLAGS) -o $@ $<
  47. $(DoDep)
  48. # Include the dependencies that are available
  49. The_DFiles = $(wildcard $($(LOCAL)-DEP))
  50. ifneq ($(words $(The_DFiles)),0)
  51. include $(The_DFiles)
  52. endif