]> git.saurik.com Git - apt.git/blob - buildlib/library.mak
Bugs
[apt.git] / buildlib / library.mak
1 # -*- make -*-
2
3 # This creates a shared library.
4
5 # Input
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
12 # All output is writtin to .opic files in the build directory to
13 # signify the PIC output.
14
15 # See defaults.mak for information about LOCAL
16
17 # Some local definitions
18 LOCAL := lib$(LIBRARY).so.$(MAJOR).$(MINOR)
19 $(LOCAL)-OBJS := $(addprefix $(OBJ)/,$(addsuffix .opic,$(notdir $(basename $(SOURCE)))))
20 $(LOCAL)-DEP := $(addprefix $(DEP)/,$(addsuffix .d,$(notdir $(basename $(SOURCE)))))
21 $(LOCAL)-HEADERS := $(addprefix $(INCLUDE)/,$(HEADERS))
22 $(LOCAL)-SONAME := lib$(LIBRARY).so.$(MAJOR)
23 $(LOCAL)-SLIBS := $(SLIBS)
24
25 # Install the command hooks
26 headers: $($(LOCAL)-HEADERS)
27 library: $(LIB)/lib$(LIBRARY).so $(LIB)/lib$(LIBRARY).so.$(MAJOR)
28 clean: clean/$(LOCAL)
29 veryclean: veryclean/$(LOCAL)
30
31 # The clean rules
32 .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
33 clean/$(LOCAL):
34 -rm -f $($(@F)-OBJS) $($(@F)-DEP)
35 veryclean/$(LOCAL): clean/$(LOCAL)
36 -rm -f $($(@F)-HEADERS) $(LIB)/lib$(LIBRARY).so*
37
38 # Build rules for the two symlinks
39 .PHONY: $(LIB)/lib$(LIBRARY).so.$(MAJOR) $(LIB)/lib$(LIBRARY).so
40 $(LIB)/lib$(LIBRARY).so.$(MAJOR): $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR)
41 ln -sf $(<F) $@
42 $(LIB)/lib$(LIBRARY).so: $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR)
43 ln -sf $(<F) $@
44
45 # The binary build rule
46 $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR): $($(LOCAL)-HEADERS) $($(LOCAL)-OBJS)
47 echo Building shared library $@
48 $(CXX) $(CXXFLAGS) $(LDFLAGS) $(PICFLAGS) $(LFLAGS) -o $@ \
49 -Wl,-soname -Wl,$($(@F)-SONAME) -shared $(filter %.opic,$^) \
50 $($(@F)-SLIBS)
51
52 # Compilation rules
53 vpath %.cc $(SUBDIRS)
54 $(OBJ)/%.opic: %.cc
55 echo Compiling $< to $@
56 $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXFLAGS) $(PICFLAGS) -o $@ $<
57 $(DoDep)
58
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