]> mj.ucw.cz Git - libucw.git/blob - build/Makebottom
fix building shared libraries on Darwin
[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_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)" $(BUILDSYS)/lib-flags $^) $(LIBS)
67         $(Q)$(call symlink-alias,$@,run/$(SO_RUNDIR),$(*F)$(SONAME_INFIX).so$(SONAME_SUFFIX))
68 # On Darwin, gcc expects shared libraries in *.dylib instead of *.so.
69 # Surprisingly, when a program is run, it suffices to have *.so files.
70 # We don't want to mess up the whole build system with configurable
71 # suffices and we also don't want to incur an overhead on Linux, so we
72 # just create symbolic links on Darwin, if requested.
73 %.dylib: %.so
74         cd $(dir $<) && ln -fs $(notdir $<) $(notdir $@)
75
76 $(o)/%.pc: $(s)/%.pc $(o)/%.$(LS)
77         $(M)PC $<
78         $(Q)DEPS="$(shell $(BUILDSYS)/lib-deps $^)" LIBDIR=$(@D) $(BUILDSYS)/genconf $< $@ $(o)/config.mk
79         $(Q)mkdir -p $(o)/pkgconfig
80         $(Q)$(call symlink,$@,$(o)/pkgconfig)
81
82 # Rules for public API
83
84 ifdef CONFIG_INSTALL_API
85
86 ifdef CONFIG_LOCAL
87 # Need an absolute path
88 API_ROOT:=$(shell pwd)/run
89 API_LIBDIR=$(API_ROOT)/lib
90 API_INCDIR=$(API_ROOT)/include
91 else
92 API_LIBDIR=$(INSTALL_LIB_DIR)
93 API_INCDIR=$(INSTALL_INCLUDE_DIR)
94 endif
95 INSTALL_RUNDIRS+=include lib/pkgconfig
96 api: $(API_INCLUDES) $(addprefix run/lib/pkgconfig/,$(addsuffix .pc,$(API_LIBS)))
97
98 $(o)/%/.include-stamp:
99         $(Q)$(BUILDSYS)/install-includes $(<D) run/include/$(IDST) $(?F)
100         $(Q)touch $@
101
102 run/lib/pkgconfig/%.pc:         # RHS supplied in the sub-makefile
103         $(M)PC-API $@
104         $(Q)sed <$< >$@ "s@^libdir=.*@libdir=$(API_LIBDIR)@;s@^incdir=.*@incdir=$(API_INCDIR)@"
105
106 else
107 api:
108 endif
109
110 # Rules for compiling C
111
112 $(o)/%.o: $(s)/%.c $(o)/autoconf.h
113         $(M)CC $<
114         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
115
116 $(o)/%.o: %.c $(o)/autoconf.h
117         $(M)CC $<
118         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
119
120 %.o: %.c $(o)/autoconf.h
121         $(M)CC $<
122         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
123
124 $(o)/%.oo: $(s)/%.c $(o)/autoconf.h
125         $(M)CC-SO $<
126         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
127
128 $(o)/%.oo: %.c $(o)/autoconf.h
129         $(M)CC-SO $<
130         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
131
132 %.oo: %.c $(o)/autoconf.h
133         $(M)CC-SO $<
134         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
135
136 $(o)/%-tt.o: $(s)/%.c $(o)/autoconf.h
137         $(M)CC-TEST $<
138         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -DTEST -c -o $@ $<
139
140 # Rules for testing
141
142 $(o)/%-t: $(o)/%-tt.o $(TESTING_DEPS)
143         $(M)LD-TEST $@
144         $(Q)$(CC) $(LDFLAGS) -o $@ $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" $(BUILDSYS)/lib-flags $^) $(LIBS)
145
146 $(o)/%.test: $(s)/%.t $(BUILDSYS)/tester
147         $(M)TEST $@
148         $(Q)$(BUILDSYS)/tester --rundir=run $(TESTERFLAGS) $< && touch $@
149
150 # Rules for binaries
151
152 BINDIR=bin
153
154 $(o)/%: $(o)/%.o
155         $(M)LD $@
156         $(Q)$(CC) $(LDFLAGS) -o $@ $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" $(BUILDSYS)/lib-flags $^) $(LIBS)
157         $(Q)$(call symlink,$@,run/$(BINDIR))
158
159 $(o)/%: $(s)/%.sh $(o)/config.mk $(BUILDSYS)/genconf
160         $(M)PP $<
161         $(Q)$(BUILDSYS)/genconf $< $@ $(o)/config.mk
162         $(Q)chmod +x $@
163         $(Q)$(call symlink,$@,run/$(BINDIR))
164
165 $(o)/%: %.sh $(o)/config.mk $(BUILDSYS)/genconf
166         $(M)PP $<
167         $(Q)$(BUILDSYS)/genconf $< $@ $(o)/config.mk
168         $(Q)chmod +x $@
169         $(Q)$(call symlink,$@,run/$(BINDIR))
170
171 $(o)/%: $(s)/%.pl $(o)/config.mk $(BUILDSYS)/genconf
172         $(M)PP $<
173         $(Q)$(BUILDSYS)/genconf $< $@ $(o)/config.mk
174         $(Q)chmod +x $@
175         $(Q)$(call symlink,$@,run/$(BINDIR))
176
177 $(o)/%: %.pl $(o)/config.mk $(BUILDSYS)/genconf
178         $(M)PP $<
179         $(Q)$(BUILDSYS)/genconf $< $@ $(o)/config.mk
180         $(Q)chmod +x $@
181         $(Q)$(call symlink,$@,run/$(BINDIR))
182
183 PERL_MODULE_DIR=UCW
184
185 $(o)/%.pm: $(s)/%.pm
186         $(M)"PM $< -> run/lib/perl5/$(PERL_MODULE_DIR)/$(@F)"
187         $(Q)cp $^ $@
188         $(Q)$(call symlink,$@,run/lib/perl5/$(PERL_MODULE_DIR))
189
190 $(o)/%.pm: %.pm
191         $(M)"PM $< -> run/lib/perl/$(PERL_MODULE_DIR)/$(@F)"
192         $(Q)cp $^ $@
193         $(Q)$(call symlink,$@,run/lib/perl5/$(PERL_MODULE_DIR))
194
195 # Rules for data files
196
197 DATADIR=lib
198
199 $(DATAFILES): $(o)/%: $(s)/%
200         $(M)DATA $<
201         $(Q)cp $^ $@
202         $(Q)$(call symlink,$@,run/$(DATADIR))
203
204 # Rules for documentation
205
206 $(o)/%.html: $(o)/%.txt $(BUILDSYS)/asciidoc.conf $(BUILDSYS)/asciidoc-xhtml.conf run/$(DOCDIR)/$(DOC_MODULE)/.dir-stamp
207         $(M)"DOC-HTML $<"
208         $(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 $<
209         $(Q)$(call symlink,$@,run/$(DOCDIR)/$(DOC_MODULE))
210
211 # In reality, we do not depend on the .txt files, but on the corresponding .deflist's.
212 # However, the Makefile language cannot express that doc-extract generates both .txt
213 # and .deflist, so we always use the .txt's in dependencies.
214 $(patsubst %.html,%.txt,$(DOC_INDICES)): $(o)/%.txt: $(patsubst %.html,%.txt,$(DOCS)) $(BUILDSYS)/doc-defs
215         $(M)"DOC-DEFS $@"
216         $(Q)echo $@: $(DOC_HEAD) $(DOC_LIST) >> $(o)/depend.new
217         $(Q)$(BUILDSYS)/doc-defs $(DOC_HEAD) $@ $(DOC_LIST)
218
219 $(patsubst %.html,%.txt,$(DOCS)): $(o)/%.txt: $(s)/%.txt $(BUILDSYS)/doc-extract
220         $(M)"DOC-EXT $<"
221         $(Q)$(BUILDSYS)/doc-extract $< $@ $(o)/depend.new $(s) $(patsubst %.txt,%.deflist,$@)
222
223 # Don't delete intermediate targets. There shouldn't be any, but due to bugs
224 # in GNU Make rules with targets in not-yet-existing directories are ignored
225 # when searching for implicit rules and thence targets considered intermediate.
226 .SECONDARY:
227
228 .PHONY: all clean distclean runtree programs api datafiles force tags configs dust install docs tests