]> mj.ucw.cz Git - libucw.git/blob - build/Makebottom
1a37a35b71903bcd5aa47e4e364ba0cb8376315c
[libucw.git] / build / Makebottom
1 # Bottom part of Makefile for the UCW Libraries
2 # (c) 1997--2007 Martin Mares <mj@ucw.cz>
3
4 # The run tree
5
6 runtree: run/.tree-stamp $(addsuffix /.dir-stamp,$(addprefix $(o)/,$(DIRS)))
7
8 run/.tree-stamp: $(o)/config.mk
9         $(M)Creating runtree
10         $(Q)mkdir -p run $(addprefix run/, cf $(EXTRA_RUNDIRS) $(INSTALL_RUNDIRS))
11         $(Q)touch run/.tree-stamp
12
13 # Miscellaneous targets
14
15 programs: $(PROGS)
16 datafiles: $(DATAFILES)
17 tests: $(TESTS)
18 configs: $(addprefix run/cf/,$(CONFIGS))
19
20 tags:
21         etags `find . -name "*.[ch]"`
22
23 # Black magic with dependencies. It would be more correct to make "depend.new"
24 # a prerequisite for "depend", but "depend.new" often has the same timestamp
25 # as "depend" which would confuse make a lot and either force remaking anyway
26 # or (as in current versions of GNU make) erroneously skipping the remaking.
27
28 -include $(o)/depend
29
30 $(o)/depend: force
31         $(Q)if [ -s $(o)/depend.new ] ; then $(s)/build/mergedeps $(o)/depend $(o)/depend.new ; >$(o)/depend.new ; fi
32
33 force:
34
35 # Rules for directories
36
37 %.dir-stamp:
38         $(Q)mkdir -p $(@D) && touch $@
39
40 # Rules for configuration files
41
42 run/cf/%: $(s)/cf/% $(o)/config.mk $(s)/build/genconf
43         $(M)CF $<
44         $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
45
46 $(o)/%.cf: $(s)/%.cf $(o)/config.mk $(s)/build/genconf
47         $(M)CF $<
48         $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
49         $(Q)cp $@ run/cf/$(basename $(@F))
50
51 # Rules for libraries
52
53 %.a:
54         $(M)AR $@
55         $(Q)rm -f $@
56         $(Q)ar rcs $@ $^
57 ifdef CONFIG_INSTALL_API
58         $(Q)$(call symlink,$@,run/lib)
59 endif
60
61 %.so:
62         $(M)LD $@
63         $(Q)$(CC) $(LSHARED) $(LDFLAGS) -o $@ $^
64         $(Q)$(call symlink,$@,run/lib)
65
66 $(o)/%.pc: $(s)/%.pc $(o)/%.$(LS)
67         $(M)PC $<
68         $(Q)DEPS="$(shell $(s)/build/lib-deps $^)" LIBDIR=$(@D) $(s)/build/genconf $< $@ $(o)/config.mk
69         $(Q)mkdir -p $(o)/pkgconfig
70         $(Q)$(call symlink,$@,$(o)/pkgconfig)
71
72 # Rules for public API
73
74 ifdef CONFIG_INSTALL_API
75
76 API_ROOT:=$(shell pwd)/run
77 INSTALL_RUNDIRS+=include lib/pkgconfig
78 api: $(API_INCLUDES) $(addprefix run/lib/pkgconfig/,$(addsuffix .pc,$(API_LIBS)))
79
80 $(o)/%/.include-stamp:
81         $(Q)$(s)/build/install-includes $(<D) run/include/$(IDST) $(?F)
82         $(Q)touch $@
83
84 run/lib/pkgconfig/%.pc:         # RHS supplied in the sub-makefile
85         $(M)PC-API $@
86         $(Q)sed <$< >$@ "s@^libdir=.*@libdir=$(API_ROOT)/lib@;s@^incdir=.*@incdir=$(API_ROOT)/include@"
87
88 else
89 api:
90 endif
91
92 # Rules for compiling C
93
94 $(o)/%.o: $(s)/%.c $(o)/autoconf.h
95         $(M)CC $<
96         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
97
98 $(o)/%.o: %.c $(o)/autoconf.h
99         $(M)CC $<
100         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
101
102 %.o: %.c $(o)/autoconf.h
103         $(M)CC $<
104         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
105
106 $(o)/%.oo: $(s)/%.c $(o)/autoconf.h
107         $(M)CC-SO $<
108         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
109
110 $(o)/%.oo: %.c $(o)/autoconf.h
111         $(M)CC-SO $<
112         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
113
114 %.oo: %.c $(o)/autoconf.h
115         $(M)CC-SO $<
116         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
117
118 $(o)/%-tt.o: $(s)/%.c $(o)/autoconf.h
119         $(M)CC-TEST $<
120         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -DTEST -c -o $@ $<
121
122 # Rules for testing
123
124 $(o)/%-t: $(o)/%-tt.o $(TESTING_DEPS)
125         $(M)LD-TEST $@
126         $(Q)$(CC) $(LDFLAGS) -o $@ $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" $(s)/build/lib-flags $^) $(LIBS)
127
128 $(o)/%.test: $(s)/%.t $(s)/build/tester
129         $(M)TEST $@
130         $(Q)$(s)/build/tester --rundir=run $(TESTERFLAGS) $< && touch $@
131
132 # Rules for binaries
133
134 BINDIR=bin
135
136 $(o)/%: $(o)/%.o
137         $(M)LD $@
138         $(Q)$(CC) $(LDFLAGS) -o $@ $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" $(s)/build/lib-flags $^) $(LIBS)
139         $(Q)$(call symlink,$@,run/$(BINDIR))
140
141 $(o)/%: $(s)/%.sh $(o)/config.mk $(s)/build/genconf
142         $(M)PP $<
143         $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
144         $(Q)chmod +x $@
145         $(Q)$(call symlink,$@,run/$(BINDIR))
146
147 $(o)/%: %.sh $(o)/config.mk $(s)/build/genconf
148         $(M)PP $<
149         $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
150         $(Q)chmod +x $@
151         $(Q)$(call symlink,$@,run/$(BINDIR))
152
153 $(o)/%: $(s)/%.pl $(o)/config.mk $(s)/build/genconf
154         $(M)PP $<
155         $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
156         $(Q)chmod +x $@
157         $(Q)$(call symlink,$@,run/$(BINDIR))
158
159 $(o)/%: %.pl $(o)/config.mk $(s)/build/genconf
160         $(M)PP $<
161         $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
162         $(Q)chmod +x $@
163         $(Q)$(call symlink,$@,run/$(BINDIR))
164
165 PERL_MODULE_DIR=UCW
166
167 $(o)/%.pm: $(s)/%.pm
168         $(M)"PM $< -> run/lib/perl5/$(PERL_MODULE_DIR)/$(@F)"
169         $(Q)cp $^ $@
170         $(Q)$(call symlink,$@,run/lib/perl5/$(PERL_MODULE_DIR))
171
172 $(o)/%.pm: %.pm
173         $(M)"PM $< -> run/lib/perl/$(PERL_MODULE_DIR)/$(@F)"
174         $(Q)cp $^ $@
175         $(Q)$(call symlink,$@,run/lib/perl5/$(PERL_MODULE_DIR))
176
177 # Rules for data files
178
179 DATADIR=lib
180
181 $(DATAFILES): $(o)/%: $(s)/%
182         $(M)DATA $<
183         $(Q)cp $^ $@
184         $(Q)$(call symlink,$@,run/$(DATADIR))
185
186 # Default installation target
187
188 default-install:
189         SH_EXTRA_RUNDIRS="$(sort $(EXTRA_RUNDIRS))" SH_INSTALL_RUNDIRS="$(sort $(INSTALL_RUNDIRS))" SH_CONFIGS="$(sort $(CONFIGS))" SH_AUTO_CONFIRM="$(CONFIRM)" $(s)/build/installer $(INSTALL_DIR)
190
191 # Don't delete intermediate targets. There shouldn't be any, but due to bugs
192 # in GNU Make rules with targets in not-yet-existing directories are ignored
193 # when searching for implicit rules and thence targets considered intermediate.
194 .SECONDARY:
195
196 .PHONY: all clean distclean runtree programs api datafiles force tags configs dust install default-install