]> git.decadent.org.uk Git - dak.git/blob - tools/dsync-0.0/buildlib/library.mak
Keep track of when a package was last added to a suite
[dak.git] / tools / dsync-0.0 / 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 .opic.d,$(notdir $(basename $(SOURCE)))))
21 $(LOCAL)-HEADERS := $(addprefix $(INCLUDE)/,$(HEADERS))
22 $(LOCAL)-SONAME := lib$(LIBRARY).so.$(MAJOR)
23 $(LOCAL)-SLIBS := $(SLIBS)
24 $(LOCAL)-LIBRARY := $(LIBRARY)
25
26 # Install the command hooks
27 headers: $($(LOCAL)-HEADERS)
28 library: $(LIB)/lib$(LIBRARY).so $(LIB)/lib$(LIBRARY).so.$(MAJOR) $(LIB)/lib$(LIBRARY).a
29 clean: clean/$(LOCAL)
30 veryclean: veryclean/$(LOCAL)
31
32 # The clean rules
33 .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
34 clean/$(LOCAL):
35         -rm -f $($(@F)-OBJS) $($(@F)-DEP)
36 veryclean/$(LOCAL): clean/$(LOCAL)
37         -rm -f $($(@F)-HEADERS) $(LIB)/lib$($(@F)-LIBRARY).so*
38
39 # Build rules for the two symlinks
40 .PHONY: $(LIB)/lib$(LIBRARY).so.$(MAJOR) $(LIB)/lib$(LIBRARY).so
41 $(LIB)/lib$(LIBRARY).so.$(MAJOR): $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR)
42         ln -sf $(<F) $@
43 $(LIB)/lib$(LIBRARY).so: $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR)
44         ln -sf $(<F) $@
45         
46 # The binary build rule
47 $(LIB)/lib$(LIBRARY).so.$(MAJOR).$(MINOR): $($(LOCAL)-HEADERS) $($(LOCAL)-OBJS)
48         -rm -f $(LIB)/lib$($(@F)-LIBRARY).so* 2> /dev/null
49         echo Building shared library $@
50         $(CXX) $(CXXFLAGS) $(LDFLAGS) $(PICFLAGS) $(LFLAGS) -o $@ \
51            $(LFLAGS_SO) $(SONAME_MAGIC)$($(@F)-SONAME) -shared \
52            $(filter %.opic,$^) $($(@F)-SLIBS)
53
54 $(LIB)/lib$(LIBRARY).a: $($(LOCAL)-HEADERS) $($(LOCAL)-OBJS)
55         -rm -f $(LIB)/lib$($(@F)-LIBRARY).a 2> /dev/null
56         echo Building static library $@
57         $(AR) rc $@ $(filter %.opic,$^)
58         ranlib $@
59
60 # Compilation rules
61 vpath %.cc $(SUBDIRS)
62 $(OBJ)/%.opic: %.cc
63         echo Compiling $< to $@
64         $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXFLAGS) $(PICFLAGS) -o $@ $<
65         $(DoDep)
66
67 # Include the dependencies that are available
68 The_DFiles = $(wildcard $($(LOCAL)-DEP))
69 ifneq ($(words $(The_DFiles)),0)
70 include $(The_DFiles)
71 endif