First draft of make system and name change to apt-pkg
[ntk/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
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
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$(LIBRARY).so*
36
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
44 # The binary build rule
45 $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR): $($(LOCAL)-HEADERS) $($(LOCAL)-OBJS)
46 echo Building shared library $@
47 $(CXX) $(CXXFLAGS) $(LDFLAGS) $(PICFLAGS) $(LFLAGS) -o $@ \
48 -Wl,-soname -Wl,$($(@F)-SONAME) -shared $(filter %.opic,$^)
49
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
57 # Include the dependencies that are available
58 The_DFiles = $(wildcard $($(LOCAL)-DEP))
59 ifneq ($(words $(The_DFiles)),0)
60 include $(The_DFiles)
61 endif