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