]> mj.ucw.cz Git - libucw.git/blob - build/Makebottom
Libucw: Be able to use public tmp directory.
[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/, $(CONFIG_DIR) $(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/$(CONFIG_DIR)/,$(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/$(CONFIG_DIR)/%: $(s)/$(CONFIG_DIR)/% $(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/$(CONFIG_DIR)/$(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-alias,$@,run/lib,$(*F)$(LIBNAME_INFIX).a)
59 endif
60
61 %.so:
62         $(M)LD $@
63         $(Q)$(CC) $(LSHARED) $(LDFLAGS) -o $@ $^
64         $(Q)$(call symlink-alias,$@,run/lib,$(*F)$(SONAME_INFIX).so$(SONAME_SUFFIX))
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 ifdef CONFIG_LOCAL
77 # Need an absolute path
78 API_ROOT:=$(shell pwd)/run
79 API_LIBDIR=$(API_ROOT)/lib
80 API_INCDIR=$(API_ROOT)/include
81 else
82 API_LIBDIR=$(INSTALL_LIB_DIR)
83 API_INCDIR=$(INSTALL_INCLUDE_DIR)
84 endif
85 INSTALL_RUNDIRS+=include lib/pkgconfig
86 api: $(API_INCLUDES) $(addprefix run/lib/pkgconfig/,$(addsuffix .pc,$(API_LIBS)))
87
88 $(o)/%/.include-stamp:
89         $(Q)$(s)/build/install-includes $(<D) run/include/$(IDST) $(?F)
90         $(Q)touch $@
91
92 run/lib/pkgconfig/%.pc:         # RHS supplied in the sub-makefile
93         $(M)PC-API $@
94         $(Q)sed <$< >$@ "s@^libdir=.*@libdir=$(API_LIBDIR)@;s@^incdir=.*@incdir=$(API_INCDIR)@"
95
96 else
97 api:
98 endif
99
100 # Rules for compiling C
101
102 $(o)/%.o: $(s)/%.c $(o)/autoconf.h
103         $(M)CC $<
104         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
105
106 $(o)/%.o: %.c $(o)/autoconf.h
107         $(M)CC $<
108         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
109
110 %.o: %.c $(o)/autoconf.h
111         $(M)CC $<
112         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -c -o $@ $<
113
114 $(o)/%.oo: $(s)/%.c $(o)/autoconf.h
115         $(M)CC-SO $<
116         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
117
118 $(o)/%.oo: %.c $(o)/autoconf.h
119         $(M)CC-SO $<
120         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
121
122 %.oo: %.c $(o)/autoconf.h
123         $(M)CC-SO $<
124         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) $(CSHARED) -c -o $@ $<
125
126 $(o)/%-tt.o: $(s)/%.c $(o)/autoconf.h
127         $(M)CC-TEST $<
128         $(Q)DEPENDENCIES_OUTPUT="$(o)/depend.new $@" $(CC) $(CFLAGS) -DTEST -c -o $@ $<
129
130 # Rules for testing
131
132 $(o)/%-t: $(o)/%-tt.o $(TESTING_DEPS)
133         $(M)LD-TEST $@
134         $(Q)$(CC) $(LDFLAGS) -o $@ $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" $(s)/build/lib-flags $^) $(LIBS)
135
136 $(o)/%.test: $(s)/%.t $(s)/build/tester
137         $(M)TEST $@
138         $(Q)$(s)/build/tester --rundir=run $(TESTERFLAGS) $< && touch $@
139
140 # Rules for binaries
141
142 BINDIR=bin
143
144 $(o)/%: $(o)/%.o
145         $(M)LD $@
146         $(Q)$(CC) $(LDFLAGS) -o $@ $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" $(s)/build/lib-flags $^) $(LIBS)
147         $(Q)$(call symlink,$@,run/$(BINDIR))
148
149 $(o)/%: $(s)/%.sh $(o)/config.mk $(s)/build/genconf
150         $(M)PP $<
151         $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
152         $(Q)chmod +x $@
153         $(Q)$(call symlink,$@,run/$(BINDIR))
154
155 $(o)/%: %.sh $(o)/config.mk $(s)/build/genconf
156         $(M)PP $<
157         $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
158         $(Q)chmod +x $@
159         $(Q)$(call symlink,$@,run/$(BINDIR))
160
161 $(o)/%: $(s)/%.pl $(o)/config.mk $(s)/build/genconf
162         $(M)PP $<
163         $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
164         $(Q)chmod +x $@
165         $(Q)$(call symlink,$@,run/$(BINDIR))
166
167 $(o)/%: %.pl $(o)/config.mk $(s)/build/genconf
168         $(M)PP $<
169         $(Q)$(s)/build/genconf $< $@ $(o)/config.mk
170         $(Q)chmod +x $@
171         $(Q)$(call symlink,$@,run/$(BINDIR))
172
173 PERL_MODULE_DIR=UCW
174
175 $(o)/%.pm: $(s)/%.pm
176         $(M)"PM $< -> run/lib/perl5/$(PERL_MODULE_DIR)/$(@F)"
177         $(Q)cp $^ $@
178         $(Q)$(call symlink,$@,run/lib/perl5/$(PERL_MODULE_DIR))
179
180 $(o)/%.pm: %.pm
181         $(M)"PM $< -> run/lib/perl/$(PERL_MODULE_DIR)/$(@F)"
182         $(Q)cp $^ $@
183         $(Q)$(call symlink,$@,run/lib/perl5/$(PERL_MODULE_DIR))
184
185 # Rules for data files
186
187 DATADIR=lib
188
189 $(DATAFILES): $(o)/%: $(s)/%
190         $(M)DATA $<
191         $(Q)cp $^ $@
192         $(Q)$(call symlink,$@,run/$(DATADIR))
193
194 # Default installation target
195
196 default-install:
197         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)
198
199 # Don't delete intermediate targets. There shouldn't be any, but due to bugs
200 # in GNU Make rules with targets in not-yet-existing directories are ignored
201 # when searching for implicit rules and thence targets considered intermediate.
202 .SECONDARY:
203
204 .PHONY: all clean distclean runtree programs api datafiles force tags configs dust install default-install