library.mak 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. # $(APT_DOMAIN) - The text domain for this library
  10. # All output is writtin to .opic files in the build directory to
  11. # signify the PIC output.
  12. # See defaults.mak for information about LOCAL
  13. # Some local definitions
  14. LOCAL := lib$(LIBRARY).so.$(MAJOR).$(MINOR)
  15. $(LOCAL)-OBJS := $(addprefix $(OBJ)/,$(addsuffix .opic,$(notdir $(basename $(SOURCE)))))
  16. $(LOCAL)-DEP := $(addprefix $(DEP)/,$(addsuffix .opic.d,$(notdir $(basename $(SOURCE)))))
  17. $(LOCAL)-HEADERS := $(addprefix $(INCLUDE)/,$(HEADERS))
  18. $(LOCAL)-SONAME := lib$(LIBRARY).so.$(MAJOR)
  19. $(LOCAL)-VERSIONSCRIPT := $(LIB)/lib$(LIBRARY)-$(MAJOR)-$(MINOR).symver
  20. $(LOCAL)-SLIBS := $(SLIBS)
  21. $(LOCAL)-LIBRARY := $(LIBRARY)
  22. TYPE = src
  23. include $(PODOMAIN_H)
  24. # Install the command hooks
  25. headers: $($(LOCAL)-HEADERS)
  26. library: $(LIB)/lib$(LIBRARY).so $(LIB)/lib$(LIBRARY).so.$(MAJOR)
  27. clean: clean/$(LOCAL)
  28. veryclean: veryclean/$(LOCAL)
  29. # Make Directories
  30. MKDIRS += $(OBJ) $(DEP) $(LIB) $(dir $($(LOCAL)-HEADERS))
  31. # The clean rules
  32. .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
  33. clean/$(LOCAL):
  34. -rm -f $($(@F)-OBJS) $($(@F)-DEP) $($(@F)-VERSIONSCRIPT)
  35. veryclean/$(LOCAL): clean/$(LOCAL)
  36. -rm -f $($(@F)-HEADERS) $(LIB)/lib$($(@F)-LIBRARY)*.so*
  37. # Build rules for the two symlinks
  38. .PHONY: $(LIB)/lib$(LIBRARY).so.$(MAJOR) $(LIB)/lib$(LIBRARY).so
  39. $(LIB)/lib$(LIBRARY).so.$(MAJOR): $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR)
  40. ln -sf $(<F) $@
  41. $(LIB)/lib$(LIBRARY).so: $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR)
  42. ln -sf $(<F) $@
  43. $($(LOCAL)-VERSIONSCRIPT):
  44. echo '$(shell echo '$(LIBRARY)' | tr -d '-' | tr 'a-z' 'A-Z')_$(MAJOR) { global: *; };' > $@
  45. # The binary build rule
  46. $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR): $($(LOCAL)-HEADERS) $($(LOCAL)-OBJS) $(LIBRARYDEPENDS) $($(LOCAL)-VERSIONSCRIPT)
  47. -rm -f $(LIB)/lib$($(@F)-LIBRARY)*.so* 2> /dev/null
  48. echo Building shared library $@
  49. $(CXX) $(CXXSTD) $(CXXFLAGS) $(LDFLAGS) -Wl,--version-script=$($(@F)-VERSIONSCRIPT) $(PICFLAGS) $(LFLAGS) $(LFLAGS_SO)\
  50. -o $@ $(SONAME_MAGIC)$($(@F)-SONAME) -shared \
  51. $(filter %.opic,$^) \
  52. $($(@F)-SLIBS)
  53. # Compilation rules
  54. vpath %.cc $(SUBDIRS)
  55. $(OBJ)/%.opic: %.cc $(LIBRARYDEPENDS)
  56. echo Compiling $< to $@
  57. $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXSTD) $(CXXFLAGS) $(PICFLAGS) -o $@ '$(abspath $<)'
  58. $(DoDep)
  59. # Include the dependencies that are available
  60. The_DFiles = $(wildcard $($(LOCAL)-DEP))
  61. ifneq ($(words $(The_DFiles)),0)
  62. include $(The_DFiles)
  63. endif