1 # Clear out all vpaths, then set just one (default vpath) for the main build
6 # Clear the default suffixes, so that built-in rules are not used.
13 # Configuration parameters.
15 BINDIR := $(DESTDIR)@BINDIR@
16 INCLUDEDIR := $(DESTDIR)@INCLUDEDIR@
17 LIBDIR := $(DESTDIR)@LIBDIR@
18 DATADIR := $(DESTDIR)@DATADIR@
19 MANDIR := $(DESTDIR)@MANDIR@
22 abs_srcroot := @abs_srcroot@
23 abs_objroot := @abs_objroot@
26 CPPFLAGS := @CPPFLAGS@ -I$(srcroot)include -I$(objroot)include
29 EXTRA_LDFLAGS := @EXTRA_LDFLAGS@
31 RPATH_EXTRA := @RPATH_EXTRA@
33 IMPORTLIB := @importlib@
37 LIBPREFIX := @libprefix@
39 install_suffix := @install_suffix@
41 XSLTPROC := @XSLTPROC@
42 AUTOCONF := @AUTOCONF@
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@
53 PIC_CFLAGS = @PIC_CFLAGS@
60 TEST_LIBRARY_PATH := DYLD_FALLBACK_LIBRARY_PATH="$(objroot)lib"
63 TEST_LIBRARY_PATH := PATH="$(PATH):$(objroot)lib"
69 LIBJEMALLOC := $(LIBPREFIX)jemalloc$(install_suffix)
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
84 CSRCS += $(srcroot)src/zone.c
86 ifeq ($(IMPORTLIB),$(SO))
87 STATIC_LIBS := $(objroot)lib/$(LIBJEMALLOC).$(A)
90 STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_pic.$(A)
92 STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_s.$(A)
94 DSOS := $(objroot)lib/$(LIBJEMALLOC).$(SOREV)
95 ifneq ($(SOREV),$(SO))
96 DSOS += $(objroot)lib/$(LIBJEMALLOC).$(SO)
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/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
111 COBJS := $(CSRCS:$(srcroot)%.c=$(objroot)%.$(O))
112 CPICOBJS := $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.$(O))
113 CTESTOBJS := $(CTESTS:$(srcroot)%.c=$(objroot)%.$(O))
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
120 .SECONDARY : $(CTESTOBJS)
127 $(srcroot)doc/%.html : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/html.xsl
128 $(XSLTPROC) -o $@ $(objroot)doc/html.xsl $<
130 $(srcroot)doc/%.3 : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/manpages.xsl
131 $(XSLTPROC) -o $@ $(objroot)doc/manpages.xsl $<
133 build_doc_html: $(DOCS_HTML)
134 build_doc_man: $(DOCS_MAN3)
138 # Include generated dependency files.
141 -include $(COBJS:%.$(O)=%.d)
142 -include $(CPICOBJS:%.$(O)=%.d)
143 -include $(CTESTOBJS:%.$(O)=%.d)
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
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
164 $(COBJS) $(CPICOBJS) $(CTESTOBJS): %.$(O):
166 $(CC) $(CFLAGS) -c $(CPPFLAGS) $(CTARGET) $<
168 @$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $<
171 ifneq ($(SOREV),$(SO))
177 $(objroot)lib/$(LIBJEMALLOC).$(SOREV) : $(if $(PIC_CFLAGS),$(CPICOBJS),$(COBJS))
179 $(CC) $(DSO_LDFLAGS) $(call RPATH,$(RPATH_EXTRA)) $(LDTARGET) $+ $(LDFLAGS) $(LIBS) $(EXTRA_LDFLAGS)
181 $(objroot)lib/$(LIBJEMALLOC)_pic.$(A) : $(CPICOBJS)
182 $(objroot)lib/$(LIBJEMALLOC).$(A) : $(COBJS)
183 $(objroot)lib/$(LIBJEMALLOC)_s.$(A) : $(COBJS)
189 $(objroot)test/bitmap$(EXE): $(objroot)src/bitmap.$(O)
191 $(objroot)test/%$(EXE): $(objroot)test/%.$(O) $(objroot)src/util.$(O) $(DSOS)
193 $(CC) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB) $(filter -lpthread,$(LIBS)) $(EXTRA_LDFLAGS)
195 build_lib_shared: $(DSOS)
196 build_lib_static: $(STATIC_LIBS)
197 build: build_lib_shared build_lib_static
201 @for b in $(BINS); do \
202 echo "install -m 755 $$b $(BINDIR)"; \
203 install -m 755 $$b $(BINDIR); \
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; \
213 install_lib_shared: $(DSOS)
215 install -m 755 $(objroot)lib/$(LIBJEMALLOC).$(SOREV) $(LIBDIR)
216 ifneq ($(SOREV),$(SO))
217 ln -sf $(LIBJEMALLOC).$(SOREV) $(LIBDIR)/$(LIBJEMALLOC).$(SO)
220 install_lib_static: $(STATIC_LIBS)
222 @for l in $(STATIC_LIBS); do \
223 echo "install -m 755 $$l $(LIBDIR)"; \
224 install -m 755 $$l $(LIBDIR); \
227 install_lib: install_lib_shared install_lib_static
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); \
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; \
243 install_doc: install_doc_html install_doc_man
245 install: install_bin install_include install_lib install_doc
247 tests: $(CTESTS:$(srcroot)%.c=$(objroot)%$(EXE))
250 @mkdir -p $(objroot)test
251 @$(SHELL) -c 'total=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; \
263 if test "$${fail}" -eq "1" ; then \
264 failures=`expr $${failures} + 1`; \
265 echo "*** FAIL ***"; \
270 echo "*** FAIL *** (.exp file is missing)"; \
271 failures=`expr $${failures} + 1`; \
274 echo "========================================="; \
275 echo "Failures: $${failures}/$${total}"'
280 rm -f $(COBJS:%.$(O)=%.d)
281 rm -f $(CPICOBJS:%.$(O)=%.d)
282 rm -f $(CTESTOBJS:%.$(O)=%$(EXE))
284 rm -f $(CTESTOBJS:%.$(O)=%.d)
285 rm -f $(CTESTOBJS:%.$(O)=%.out)
286 rm -f $(DSOS) $(STATIC_LIBS)
289 rm -rf $(objroot)autom4te.cache
290 rm -f $(objroot)config.log
291 rm -f $(objroot)config.status
292 rm -f $(objroot)config.stamp
294 rm -f $(cfgoutputs_out)
297 rm -f $(objroot)configure
298 rm -f $(srcroot)VERSION
302 #===============================================================================
303 # Re-configuration rules.
305 ifeq ($(enable_autogen), 1)
306 $(srcroot)configure : $(srcroot)configure.ac
307 cd ./$(srcroot) && $(AUTOCONF)
309 $(objroot)config.status : $(srcroot)configure
310 ./$(objroot)config.status --recheck
312 $(srcroot)config.stamp.in : $(srcroot)configure.ac
313 echo stamp > $(srcroot)config.stamp.in
315 $(objroot)config.stamp : $(cfgoutputs_in) $(cfghdrs_in) $(srcroot)configure
316 ./$(objroot)config.status
319 # There must be some action in order for make to re-read Makefile when it is
321 $(cfgoutputs_out) $(cfghdrs_out) : $(objroot)config.stamp