library.mak 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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)$(LIBEXT).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)$(LIBEXT).so.$(MAJOR)
  19. $(LOCAL)-SLIBS := $(SLIBS)
  20. $(LOCAL)-LIBRARY := $(LIBRARY)
  21. TYPE = src
  22. include $(PODOMAIN_H)
  23. # Install the command hooks
  24. headers: $($(LOCAL)-HEADERS)
  25. library: $(LIB)/lib$(LIBRARY).so $(LIB)/lib$(LIBRARY)$(LIBEXT).so.$(MAJOR)
  26. clean: clean/$(LOCAL)
  27. veryclean: veryclean/$(LOCAL)
  28. # Make Directories
  29. MKDIRS += $(OBJ) $(DEP) $(LIB) $(dir $($(LOCAL)-HEADERS))
  30. # The clean rules
  31. .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
  32. clean/$(LOCAL):
  33. -rm -f $($(@F)-OBJS) $($(@F)-DEP)
  34. veryclean/$(LOCAL): clean/$(LOCAL)
  35. -rm -f $($(@F)-HEADERS) $(LIB)/lib$($(@F)-LIBRARY)*.so*
  36. # Build rules for the two symlinks
  37. .PHONY: $(LIB)/lib$(LIBRARY)$(LIBEXT).so.$(MAJOR) $(LIB)/lib$(LIBRARY).so
  38. $(LIB)/lib$(LIBRARY)$(LIBEXT).so.$(MAJOR): $(LIB)/lib$(LIBRARY)$(LIBEXT).so.$(MAJOR).$(MINOR)
  39. ln -sf $(<F) $@
  40. $(LIB)/lib$(LIBRARY).so: $(LIB)/lib$(LIBRARY)$(LIBEXT).so.$(MAJOR).$(MINOR)
  41. ln -sf $(<F) $@
  42. # The binary build rule
  43. $(LIB)/lib$(LIBRARY)$(LIBEXT).so.$(MAJOR).$(MINOR): $($(LOCAL)-HEADERS) $($(LOCAL)-OBJS)
  44. -rm -f $(LIB)/lib$($(@F)-LIBRARY)*.so* 2> /dev/null
  45. echo Building shared library $@
  46. $(CXX) $(CXXFLAGS) $(LDFLAGS) $(PICFLAGS) $(LFLAGS) $(LFLAGS_SO)\
  47. -o $@ $(SONAME_MAGIC)$($(@F)-SONAME) -shared \
  48. $(filter %.opic,$^) \
  49. $($(@F)-SLIBS)
  50. # Compilation rules
  51. vpath %.cc $(SUBDIRS)
  52. $(OBJ)/%.opic: %.cc
  53. echo Compiling $< to $@
  54. $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXFLAGS) $(PICFLAGS) -o $@ $<
  55. $(DoDep)
  56. # Include the dependencies that are available
  57. The_DFiles = $(wildcard $($(LOCAL)-DEP))
  58. ifneq ($(words $(The_DFiles)),0)
  59. include $(The_DFiles)
  60. endif