3 # This creates a shared library.
6 # $(SOURCE) - The source code to use
7 # $(HEADERS) - Exported header files and private header files
8 # $(LIBRARY) - The name of the library without lib or .so
9 # $(MAJOR) - The major version number of this library
10 # $(MINOR) - The minor version number of this library
11 # $(APT_DOMAIN) - The text domain for this library
13 # All output is writtin to .opic files in the build directory to
14 # signify the PIC output.
16 # See defaults.mak for information about LOCAL
18 # Some local definitions
19 LOCAL := lib$(LIBRARY).so.$(MAJOR).$(MINOR)
20 $(LOCAL)-OBJS := $(addprefix $(OBJ)/,$(addsuffix .opic,$(notdir $(basename $(SOURCE)))))
21 $(LOCAL)-DEP := $(addprefix $(DEP)/,$(addsuffix .opic.d,$(notdir $(basename $(SOURCE)))))
22 $(LOCAL)-HEADERS := $(addprefix $(INCLUDE)/,$(HEADERS))
23 $(LOCAL)-SONAME := lib$(LIBRARY).so.$(MAJOR)
24 $(LOCAL)-VERSIONSCRIPT := $(LIB)/lib$(LIBRARY)-$(MAJOR)-$(MINOR).symver
25 $(LOCAL)-SLIBS := $(SLIBS)
26 $(LOCAL)-LIBRARY := $(LIBRARY)
31 # Install the command hooks
32 headers: $($(LOCAL)-HEADERS)
33 library: $(LIB)/lib$(LIBRARY).so $(LIB)/lib$(LIBRARY).so.$(MAJOR)
35 veryclean: veryclean/$(LOCAL)
38 MKDIRS += $(OBJ) $(DEP) $(LIB) $(dir $($(LOCAL)-HEADERS))
41 .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
43 -rm -f $($(@F)-OBJS) $($(@F)-DEP) $($(@F)-VERSIONSCRIPT)
44 veryclean/$(LOCAL): clean/$(LOCAL)
45 -rm -f $($(@F)-HEADERS) $(LIB)/lib$($(@F)-LIBRARY)*.so*
47 # Build rules for the two symlinks
48 .PHONY: $(LIB)/lib$(LIBRARY).so.$(MAJOR) $(LIB)/lib$(LIBRARY).so
49 $(LIB)/lib$(LIBRARY).so.$(MAJOR): $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR)
51 $(LIB)/lib$(LIBRARY).so: $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR)
54 $($(LOCAL)-VERSIONSCRIPT):
55 echo '$(shell echo '$(LIBRARY)' | tr -d '-' | tr 'a-z' 'A-Z')_$(MAJOR) { global: *; };' > $@
57 # The binary build rule
58 $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR): $($(LOCAL)-HEADERS) $($(LOCAL)-OBJS) $(LIBRARYDEPENDS) $($(LOCAL)-VERSIONSCRIPT)
59 -rm -f $(LIB)/lib$($(@F)-LIBRARY)*.so* 2> /dev/null
60 echo Building shared library $@
61 $(CXX) $(CXXFLAGS) $(LDFLAGS) -Wl,--version-script=$($(@F)-VERSIONSCRIPT) $(PICFLAGS) $(LFLAGS) $(LFLAGS_SO)\
62 -o $@ $(SONAME_MAGIC)$($(@F)-SONAME) -shared \
68 $(OBJ)/%.opic: %.cc $(LIBRARYDEPENDS)
69 echo Compiling $< to $@
70 $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXFLAGS) $(PICFLAGS) -o $@ $(abspath $<)
73 # Include the dependencies that are available
74 The_DFiles = $(wildcard $($(LOCAL)-DEP))
75 ifneq ($(words $(The_DFiles)),0)