]>
Commit | Line | Data |
---|---|---|
1 | # Clear out all vpaths, then set just one (default vpath) for the main build | |
2 | # directory. | |
3 | vpath | |
4 | vpath % . | |
5 | ||
6 | # Clear the default suffixes, so that built-in rules are not used. | |
7 | .SUFFIXES : | |
8 | ||
9 | SHELL := /bin/sh | |
10 | ||
11 | CC := @CC@ | |
12 | ||
13 | # Configuration parameters. | |
14 | DESTDIR = | |
15 | BINDIR := $(DESTDIR)@BINDIR@ | |
16 | INCLUDEDIR := $(DESTDIR)@INCLUDEDIR@ | |
17 | LIBDIR := $(DESTDIR)@LIBDIR@ | |
18 | DATADIR := $(DESTDIR)@DATADIR@ | |
19 | MANDIR := $(DESTDIR)@MANDIR@ | |
20 | srcroot := @srcroot@ | |
21 | objroot := @objroot@ | |
22 | abs_srcroot := @abs_srcroot@ | |
23 | abs_objroot := @abs_objroot@ | |
24 | ||
25 | # Build parameters. | |
26 | CPPFLAGS := @CPPFLAGS@ -I$(srcroot)include -I$(objroot)include | |
27 | CFLAGS := @CFLAGS@ | |
28 | LDFLAGS := @LDFLAGS@ | |
29 | EXTRA_LDFLAGS := @EXTRA_LDFLAGS@ | |
30 | LIBS := @LIBS@ | |
31 | RPATH_EXTRA := @RPATH_EXTRA@ | |
32 | SO := @so@ | |
33 | IMPORTLIB := @importlib@ | |
34 | O := @o@ | |
35 | A := @a@ | |
36 | EXE := @exe@ | |
37 | LIBPREFIX := @libprefix@ | |
38 | REV := @rev@ | |
39 | install_suffix := @install_suffix@ | |
40 | ABI := @abi@ | |
41 | XSLTPROC := @XSLTPROC@ | |
42 | AUTOCONF := @AUTOCONF@ | |
43 | _RPATH = @RPATH@ | |
44 | RPATH = $(if $(1),$(call _RPATH,$(1))) | |
45 | cfghdrs_in := @cfghdrs_in@ | |
46 | cfghdrs_out := @cfghdrs_out@ | |
47 | cfgoutputs_in := @cfgoutputs_in@ | |
48 | cfgoutputs_out := @cfgoutputs_out@ | |
49 | enable_autogen := @enable_autogen@ | |
50 | enable_experimental := @enable_experimental@ | |
51 | DSO_LDFLAGS = @DSO_LDFLAGS@ | |
52 | SOREV = @SOREV@ | |
53 | PIC_CFLAGS = @PIC_CFLAGS@ | |
54 | CTARGET = @CTARGET@ | |
55 | LDTARGET = @LDTARGET@ | |
56 | MKLIB = @MKLIB@ | |
57 | CC_MM = @CC_MM@ | |
58 | ||
59 | ifeq (macho, $(ABI)) | |
60 | TEST_LIBRARY_PATH := DYLD_FALLBACK_LIBRARY_PATH="$(objroot)lib" | |
61 | else | |
62 | ifeq (pecoff, $(ABI)) | |
63 | TEST_LIBRARY_PATH := PATH="$(PATH):$(objroot)lib" | |
64 | else | |
65 | TEST_LIBRARY_PATH := | |
66 | endif | |
67 | endif | |
68 | ||
69 | LIBJEMALLOC := $(LIBPREFIX)jemalloc$(install_suffix) | |
70 | ||
71 | # Lists of files. | |
72 | BINS := $(srcroot)bin/pprof $(objroot)bin/jemalloc.sh | |
73 | CHDRS := $(objroot)include/jemalloc/jemalloc$(install_suffix).h \ | |
74 | $(objroot)include/jemalloc/jemalloc_defs$(install_suffix).h | |
75 | CSRCS := $(srcroot)src/jemalloc.c $(srcroot)src/arena.c $(srcroot)src/atomic.c \ | |
76 | $(srcroot)src/base.c $(srcroot)src/bitmap.c $(srcroot)src/chunk.c \ | |
77 | $(srcroot)src/chunk_dss.c $(srcroot)src/chunk_mmap.c \ | |
78 | $(srcroot)src/ckh.c $(srcroot)src/ctl.c $(srcroot)src/extent.c \ | |
79 | $(srcroot)src/hash.c $(srcroot)src/huge.c $(srcroot)src/mb.c \ | |
80 | $(srcroot)src/mutex.c $(srcroot)src/prof.c $(srcroot)src/quarantine.c \ | |
81 | $(srcroot)src/rtree.c $(srcroot)src/stats.c $(srcroot)src/tcache.c \ | |
82 | $(srcroot)src/util.c $(srcroot)src/tsd.c | |
83 | ifeq (macho, $(ABI)) | |
84 | CSRCS += $(srcroot)src/zone.c | |
85 | endif | |
86 | ifeq ($(IMPORTLIB),$(SO)) | |
87 | STATIC_LIBS := $(objroot)lib/$(LIBJEMALLOC).$(A) | |
88 | endif | |
89 | ifdef PIC_CFLAGS | |
90 | STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_pic.$(A) | |
91 | else | |
92 | STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_s.$(A) | |
93 | endif | |
94 | DSOS := $(objroot)lib/$(LIBJEMALLOC).$(SOREV) | |
95 | ifneq ($(SOREV),$(SO)) | |
96 | DSOS += $(objroot)lib/$(LIBJEMALLOC).$(SO) | |
97 | endif | |
98 | MAN3 := $(objroot)doc/jemalloc$(install_suffix).3 | |
99 | DOCS_XML := $(objroot)doc/jemalloc$(install_suffix).xml | |
100 | DOCS_HTML := $(DOCS_XML:$(objroot)%.xml=$(srcroot)%.html) | |
101 | DOCS_MAN3 := $(DOCS_XML:$(objroot)%.xml=$(srcroot)%.3) | |
102 | DOCS := $(DOCS_HTML) $(DOCS_MAN3) | |
103 | CTESTS := $(srcroot)test/aligned_alloc.c $(srcroot)test/allocated.c \ | |
104 | $(srcroot)test/ALLOCM_ARENA.c $(srcroot)test/bitmap.c \ | |
105 | $(srcroot)test/mremap.c $(srcroot)test/posix_memalign.c \ | |
106 | $(srcroot)test/thread_arena.c $(srcroot)test/thread_tcache_enabled.c | |
107 | ifeq ($(enable_experimental), 1) | |
108 | CTESTS += $(srcroot)test/allocm.c $(srcroot)test/rallocm.c | |
109 | endif | |
110 | ||
111 | COBJS := $(CSRCS:$(srcroot)%.c=$(objroot)%.$(O)) | |
112 | CPICOBJS := $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.$(O)) | |
113 | CTESTOBJS := $(CTESTS:$(srcroot)%.c=$(objroot)%.$(O)) | |
114 | ||
115 | .PHONY: all dist doc_html doc_man doc | |
116 | .PHONY: install_bin install_include install_lib | |
117 | .PHONY: install_html install_man install_doc install | |
118 | .PHONY: tests check clean distclean relclean | |
119 | ||
120 | .SECONDARY : $(CTESTOBJS) | |
121 | ||
122 | # Default target. | |
123 | all: build | |
124 | ||
125 | dist: build_doc | |
126 | ||
127 | $(srcroot)doc/%.html : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/html.xsl | |
128 | $(XSLTPROC) -o $@ $(objroot)doc/html.xsl $< | |
129 | ||
130 | $(srcroot)doc/%.3 : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/manpages.xsl | |
131 | $(XSLTPROC) -o $@ $(objroot)doc/manpages.xsl $< | |
132 | ||
133 | build_doc_html: $(DOCS_HTML) | |
134 | build_doc_man: $(DOCS_MAN3) | |
135 | build_doc: $(DOCS) | |
136 | ||
137 | # | |
138 | # Include generated dependency files. | |
139 | # | |
140 | ifdef CC_MM | |
141 | -include $(COBJS:%.$(O)=%.d) | |
142 | -include $(CPICOBJS:%.$(O)=%.d) | |
143 | -include $(CTESTOBJS:%.$(O)=%.d) | |
144 | endif | |
145 | ||
146 | $(COBJS): $(objroot)src/%.$(O): $(srcroot)src/%.c | |
147 | $(CPICOBJS): $(objroot)src/%.pic.$(O): $(srcroot)src/%.c | |
148 | $(CPICOBJS): CFLAGS += $(PIC_CFLAGS) | |
149 | $(CTESTOBJS): $(objroot)test/%.$(O): $(srcroot)test/%.c | |
150 | $(CTESTOBJS): CPPFLAGS += -I$(objroot)test | |
151 | ifneq ($(IMPORTLIB),$(SO)) | |
152 | $(COBJS): CPPFLAGS += -DDLLEXPORT | |
153 | endif | |
154 | ||
155 | ifndef CC_MM | |
156 | # Dependencies | |
157 | HEADER_DIRS = $(srcroot)include/jemalloc/internal \ | |
158 | $(objroot)include/jemalloc $(objroot)include/jemalloc/internal | |
159 | HEADERS = $(wildcard $(foreach dir,$(HEADER_DIRS),$(dir)/*.h)) | |
160 | $(COBJS) $(CPICOBJS) $(CTESTOBJS): $(HEADERS) | |
161 | $(CTESTOBJS): $(objroot)test/jemalloc_test.h | |
162 | endif | |
163 | ||
164 | $(COBJS) $(CPICOBJS) $(CTESTOBJS): %.$(O): | |
165 | @mkdir -p $(@D) | |
166 | $(CC) $(CFLAGS) -c $(CPPFLAGS) $(CTARGET) $< | |
167 | ifdef CC_MM | |
168 | @$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $< | |
169 | endif | |
170 | ||
171 | ifneq ($(SOREV),$(SO)) | |
172 | %.$(SO) : %.$(SOREV) | |
173 | @mkdir -p $(@D) | |
174 | ln -sf $(<F) $@ | |
175 | endif | |
176 | ||
177 | $(objroot)lib/$(LIBJEMALLOC).$(SOREV) : $(if $(PIC_CFLAGS),$(CPICOBJS),$(COBJS)) | |
178 | @mkdir -p $(@D) | |
179 | $(CC) $(DSO_LDFLAGS) $(call RPATH,$(RPATH_EXTRA)) $(LDTARGET) $+ $(LDFLAGS) $(LIBS) $(EXTRA_LDFLAGS) | |
180 | ||
181 | $(objroot)lib/$(LIBJEMALLOC)_pic.$(A) : $(CPICOBJS) | |
182 | $(objroot)lib/$(LIBJEMALLOC).$(A) : $(COBJS) | |
183 | $(objroot)lib/$(LIBJEMALLOC)_s.$(A) : $(COBJS) | |
184 | ||
185 | $(STATIC_LIBS): | |
186 | @mkdir -p $(@D) | |
187 | $(MKLIB) $+ | |
188 | ||
189 | $(objroot)test/bitmap$(EXE): $(objroot)src/bitmap.$(O) | |
190 | ||
191 | $(objroot)test/%$(EXE): $(objroot)test/%.$(O) $(objroot)src/util.$(O) $(DSOS) | |
192 | @mkdir -p $(@D) | |
193 | $(CC) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB) $(filter -lpthread,$(LIBS)) $(EXTRA_LDFLAGS) | |
194 | ||
195 | build_lib_shared: $(DSOS) | |
196 | build_lib_static: $(STATIC_LIBS) | |
197 | build: build_lib_shared build_lib_static | |
198 | ||
199 | install_bin: | |
200 | install -d $(BINDIR) | |
201 | @for b in $(BINS); do \ | |
202 | echo "install -m 755 $$b $(BINDIR)"; \ | |
203 | install -m 755 $$b $(BINDIR); \ | |
204 | done | |
205 | ||
206 | install_include: | |
207 | install -d $(INCLUDEDIR)/jemalloc | |
208 | @for h in $(CHDRS); do \ | |
209 | echo "install -m 644 $$h $(INCLUDEDIR)/jemalloc"; \ | |
210 | install -m 644 $$h $(INCLUDEDIR)/jemalloc; \ | |
211 | done | |
212 | ||
213 | install_lib_shared: $(DSOS) | |
214 | install -d $(LIBDIR) | |
215 | install -m 755 $(objroot)lib/$(LIBJEMALLOC).$(SOREV) $(LIBDIR) | |
216 | ifneq ($(SOREV),$(SO)) | |
217 | ln -sf $(LIBJEMALLOC).$(SOREV) $(LIBDIR)/$(LIBJEMALLOC).$(SO) | |
218 | endif | |
219 | ||
220 | install_lib_static: $(STATIC_LIBS) | |
221 | install -d $(LIBDIR) | |
222 | @for l in $(STATIC_LIBS); do \ | |
223 | echo "install -m 755 $$l $(LIBDIR)"; \ | |
224 | install -m 755 $$l $(LIBDIR); \ | |
225 | done | |
226 | ||
227 | install_lib: install_lib_shared install_lib_static | |
228 | ||
229 | install_doc_html: | |
230 | install -d $(DATADIR)/doc/jemalloc$(install_suffix) | |
231 | @for d in $(DOCS_HTML); do \ | |
232 | echo "install -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix)"; \ | |
233 | install -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix); \ | |
234 | done | |
235 | ||
236 | install_doc_man: | |
237 | install -d $(MANDIR)/man3 | |
238 | @for d in $(DOCS_MAN3); do \ | |
239 | echo "install -m 644 $$d $(MANDIR)/man3"; \ | |
240 | install -m 644 $$d $(MANDIR)/man3; \ | |
241 | done | |
242 | ||
243 | install_doc: install_doc_html install_doc_man | |
244 | ||
245 | install: install_bin install_include install_lib install_doc | |
246 | ||
247 | tests: $(CTESTS:$(srcroot)%.c=$(objroot)%$(EXE)) | |
248 | ||
249 | check: tests | |
250 | @mkdir -p $(objroot)test | |
251 | @$(SHELL) -c 'total=0; \ | |
252 | failures=0; \ | |
253 | echo "========================================="; \ | |
254 | for t in $(CTESTS:$(srcroot)%.c=$(objroot)%); do \ | |
255 | total=`expr $$total + 1`; \ | |
256 | /bin/echo -n "$${t} ... "; \ | |
257 | $(TEST_LIBRARY_PATH) $${t}$(EXE) $(abs_srcroot) \ | |
258 | $(abs_objroot) > $(objroot)$${t}.out 2>&1; \ | |
259 | if test -e "$(srcroot)$${t}.exp"; then \ | |
260 | diff -w -u $(srcroot)$${t}.exp \ | |
261 | $(objroot)$${t}.out >/dev/null 2>&1; \ | |
262 | fail=$$?; \ | |
263 | if test "$${fail}" -eq "1" ; then \ | |
264 | failures=`expr $${failures} + 1`; \ | |
265 | echo "*** FAIL ***"; \ | |
266 | else \ | |
267 | echo "pass"; \ | |
268 | fi; \ | |
269 | else \ | |
270 | echo "*** FAIL *** (.exp file is missing)"; \ | |
271 | failures=`expr $${failures} + 1`; \ | |
272 | fi; \ | |
273 | done; \ | |
274 | echo "========================================="; \ | |
275 | echo "Failures: $${failures}/$${total}"' | |
276 | ||
277 | clean: | |
278 | rm -f $(COBJS) | |
279 | rm -f $(CPICOBJS) | |
280 | rm -f $(COBJS:%.$(O)=%.d) | |
281 | rm -f $(CPICOBJS:%.$(O)=%.d) | |
282 | rm -f $(CTESTOBJS:%.$(O)=%$(EXE)) | |
283 | rm -f $(CTESTOBJS) | |
284 | rm -f $(CTESTOBJS:%.$(O)=%.d) | |
285 | rm -f $(CTESTOBJS:%.$(O)=%.out) | |
286 | rm -f $(DSOS) $(STATIC_LIBS) | |
287 | ||
288 | distclean: clean | |
289 | rm -rf $(objroot)autom4te.cache | |
290 | rm -f $(objroot)config.log | |
291 | rm -f $(objroot)config.status | |
292 | rm -f $(objroot)config.stamp | |
293 | rm -f $(cfghdrs_out) | |
294 | rm -f $(cfgoutputs_out) | |
295 | ||
296 | relclean: distclean | |
297 | rm -f $(objroot)configure | |
298 | rm -f $(srcroot)VERSION | |
299 | rm -f $(DOCS_HTML) | |
300 | rm -f $(DOCS_MAN3) | |
301 | ||
302 | #=============================================================================== | |
303 | # Re-configuration rules. | |
304 | ||
305 | ifeq ($(enable_autogen), 1) | |
306 | $(srcroot)configure : $(srcroot)configure.ac | |
307 | cd ./$(srcroot) && $(AUTOCONF) | |
308 | ||
309 | $(objroot)config.status : $(srcroot)configure | |
310 | ./$(objroot)config.status --recheck | |
311 | ||
312 | $(srcroot)config.stamp.in : $(srcroot)configure.ac | |
313 | echo stamp > $(srcroot)config.stamp.in | |
314 | ||
315 | $(objroot)config.stamp : $(cfgoutputs_in) $(cfghdrs_in) $(srcroot)configure | |
316 | ./$(objroot)config.status | |
317 | @touch $@ | |
318 | ||
319 | # There must be some action in order for make to re-read Makefile when it is | |
320 | # out of date. | |
321 | $(cfgoutputs_out) $(cfghdrs_out) : $(objroot)config.stamp | |
322 | @true | |
323 | endif |