library.mak 2.3 KB

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