]> mj.ucw.cz Git - libucw.git/blob - build/Makebottom
Packages: Fixed static linking.
[libucw.git] / build / Makebottom
1 # Bottom part of Makefile for the UCW Libraries
2 # (c) 1997--2008 Martin Mares <mj@ucw.cz>
3
4 # The run tree
5
6 DOCDIR=doc
7
8 runtree: run/.tree-stamp $(addsuffix /.dir-stamp,$(addprefix $(o)/,$(DIRS)) $(addprefix run/$(DOCDIR)/,$(DOC_MODULES)))
9
10 run/.tree-stamp: $(o)/config.mk
11         $(M)Creating runtree
12         $(Q)mkdir -p run $(addprefix run/, $(CONFIG_DIR) $(EXTRA_RUNDIRS) $(INSTALL_RUNDIRS))
13         $(Q)touch run/.tree-stamp
14
15 # Miscellaneous targets
16
17 programs: $(PROGS)
18 datafiles: $(DATAFILES)
19 tests: $(TESTS)
20 configs: $(addprefix run/$(CONFIG_DIR)/,$(CONFIGS))
21 docs: runtree $(DOCS) $(DOC_INDICES)
22
23 tags:
24         etags `find . -name "*.[ch]"`
25
26 # Black magic with dependencies. It would be more correct to make "depend.new"
27 # a prerequisite for "depend", but "depend.new" often has the same timestamp
28 # as "depend" which would confuse make a lot and either force remaking anyway
29 # or (as in current versions of GNU make) erroneously skipping the remaking.
30
31 -include $(o)/depend
32
33 $(o)/depend: force
34         $(Q)if [ -s $(o)/depend.new ] ; then $(BUILDSYS)/mergedeps $(o)/depend $(o)/depend.new ; >$(o)/depend.new ; fi
35
36 force:
37
38 # Rules for directories
39
40 %.dir-stamp:
41         $(Q)mkdir -p $(@D) && touch $@
42
43 # Rules for configuration files
44
45 run/$(CONFIG_DIR)/%: $(s)/$(CONFIG_SRC_DIR)/% $(o)/config.mk $(BUILDSYS)/genconf
46         $(M)CF $<
47         $(Q)$(BUILDSYS)/genconf $< $@ $(o)/config.mk
48
49 $(o)/%.cf: $(s)/%.cf $(o)/config.mk $(BUILDSYS)/genconf
50         $(M)CF $<
51         $(Q)$(BUILDSYS)/genconf $< $@ $(o)/config.mk
52         $(Q)cp $@ run/$(CONFIG_DIR)/$(basename $(@F))
53
54 # Rules for libraries
55
56 %.a:
57         $(M)AR $@
58         $(Q)rm -f $@
59         $(Q)ar rcs $@ $^
60 ifdef CONFIG_INSTALL_API
61         $(Q)$(call symlink-alias,$@,run/lib,$(*F)$(LIBNAME_INFIX).a)
62 endif
63
64 %.so:
65         $(M)LD $@
66         $(Q)$(CC) $(LSHARED) $(LDFLAGS) -o $@ $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" PKG_CONFIG_OPTS="$(PKG_CONFIG_OPTS)" $(BUILDSYS)/lib-flags $^) $(LIBS)
67         $(Q)$(call symlink-alias,$@,run/$(SO_RUNDIR),$(*F)$(SONAME_INFIX).so$(SONAME_SUFFIX))
68
69 # On Darwin, gcc expects shared libraries in *.dylib instead of *.so.
70 # Surprisingly, when a program is run, it suffices to have *.so files.
71 # We don't want to mess up the whole build system with configurable
72 # suffices and we also don't want to incur an overhead on Linux, so we
73 # just create symbolic links on Darwin, if requested.
74 %.dylib: %.so
75         cd $(dir $<) && ln -fs $(notdir $<) $(notdir $@)
76
77 $(o)/%.pc: $(s)/%.pc $(o)/%$(LV).$(LS)
78         $(M)PC $<
79         $(Q)DEPS="$(shell $(BUILDSYS)/lib-deps $^)" LIBDIR=$(@D) $(BUILDSYS)/genconf $< $@ $(o)/config.mk
80         $(Q)mkdir -p $(o)/pkgconfig
81         $(Q)$(call symlink,$@,$(o)/pkgconfig)
82
83 # Rules for public API
84
85 ifdef CONFIG_INSTALL_API
86
87 ifdef CONFIG_LOCAL
88 # Need an absolute path
89 API_ROOT:=$(shell pwd)/run
90 API_LIBDIR=$(API_ROOT)/lib
91 API_INCDIR=$(API_ROOT)/include
92 else
93 API_LIBDIR=$(INSTALL_LIB_DIR)
94 API_INCDIR=$(INSTALL_INCLUDE_DIR)
95 endif
96 INSTALL_RUNDIRS+=include lib/pkgconfig
97 api: $(API_INCLUDES) $(addprefix run/lib/pkgconfig/,$(addsuffix .pc,$(API_LIBS)))
98
99 $(o)/%/.include-stamp:
100         $(Q)$(BUILDSYS)/install-includes $(<D) run/include/$(IDST) $(?F)
101         $(Q)touch $@
102
103 run/lib/pkgconfig/%.pc:         # RHS supplied in the sub-makefile
104         $(M)PC-API $@
105         $(Q)sed <$< >$@ "s@^libdir=.*@libdir=$(API_LIBDIR)@;s@^incdir=.*@incdir=$(API_INCDIR)@"
106
107 else
108 api:
109 endif
110
111 # Rules for compiling C
112
113 $(o)/%.o: $(s)/%.c $(o)/autoconf.h
114         $(M)CC $<
115         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
116
117 $(o)/%.o: %.c $(o)/autoconf.h
118         $(M)CC $<
119         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
120
121 %.o: %.c $(o)/autoconf.h
122         $(M)CC $<
123         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
124
125 $(o)/%.oo: $(s)/%.c $(o)/autoconf.h
126         $(M)CC-SO $<
127         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
128
129 $(o)/%.oo: %.c $(o)/autoconf.h
130         $(M)CC-SO $<
131         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
132
133 %.oo: %.c $(o)/autoconf.h
134         $(M)CC-SO $<
135         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
136
137 $(o)/%-tt.o: $(s)/%.c $(o)/autoconf.h
138         $(M)CC-TEST $<
139         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -DTEST -c -o $@ $<
140
141 # Rules for testing
142
143 $(o)/%-t: $(o)/%-tt.o $(TESTING_DEPS)
144         $(M)LD-TEST $@
145         $(Q)$(CC) $(LDFLAGS) -o $@ $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" PKG_CONFIG_OPTS="$(PKG_CONFIG_OPTS)" $(BUILDSYS)/lib-flags $^) $(LIBS)
146
147 $(o)/%.test: $(s)/%.t $(BUILDSYS)/tester
148         $(M)TEST $@
149         $(Q)$(BUILDSYS)/tester --rundir=run $(TESTERFLAGS) $< && touch $@
150
151 # Rules for binaries
152
153 BINDIR=bin
154
155 $(o)/%: $(o)/%.o
156         $(M)LD $@
157         $(Q)$(CC) $(LDFLAGS) -o $@ $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" PKG_CONFIG_OPTS="$(PKG_CONFIG_OPTS)" $(BUILDSYS)/lib-flags $^) $(LIBS)
158         $(Q)$(call symlink,$@,run/$(BINDIR))
159
160 $(o)/%: $(s)/%.sh $(o)/config.mk $(BUILDSYS)/genconf
161         $(M)PP $<
162         $(Q)$(BUILDSYS)/genconf $< $@ $(o)/config.mk
163         $(Q)chmod +x $@
164         $(Q)$(call symlink,$@,run/$(BINDIR))
165
166 $(o)/%: %.sh $(o)/config.mk $(BUILDSYS)/genconf
167         $(M)PP $<
168         $(Q)$(BUILDSYS)/genconf $< $@ $(o)/config.mk
169         $(Q)chmod +x $@
170         $(Q)$(call symlink,$@,run/$(BINDIR))
171
172 $(o)/%: $(s)/%.pl $(o)/config.mk $(BUILDSYS)/genconf
173         $(M)PP $<
174         $(Q)$(BUILDSYS)/genconf $< $@ $(o)/config.mk
175         $(Q)chmod +x $@
176         $(Q)$(call symlink,$@,run/$(BINDIR))
177
178 $(o)/%: %.pl $(o)/config.mk $(BUILDSYS)/genconf
179         $(M)PP $<
180         $(Q)$(BUILDSYS)/genconf $< $@ $(o)/config.mk
181         $(Q)chmod +x $@
182         $(Q)$(call symlink,$@,run/$(BINDIR))
183
184 PERL_MODULE_DIR=UCW
185
186 $(o)/%.pm: $(s)/%.pm
187         $(M)"PM $< -> run/lib/perl5/$(PERL_MODULE_DIR)/$(@F)"
188         $(Q)cp $^ $@
189         $(Q)$(call symlink,$@,run/lib/perl5/$(PERL_MODULE_DIR))
190
191 $(o)/%.pm: %.pm
192         $(M)"PM $< -> run/lib/perl/$(PERL_MODULE_DIR)/$(@F)"
193         $(Q)cp $^ $@
194         $(Q)$(call symlink,$@,run/lib/perl5/$(PERL_MODULE_DIR))
195
196 # Rules for data files
197
198 DATADIR=lib
199
200 $(DATAFILES): $(o)/%: $(s)/%
201         $(M)DATA $<
202         $(Q)cp $^ $@
203         $(Q)$(call symlink,$@,run/$(DATADIR))
204
205 # Rules for documentation
206
207 $(o)/%.html: $(o)/%.txt $(BUILDSYS)/asciidoc.conf $(BUILDSYS)/asciidoc-xhtml.conf run/$(DOCDIR)/$(DOC_MODULE)/.dir-stamp
208         $(M)"DOC-HTML $<"
209         $(Q)asciidoc -e -f $(BUILDSYS)/asciidoc.conf -f $(BUILDSYS)/asciidoc-xhtml.conf -f $(HOST_PREFIX)/etc/asciidoc/asciidoc.conf -f $(HOST_PREFIX)/etc/asciidoc/xhtml11.conf $<
210         $(Q)$(call symlink,$@,run/$(DOCDIR)/$(DOC_MODULE))
211
212 # In reality, we do not depend on the .txt files, but on the corresponding .deflist's.
213 # However, the Makefile language cannot express that doc-extract generates both .txt
214 # and .deflist, so we always use the .txt's in dependencies.
215 $(patsubst %.html,%.txt,$(DOC_INDICES)): $(o)/%.txt: $(patsubst %.html,%.txt,$(DOCS)) $(BUILDSYS)/doc-defs
216         $(M)"DOC-DEFS $@"
217         $(Q)echo $@: $(DOC_HEAD) $(DOC_LIST) >> $(o)/depend.new
218         $(Q)$(BUILDSYS)/doc-defs $(DOC_HEAD) $@ $(DOC_LIST)
219
220 $(patsubst %.html,%.txt,$(DOCS)): $(o)/%.txt: $(s)/%.txt $(BUILDSYS)/doc-extract
221         $(M)"DOC-EXT $<"
222         $(Q)$(BUILDSYS)/doc-extract $< $@ $(o)/depend.new $(s) $(patsubst %.txt,%.deflist,$@)
223
224 # Don't delete intermediate targets. There shouldn't be any, but due to bugs
225 # in GNU Make rules with targets in not-yet-existing directories are ignored
226 # when searching for implicit rules and thence targets considered intermediate.
227 .SECONDARY:
228
229 .PHONY: all clean distclean runtree programs api datafiles force tags configs dust install docs tests