]>
Commit | Line | Data |
---|---|---|
a78e148b | 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@ | |
4934f93d | 20 | srcroot := @srcroot@ |
21 | objroot := @objroot@ | |
22 | abs_srcroot := @abs_srcroot@ | |
23 | abs_objroot := @abs_objroot@ | |
a78e148b | 24 | |
25 | # Build parameters. | |
4934f93d | 26 | CPPFLAGS := @CPPFLAGS@ -I$(srcroot)include -I$(objroot)include |
a78e148b | 27 | CFLAGS := @CFLAGS@ |
a78e148b | 28 | LDFLAGS := @LDFLAGS@ |
4934f93d | 29 | EXTRA_LDFLAGS := @EXTRA_LDFLAGS@ |
a78e148b | 30 | LIBS := @LIBS@ |
31 | RPATH_EXTRA := @RPATH_EXTRA@ | |
4934f93d | 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" | |
a78e148b | 61 | else |
4934f93d | 62 | ifeq (pecoff, $(ABI)) |
63 | TEST_LIBRARY_PATH := PATH="$(PATH):$(objroot)lib" | |
a78e148b | 64 | else |
65 | TEST_LIBRARY_PATH := | |
66 | endif | |
4934f93d | 67 | endif |
68 | ||
69 | LIBJEMALLOC := $(LIBPREFIX)jemalloc$(install_suffix) | |
a78e148b | 70 | |
71 | # Lists of files. | |
4934f93d | 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) | |
a78e148b | 93 | endif |
4934f93d | 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) | |
a78e148b | 102 | DOCS := $(DOCS_HTML) $(DOCS_MAN3) |
4934f93d | 103 | CTESTS := $(srcroot)test/aligned_alloc.c $(srcroot)test/allocated.c \ |
104 | $(srcroot)test/bitmap.c $(srcroot)test/mremap.c \ | |
105 | $(srcroot)test/posix_memalign.c $(srcroot)test/thread_arena.c \ | |
106 | $(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)) | |
a78e148b | 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 | ||
4934f93d | 120 | .SECONDARY : $(CTESTOBJS) |
a78e148b | 121 | |
122 | # Default target. | |
4934f93d | 123 | all: build |
a78e148b | 124 | |
4934f93d | 125 | dist: build_doc |
a78e148b | 126 | |
4934f93d | 127 | $(srcroot)doc/%.html : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/html.xsl |
128 | $(XSLTPROC) -o $@ $(objroot)doc/html.xsl $< | |
a78e148b | 129 | |
4934f93d | 130 | $(srcroot)doc/%.3 : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/manpages.xsl |
131 | $(XSLTPROC) -o $@ $(objroot)doc/manpages.xsl $< | |
a78e148b | 132 | |
4934f93d | 133 | build_doc_html: $(DOCS_HTML) |
134 | build_doc_man: $(DOCS_MAN3) | |
135 | build_doc: $(DOCS) | |
a78e148b | 136 | |
137 | # | |
138 | # Include generated dependency files. | |
139 | # | |
4934f93d | 140 | ifdef CC_MM |
141 | -include $(COBJS:%.$(O)=%.d) | |
142 | -include $(CPICOBJS:%.$(O)=%.d) | |
143 | -include $(CTESTOBJS:%.$(O)=%.d) | |
144 | endif | |
a78e148b | 145 | |
4934f93d | 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 | |
a78e148b | 154 | |
4934f93d | 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 | |
a78e148b | 163 | |
4934f93d | 164 | $(COBJS) $(CPICOBJS) $(CTESTOBJS): %.$(O): |
a78e148b | 165 | @mkdir -p $(@D) |
4934f93d | 166 | $(CC) $(CFLAGS) -c $(CPPFLAGS) $(CTARGET) $< |
167 | ifdef CC_MM | |
168 | @$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $< | |
169 | endif | |
a78e148b | 170 | |
4934f93d | 171 | ifneq ($(SOREV),$(SO)) |
172 | %.$(SO) : %.$(SOREV) | |
a78e148b | 173 | @mkdir -p $(@D) |
4934f93d | 174 | ln -sf $(<F) $@ |
175 | endif | |
a78e148b | 176 | |
4934f93d | 177 | $(objroot)lib/$(LIBJEMALLOC).$(SOREV) : $(if $(PIC_CFLAGS),$(CPICOBJS),$(COBJS)) |
a78e148b | 178 | @mkdir -p $(@D) |
4934f93d | 179 | $(CC) $(DSO_LDFLAGS) $(call RPATH,$(RPATH_EXTRA)) $(LDTARGET) $+ $(LDFLAGS) $(LIBS) $(EXTRA_LDFLAGS) |
a78e148b | 180 | |
4934f93d | 181 | $(objroot)lib/$(LIBJEMALLOC)_pic.$(A) : $(CPICOBJS) |
182 | $(objroot)lib/$(LIBJEMALLOC).$(A) : $(COBJS) | |
183 | $(objroot)lib/$(LIBJEMALLOC)_s.$(A) : $(COBJS) | |
a78e148b | 184 | |
4934f93d | 185 | $(STATIC_LIBS): |
a78e148b | 186 | @mkdir -p $(@D) |
4934f93d | 187 | $(MKLIB) $+ |
a78e148b | 188 | |
4934f93d | 189 | $(objroot)test/bitmap$(EXE): $(objroot)src/bitmap.$(O) |
a78e148b | 190 | |
4934f93d | 191 | $(objroot)test/%$(EXE): $(objroot)test/%.$(O) $(objroot)src/util.$(O) $(DSOS) |
a78e148b | 192 | @mkdir -p $(@D) |
4934f93d | 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 | |
a78e148b | 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 | ||
4934f93d | 213 | install_lib_shared: $(DSOS) |
a78e148b | 214 | install -d $(LIBDIR) |
4934f93d | 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 | |
a78e148b | 228 | |
4934f93d | 229 | install_doc_html: |
230 | install -d $(DATADIR)/doc/jemalloc$(install_suffix) | |
a78e148b | 231 | @for d in $(DOCS_HTML); do \ |
4934f93d | 232 | echo "install -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix)"; \ |
233 | install -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix); \ | |
a78e148b | 234 | done |
235 | ||
4934f93d | 236 | install_doc_man: |
a78e148b | 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 | ||
4934f93d | 243 | install_doc: install_doc_html install_doc_man |
a78e148b | 244 | |
245 | install: install_bin install_include install_lib install_doc | |
246 | ||
4934f93d | 247 | tests: $(CTESTS:$(srcroot)%.c=$(objroot)%$(EXE)) |
a78e148b | 248 | |
249 | check: tests | |
4934f93d | 250 | @mkdir -p $(objroot)test |
a78e148b | 251 | @$(SHELL) -c 'total=0; \ |
252 | failures=0; \ | |
253 | echo "========================================="; \ | |
4934f93d | 254 | for t in $(CTESTS:$(srcroot)%.c=$(objroot)%); do \ |
a78e148b | 255 | total=`expr $$total + 1`; \ |
256 | /bin/echo -n "$${t} ... "; \ | |
4934f93d | 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; \ | |
a78e148b | 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: | |
4934f93d | 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) | |
a78e148b | 286 | rm -f $(DSOS) $(STATIC_LIBS) |
287 | ||
288 | distclean: clean | |
4934f93d | 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) | |
a78e148b | 295 | |
296 | relclean: distclean | |
4934f93d | 297 | rm -f $(objroot)configure |
298 | rm -f $(srcroot)VERSION | |
a78e148b | 299 | rm -f $(DOCS_HTML) |
300 | rm -f $(DOCS_MAN3) | |
301 | ||
302 | #=============================================================================== | |
303 | # Re-configuration rules. | |
304 | ||
4934f93d | 305 | ifeq ($(enable_autogen), 1) |
306 | $(srcroot)configure : $(srcroot)configure.ac | |
307 | cd ./$(srcroot) && $(AUTOCONF) | |
a78e148b | 308 | |
4934f93d | 309 | $(objroot)config.status : $(srcroot)configure |
310 | ./$(objroot)config.status --recheck | |
a78e148b | 311 | |
4934f93d | 312 | $(srcroot)config.stamp.in : $(srcroot)configure.ac |
313 | echo stamp > $(srcroot)config.stamp.in | |
a78e148b | 314 | |
4934f93d | 315 | $(objroot)config.stamp : $(cfgoutputs_in) $(cfghdrs_in) $(srcroot)configure |
316 | ./$(objroot)config.status | |
a78e148b | 317 | @touch $@ |
318 | ||
319 | # There must be some action in order for make to re-read Makefile when it is | |
320 | # out of date. | |
4934f93d | 321 | $(cfgoutputs_out) $(cfghdrs_out) : $(objroot)config.stamp |
a78e148b | 322 | @true |
323 | endif |