blob: 7399f27789979cfe2dc42e3d5e37bb369401164d [file] [log] [blame]
Jason Evansb7924f52009-06-23 19:01:18 -07001# Clear out all vpaths, then set just one (default vpath) for the main build
2# directory.
3vpath
4vpath % .
5
6# Clear the default suffixes, so that built-in rules are not used.
7.SUFFIXES :
8
9SHELL := /bin/sh
10
11CC := @CC@
12
13# Configuration parameters.
Jason Evanscfeccd32010-03-03 15:48:20 -080014DESTDIR =
Jason Evansa91f2102010-04-02 13:50:53 -070015BINDIR := $(DESTDIR)@BINDIR@
Jason Evanscfeccd32010-03-03 15:48:20 -080016INCLUDEDIR := $(DESTDIR)@INCLUDEDIR@
17LIBDIR := $(DESTDIR)@LIBDIR@
Jason Evansaee7fd22010-11-24 22:00:02 -080018DATADIR := $(DESTDIR)@DATADIR@
Jason Evanscfeccd32010-03-03 15:48:20 -080019MANDIR := $(DESTDIR)@MANDIR@
Mike Hommey2d04f5e2012-04-16 16:30:22 +020020srcroot := @srcroot@
21objroot := @objroot@
22abs_srcroot := @abs_srcroot@
23abs_objroot := @abs_objroot@
Jason Evansb7924f52009-06-23 19:01:18 -070024
25# Build parameters.
Mike Hommey2d04f5e2012-04-16 16:30:22 +020026CPPFLAGS := @CPPFLAGS@ -I$(srcroot)include -I$(objroot)include
Arun Sharmaaf5d6982011-02-15 14:13:38 -080027CFLAGS := @CFLAGS@
Jason Evansb7924f52009-06-23 19:01:18 -070028LDFLAGS := @LDFLAGS@
Mike Hommeyfd97b1d2012-04-30 12:38:31 +020029EXTRA_LDFLAGS := @EXTRA_LDFLAGS@
Jason Evansb7924f52009-06-23 19:01:18 -070030LIBS := @LIBS@
31RPATH_EXTRA := @RPATH_EXTRA@
Jason Evansf576c632011-11-01 22:27:41 -070032SO := @so@
Mike Hommeyfd97b1d2012-04-30 12:38:31 +020033IMPORTLIB := @importlib@
Mike Hommey5bee66d2012-04-16 16:30:24 +020034O := @o@
35A := @a@
36EXE := @exe@
Mike Hommeya19e87f2012-04-21 21:27:46 -070037LIBPREFIX := @libprefix@
Jason Evansf576c632011-11-01 22:27:41 -070038REV := @rev@
Mike Hommey2d04f5e2012-04-16 16:30:22 +020039install_suffix := @install_suffix@
40ABI := @abi@
41XSLTPROC := @XSLTPROC@
42AUTOCONF := @AUTOCONF@
Mike Hommeyfa08da72012-04-16 16:30:25 +020043_RPATH = @RPATH@
44RPATH = $(if $(1),$(call _RPATH,$(1)))
Mike Hommey2d04f5e2012-04-16 16:30:22 +020045cfghdrs_in := @cfghdrs_in@
46cfghdrs_out := @cfghdrs_out@
47cfgoutputs_in := @cfgoutputs_in@
48cfgoutputs_out := @cfgoutputs_out@
49enable_autogen := @enable_autogen@
Jason Evans748dfac2013-12-06 18:27:33 -080050enable_code_coverage := @enable_code_coverage@
Mike Hommey2d04f5e2012-04-16 16:30:22 +020051enable_experimental := @enable_experimental@
Mike Hommeyd0357f72012-11-26 18:52:41 +010052enable_zone_allocator := @enable_zone_allocator@
Mike Hommeyfa08da72012-04-16 16:30:25 +020053DSO_LDFLAGS = @DSO_LDFLAGS@
Mike Hommey85221d52012-04-18 18:29:40 +020054SOREV = @SOREV@
Mike Hommey188da7c2012-04-18 18:29:41 +020055PIC_CFLAGS = @PIC_CFLAGS@
Mike Hommeyfd97b1d2012-04-30 12:38:31 +020056CTARGET = @CTARGET@
57LDTARGET = @LDTARGET@
58MKLIB = @MKLIB@
Jory A. Prattad505e02013-08-11 09:44:59 -050059AR = @AR@
Jason Evans80ddf492013-08-20 11:48:19 +010060ARFLAGS = @ARFLAGS@
Mike Hommey79c4bca2012-05-02 21:30:51 +020061CC_MM = @CC_MM@
Mike Hommey2d04f5e2012-04-16 16:30:22 +020062
63ifeq (macho, $(ABI))
Mike Hommeya19e87f2012-04-21 21:27:46 -070064TEST_LIBRARY_PATH := DYLD_FALLBACK_LIBRARY_PATH="$(objroot)lib"
65else
66ifeq (pecoff, $(ABI))
67TEST_LIBRARY_PATH := PATH="$(PATH):$(objroot)lib"
Jason Evans2dbecf12010-09-05 10:35:13 -070068else
69TEST_LIBRARY_PATH :=
70endif
Mike Hommeya19e87f2012-04-21 21:27:46 -070071endif
Jason Evansb7924f52009-06-23 19:01:18 -070072
Mike Hommeya19e87f2012-04-21 21:27:46 -070073LIBJEMALLOC := $(LIBPREFIX)jemalloc$(install_suffix)
Mike Hommey5bee66d2012-04-16 16:30:24 +020074
Jason Evansb0fd5012010-01-17 01:49:20 -080075# Lists of files.
Mike Hommey2d04f5e2012-04-16 16:30:22 +020076BINS := $(srcroot)bin/pprof $(objroot)bin/jemalloc.sh
Jason Evans86abd0d2013-11-30 15:25:42 -080077C_HDRS := $(objroot)include/jemalloc/jemalloc$(install_suffix).h
78C_SRCS := $(srcroot)src/jemalloc.c $(srcroot)src/arena.c \
79 $(srcroot)src/atomic.c $(srcroot)src/base.c $(srcroot)src/bitmap.c \
80 $(srcroot)src/chunk.c $(srcroot)src/chunk_dss.c \
81 $(srcroot)src/chunk_mmap.c $(srcroot)src/ckh.c $(srcroot)src/ctl.c \
82 $(srcroot)src/extent.c $(srcroot)src/hash.c $(srcroot)src/huge.c \
83 $(srcroot)src/mb.c $(srcroot)src/mutex.c $(srcroot)src/prof.c \
84 $(srcroot)src/quarantine.c $(srcroot)src/rtree.c $(srcroot)src/stats.c \
85 $(srcroot)src/tcache.c $(srcroot)src/util.c $(srcroot)src/tsd.c
Mike Hommeyd0357f72012-11-26 18:52:41 +010086ifeq ($(enable_zone_allocator), 1)
Jason Evans86abd0d2013-11-30 15:25:42 -080087C_SRCS += $(srcroot)src/zone.c
Jason Evans2dbecf12010-09-05 10:35:13 -070088endif
Mike Hommeyfd97b1d2012-04-30 12:38:31 +020089ifeq ($(IMPORTLIB),$(SO))
Mike Hommey5bee66d2012-04-16 16:30:24 +020090STATIC_LIBS := $(objroot)lib/$(LIBJEMALLOC).$(A)
Mike Hommeyfd97b1d2012-04-30 12:38:31 +020091endif
Mike Hommey188da7c2012-04-18 18:29:41 +020092ifdef PIC_CFLAGS
93STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_pic.$(A)
Mike Hommeyfd97b1d2012-04-30 12:38:31 +020094else
95STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_s.$(A)
Mike Hommey188da7c2012-04-18 18:29:41 +020096endif
97DSOS := $(objroot)lib/$(LIBJEMALLOC).$(SOREV)
Mike Hommey85221d52012-04-18 18:29:40 +020098ifneq ($(SOREV),$(SO))
99DSOS += $(objroot)lib/$(LIBJEMALLOC).$(SO)
100endif
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200101MAN3 := $(objroot)doc/jemalloc$(install_suffix).3
102DOCS_XML := $(objroot)doc/jemalloc$(install_suffix).xml
103DOCS_HTML := $(DOCS_XML:$(objroot)%.xml=$(srcroot)%.html)
104DOCS_MAN3 := $(DOCS_XML:$(objroot)%.xml=$(srcroot)%.3)
Jason Evansaee7fd22010-11-24 22:00:02 -0800105DOCS := $(DOCS_HTML) $(DOCS_MAN3)
Jason Evans0f4f1ef2013-12-12 14:41:02 -0800106C_TESTLIB_SRCS := $(srcroot)test/src/math.c $(srcroot)test/src/mtx.c \
107 $(srcroot)test/src/SFMT.c $(srcroot)test/src/test.c \
108 $(srcroot)test/src/thd.c
Jason Evans86abd0d2013-11-30 15:25:42 -0800109C_UTIL_INTEGRATION_SRCS := $(srcroot)src/util.c
Jason Evans772163b2014-01-17 15:40:52 -0800110TESTS_UNIT := $(srcroot)test/unit/bitmap.c \
111 $(srcroot)test/unit/ckh.c \
112 $(srcroot)test/unit/hash.c \
113 $(srcroot)test/unit/junk.c \
114 $(srcroot)test/unit/mallctl.c \
115 $(srcroot)test/unit/math.c \
116 $(srcroot)test/unit/mq.c \
117 $(srcroot)test/unit/mtx.c \
118 $(srcroot)test/unit/prof_accum.c \
119 $(srcroot)test/unit/prof_gdump.c \
120 $(srcroot)test/unit/prof_idump.c \
121 $(srcroot)test/unit/ql.c \
122 $(srcroot)test/unit/qr.c \
123 $(srcroot)test/unit/quarantine.c \
124 $(srcroot)test/unit/rb.c \
125 $(srcroot)test/unit/rtree.c \
126 $(srcroot)test/unit/SFMT.c \
127 $(srcroot)test/unit/stats.c \
128 $(srcroot)test/unit/tsd.c \
129 $(srcroot)test/unit/util.c \
130 $(srcroot)test/unit/zero.c
Jason Evansad47e892014-02-24 22:00:10 -0800131TESTS_UNIT_AUX := $(srcroot)test/unit/prof_accum_a.c \
132 $(srcroot)test/unit/prof_accum_b.c
Jason Evans86abd0d2013-11-30 15:25:42 -0800133TESTS_INTEGRATION := $(srcroot)test/integration/aligned_alloc.c \
134 $(srcroot)test/integration/allocated.c \
Jason Evansd82a5e62013-12-12 22:35:52 -0800135 $(srcroot)test/integration/mallocx.c \
Jason Evans86abd0d2013-11-30 15:25:42 -0800136 $(srcroot)test/integration/mremap.c \
137 $(srcroot)test/integration/posix_memalign.c \
Jason Evansd82a5e62013-12-12 22:35:52 -0800138 $(srcroot)test/integration/rallocx.c \
Jason Evans86abd0d2013-11-30 15:25:42 -0800139 $(srcroot)test/integration/thread_arena.c \
Jason Evansd82a5e62013-12-12 22:35:52 -0800140 $(srcroot)test/integration/thread_tcache_enabled.c \
141 $(srcroot)test/integration/xallocx.c
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200142ifeq ($(enable_experimental), 1)
Jason Evans86abd0d2013-11-30 15:25:42 -0800143TESTS_INTEGRATION += $(srcroot)test/integration/allocm.c \
Jason Evansd82a5e62013-12-12 22:35:52 -0800144 $(srcroot)test/integration/ALLOCM_ARENA.c \
Jason Evans86abd0d2013-11-30 15:25:42 -0800145 $(srcroot)test/integration/rallocm.c
Jason Evans7e77eaf2012-03-02 17:47:37 -0800146endif
Jason Evans86abd0d2013-11-30 15:25:42 -0800147TESTS_STRESS :=
148TESTS := $(TESTS_UNIT) $(TESTS_INTEGRATION) $(TESTS_STRESS)
Jason Evansb7924f52009-06-23 19:01:18 -0700149
Jason Evans86abd0d2013-11-30 15:25:42 -0800150C_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.$(O))
151C_PIC_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.pic.$(O))
152C_JET_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.jet.$(O))
153C_TESTLIB_UNIT_OBJS := $(C_TESTLIB_SRCS:$(srcroot)%.c=$(objroot)%.unit.$(O))
154C_TESTLIB_INTEGRATION_OBJS := $(C_TESTLIB_SRCS:$(srcroot)%.c=$(objroot)%.integration.$(O))
155C_UTIL_INTEGRATION_OBJS := $(C_UTIL_INTEGRATION_SRCS:$(srcroot)%.c=$(objroot)%.integration.$(O))
156C_TESTLIB_STRESS_OBJS := $(C_TESTLIB_SRCS:$(srcroot)%.c=$(objroot)%.stress.$(O))
157C_TESTLIB_OBJS := $(C_TESTLIB_UNIT_OBJS) $(C_TESTLIB_INTEGRATION_OBJS) $(C_UTIL_INTEGRATION_OBJS) $(C_TESTLIB_STRESS_OBJS)
158
159TESTS_UNIT_OBJS := $(TESTS_UNIT:$(srcroot)%.c=$(objroot)%.$(O))
Jason Evansad47e892014-02-24 22:00:10 -0800160TESTS_UNIT_AUX_OBJS := $(TESTS_UNIT_AUX:$(srcroot)%.c=$(objroot)%.$(O))
Jason Evans86abd0d2013-11-30 15:25:42 -0800161TESTS_INTEGRATION_OBJS := $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%.$(O))
162TESTS_STRESS_OBJS := $(TESTS_STRESS:$(srcroot)%.c=$(objroot)%.$(O))
Jason Evansad47e892014-02-24 22:00:10 -0800163TESTS_OBJS := $(TESTS_UNIT_OBJS) $(TESTS_UNIT_AUX_OBJS) $(TESTS_INTEGRATION_OBJS) $(TESTS_STRESS_OBJS)
Mike Hommey188da7c2012-04-18 18:29:41 +0200164
Jason Evans42ba90e2013-01-22 12:55:42 -0800165.PHONY: all dist build_doc_html build_doc_man build_doc
Jason Evansaee7fd22010-11-24 22:00:02 -0800166.PHONY: install_bin install_include install_lib
Jason Evans42ba90e2013-01-22 12:55:42 -0800167.PHONY: install_doc_html install_doc_man install_doc install
Jason Evansaee7fd22010-11-24 22:00:02 -0800168.PHONY: tests check clean distclean relclean
Jason Evansb7924f52009-06-23 19:01:18 -0700169
Jason Evans86abd0d2013-11-30 15:25:42 -0800170.SECONDARY : $(TESTS_OBJS)
Jason Evans9dcad2d2011-02-13 18:11:54 -0800171
Jason Evansb7924f52009-06-23 19:01:18 -0700172# Default target.
Jason Evans95424fc2013-12-03 22:28:10 -0800173all: build_lib
Jason Evansb7924f52009-06-23 19:01:18 -0700174
Jason Evans7b398ac2012-03-02 16:38:37 -0800175dist: build_doc
Jason Evansaee7fd22010-11-24 22:00:02 -0800176
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200177$(srcroot)doc/%.html : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/html.xsl
178 $(XSLTPROC) -o $@ $(objroot)doc/html.xsl $<
Jason Evansaee7fd22010-11-24 22:00:02 -0800179
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200180$(srcroot)doc/%.3 : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/manpages.xsl
181 $(XSLTPROC) -o $@ $(objroot)doc/manpages.xsl $<
Jason Evansaee7fd22010-11-24 22:00:02 -0800182
Jason Evans7b398ac2012-03-02 16:38:37 -0800183build_doc_html: $(DOCS_HTML)
184build_doc_man: $(DOCS_MAN3)
185build_doc: $(DOCS)
Jason Evansaee7fd22010-11-24 22:00:02 -0800186
Jason Evanse476f8a2010-01-16 09:53:50 -0800187#
188# Include generated dependency files.
189#
Mike Hommey79c4bca2012-05-02 21:30:51 +0200190ifdef CC_MM
Jason Evans86abd0d2013-11-30 15:25:42 -0800191-include $(C_OBJS:%.$(O)=%.d)
192-include $(C_PIC_OBJS:%.$(O)=%.d)
193-include $(C_JET_OBJS:%.$(O)=%.d)
Jason Evansb1941c62013-12-09 23:36:37 -0800194-include $(C_TESTLIB_OBJS:%.$(O)=%.d)
Jason Evans86abd0d2013-11-30 15:25:42 -0800195-include $(TESTS_OBJS:%.$(O)=%.d)
Mike Hommey79c4bca2012-05-02 21:30:51 +0200196endif
Jason Evanse476f8a2010-01-16 09:53:50 -0800197
Jason Evans86abd0d2013-11-30 15:25:42 -0800198$(C_OBJS): $(objroot)src/%.$(O): $(srcroot)src/%.c
199$(C_PIC_OBJS): $(objroot)src/%.pic.$(O): $(srcroot)src/%.c
200$(C_PIC_OBJS): CFLAGS += $(PIC_CFLAGS)
201$(C_JET_OBJS): $(objroot)src/%.jet.$(O): $(srcroot)src/%.c
202$(C_JET_OBJS): CFLAGS += -DJEMALLOC_JET
203$(C_TESTLIB_UNIT_OBJS): $(objroot)test/src/%.unit.$(O): $(srcroot)test/src/%.c
204$(C_TESTLIB_UNIT_OBJS): CPPFLAGS += -DJEMALLOC_UNIT_TEST
205$(C_TESTLIB_INTEGRATION_OBJS): $(objroot)test/src/%.integration.$(O): $(srcroot)test/src/%.c
206$(C_TESTLIB_INTEGRATION_OBJS): CPPFLAGS += -DJEMALLOC_INTEGRATION_TEST
207$(C_UTIL_INTEGRATION_OBJS): $(objroot)src/%.integration.$(O): $(srcroot)src/%.c
208$(C_TESTLIB_STRESS_OBJS): $(objroot)test/src/%.stress.$(O): $(srcroot)test/src/%.c
Jason Evansf234dc52014-01-16 17:38:01 -0800209$(C_TESTLIB_STRESS_OBJS): CPPFLAGS += -DJEMALLOC_STRESS_TEST -DJEMALLOC_STRESS_TESTLIB
Jason Evans2a83ed02013-12-08 20:52:21 -0800210$(C_TESTLIB_OBJS): CPPFLAGS += -I$(srcroot)test/include -I$(objroot)test/include
Jason Evans86abd0d2013-11-30 15:25:42 -0800211$(TESTS_UNIT_OBJS): CPPFLAGS += -DJEMALLOC_UNIT_TEST
Jason Evansad47e892014-02-24 22:00:10 -0800212$(TESTS_UNIT_AUX_OBJS): CPPFLAGS += -DJEMALLOC_UNIT_TEST
213define make-unit-link-dep
214$(1): TESTS_UNIT_LINK_OBJS += $(2)
215$(1): $(2)
216endef
217$(foreach test, $(TESTS_UNIT:$(srcroot)test/unit/%.c=$(objroot)test/unit/%$(EXE)), $(eval $(call make-unit-link-dep,$(test),$(filter $(test:%=%_a.$(O)) $(test:%=%_b.$(O)),$(TESTS_UNIT_AUX_OBJS)))))
Jason Evans86abd0d2013-11-30 15:25:42 -0800218$(TESTS_INTEGRATION_OBJS): CPPFLAGS += -DJEMALLOC_INTEGRATION_TEST
219$(TESTS_STRESS_OBJS): CPPFLAGS += -DJEMALLOC_STRESS_TEST
220$(TESTS_OBJS): $(objroot)test/%.$(O): $(srcroot)test/%.c
Jason Evans2a83ed02013-12-08 20:52:21 -0800221$(TESTS_OBJS): CPPFLAGS += -I$(srcroot)test/include -I$(objroot)test/include
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200222ifneq ($(IMPORTLIB),$(SO))
Jason Evans86abd0d2013-11-30 15:25:42 -0800223$(C_OBJS): CPPFLAGS += -DDLLEXPORT
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200224endif
Mike Hommey188da7c2012-04-18 18:29:41 +0200225
Mike Hommey79c4bca2012-05-02 21:30:51 +0200226ifndef CC_MM
Jason Evans86abd0d2013-11-30 15:25:42 -0800227# Dependencies.
Mike Hommey79c4bca2012-05-02 21:30:51 +0200228HEADER_DIRS = $(srcroot)include/jemalloc/internal \
229 $(objroot)include/jemalloc $(objroot)include/jemalloc/internal
230HEADERS = $(wildcard $(foreach dir,$(HEADER_DIRS),$(dir)/*.h))
Jason Evans86abd0d2013-11-30 15:25:42 -0800231$(C_OBJS) $(C_PIC_OBJS) $(C_JET_OBJS) $(C_TESTLIB_OBJS) $(TESTS_OBJS): $(HEADERS)
232$(TESTS_OBJS): $(objroot)test/unit/jemalloc_test.h
Mike Hommey79c4bca2012-05-02 21:30:51 +0200233endif
234
Jason Evans86abd0d2013-11-30 15:25:42 -0800235$(C_OBJS) $(C_PIC_OBJS) $(C_JET_OBJS) $(C_TESTLIB_OBJS) $(TESTS_OBJS): %.$(O):
Jason Evans376b1522010-02-11 14:45:59 -0800236 @mkdir -p $(@D)
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200237 $(CC) $(CFLAGS) -c $(CPPFLAGS) $(CTARGET) $<
Mike Hommey79c4bca2012-05-02 21:30:51 +0200238ifdef CC_MM
Mike Hommey5bee66d2012-04-16 16:30:24 +0200239 @$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $<
Mike Hommey79c4bca2012-05-02 21:30:51 +0200240endif
Jason Evansb7924f52009-06-23 19:01:18 -0700241
Mike Hommey85221d52012-04-18 18:29:40 +0200242ifneq ($(SOREV),$(SO))
243%.$(SO) : %.$(SOREV)
Jason Evansb7924f52009-06-23 19:01:18 -0700244 @mkdir -p $(@D)
Jason Evans0656ec02010-04-07 23:37:35 -0700245 ln -sf $(<F) $@
Mike Hommey85221d52012-04-18 18:29:40 +0200246endif
Jason Evans0656ec02010-04-07 23:37:35 -0700247
Jason Evans86abd0d2013-11-30 15:25:42 -0800248$(objroot)lib/$(LIBJEMALLOC).$(SOREV) : $(if $(PIC_CFLAGS),$(C_PIC_OBJS),$(C_OBJS))
Jason Evans0656ec02010-04-07 23:37:35 -0700249 @mkdir -p $(@D)
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200250 $(CC) $(DSO_LDFLAGS) $(call RPATH,$(RPATH_EXTRA)) $(LDTARGET) $+ $(LDFLAGS) $(LIBS) $(EXTRA_LDFLAGS)
Jason Evans0656ec02010-04-07 23:37:35 -0700251
Jason Evans86abd0d2013-11-30 15:25:42 -0800252$(objroot)lib/$(LIBJEMALLOC)_pic.$(A) : $(C_PIC_OBJS)
253$(objroot)lib/$(LIBJEMALLOC).$(A) : $(C_OBJS)
254$(objroot)lib/$(LIBJEMALLOC)_s.$(A) : $(C_OBJS)
Mike Hommey188da7c2012-04-18 18:29:41 +0200255
256$(STATIC_LIBS):
Arun Sharmaaf5d6982011-02-15 14:13:38 -0800257 @mkdir -p $(@D)
Jason Evans80ddf492013-08-20 11:48:19 +0100258 $(AR) $(ARFLAGS)@AROUT@ $+
Arun Sharmaaf5d6982011-02-15 14:13:38 -0800259
Jason Evansad47e892014-02-24 22:00:10 -0800260$(objroot)test/unit/%$(EXE): $(objroot)test/unit/%.$(O) $(TESTS_UNIT_LINK_OBJS) $(C_JET_OBJS) $(C_TESTLIB_UNIT_OBJS)
Jason Evans86abd0d2013-11-30 15:25:42 -0800261 @mkdir -p $(@D)
Jason Evansb1941c62013-12-09 23:36:37 -0800262 $(CC) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(LDFLAGS) $(filter-out -lm,$(LIBS)) -lm $(EXTRA_LDFLAGS)
Mike Hommey45f208e2012-04-16 16:30:26 +0200263
Jason Evans86abd0d2013-11-30 15:25:42 -0800264$(objroot)test/integration/%$(EXE): $(objroot)test/integration/%.$(O) $(C_TESTLIB_INTEGRATION_OBJS) $(C_UTIL_INTEGRATION_OBJS) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB)
265 @mkdir -p $(@D)
Jason Evansb1941c62013-12-09 23:36:37 -0800266 $(CC) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB) $(LDFLAGS) $(filter-out -lm,$(filter -lpthread,$(LIBS))) -lm $(EXTRA_LDFLAGS)
Jason Evans86abd0d2013-11-30 15:25:42 -0800267
268$(objroot)test/stress/%$(EXE): $(objroot)test/stress/%.$(O) $(C_JET_OBJS) $(C_TESTLIB_STRESS_OBJS) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB)
Jason Evansb267d0f2010-08-13 15:42:29 -0700269 @mkdir -p $(@D)
Jason Evansb1941c62013-12-09 23:36:37 -0800270 $(CC) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB) $(LDFLAGS) $(filter-out -lm,$(LIBS)) -lm $(EXTRA_LDFLAGS)
Jason Evansb267d0f2010-08-13 15:42:29 -0700271
Jason Evans7b398ac2012-03-02 16:38:37 -0800272build_lib_shared: $(DSOS)
273build_lib_static: $(STATIC_LIBS)
Jason Evans95424fc2013-12-03 22:28:10 -0800274build_lib: build_lib_shared build_lib_static
Jason Evans7b398ac2012-03-02 16:38:37 -0800275
Jason Evansa91f2102010-04-02 13:50:53 -0700276install_bin:
277 install -d $(BINDIR)
278 @for b in $(BINS); do \
279 echo "install -m 755 $$b $(BINDIR)"; \
280 install -m 755 $$b $(BINDIR); \
281done
282
Jason Evanscfeccd32010-03-03 15:48:20 -0800283install_include:
Jason Evans376b1522010-02-11 14:45:59 -0800284 install -d $(INCLUDEDIR)/jemalloc
Jason Evans86abd0d2013-11-30 15:25:42 -0800285 @for h in $(C_HDRS); do \
Jason Evans376b1522010-02-11 14:45:59 -0800286 echo "install -m 644 $$h $(INCLUDEDIR)/jemalloc"; \
287 install -m 644 $$h $(INCLUDEDIR)/jemalloc; \
Jason Evansb7924f52009-06-23 19:01:18 -0700288done
Jason Evanscfeccd32010-03-03 15:48:20 -0800289
Jason Evans7b398ac2012-03-02 16:38:37 -0800290install_lib_shared: $(DSOS)
Jason Evansb7924f52009-06-23 19:01:18 -0700291 install -d $(LIBDIR)
Mike Hommey85221d52012-04-18 18:29:40 +0200292 install -m 755 $(objroot)lib/$(LIBJEMALLOC).$(SOREV) $(LIBDIR)
293ifneq ($(SOREV),$(SO))
294 ln -sf $(LIBJEMALLOC).$(SOREV) $(LIBDIR)/$(LIBJEMALLOC).$(SO)
295endif
Jason Evans7b398ac2012-03-02 16:38:37 -0800296
Mike Hommey188da7c2012-04-18 18:29:41 +0200297install_lib_static: $(STATIC_LIBS)
Jason Evans7b398ac2012-03-02 16:38:37 -0800298 install -d $(LIBDIR)
Mike Hommey188da7c2012-04-18 18:29:41 +0200299 @for l in $(STATIC_LIBS); do \
300 echo "install -m 755 $$l $(LIBDIR)"; \
301 install -m 755 $$l $(LIBDIR); \
302done
Jason Evanscfeccd32010-03-03 15:48:20 -0800303
Jason Evans7b398ac2012-03-02 16:38:37 -0800304install_lib: install_lib_shared install_lib_static
305
306install_doc_html:
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200307 install -d $(DATADIR)/doc/jemalloc$(install_suffix)
Jason Evansaee7fd22010-11-24 22:00:02 -0800308 @for d in $(DOCS_HTML); do \
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200309 echo "install -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix)"; \
310 install -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix); \
Jason Evansb7924f52009-06-23 19:01:18 -0700311done
312
Jason Evans7b398ac2012-03-02 16:38:37 -0800313install_doc_man:
Jason Evansaee7fd22010-11-24 22:00:02 -0800314 install -d $(MANDIR)/man3
315 @for d in $(DOCS_MAN3); do \
316 echo "install -m 644 $$d $(MANDIR)/man3"; \
317 install -m 644 $$d $(MANDIR)/man3; \
318done
319
Jason Evans7b398ac2012-03-02 16:38:37 -0800320install_doc: install_doc_html install_doc_man
Jason Evansaee7fd22010-11-24 22:00:02 -0800321
322install: install_bin install_include install_lib install_doc
Jason Evanscfeccd32010-03-03 15:48:20 -0800323
Jason Evans86abd0d2013-11-30 15:25:42 -0800324tests_unit: $(TESTS_UNIT:$(srcroot)%.c=$(objroot)%$(EXE))
325tests_integration: $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%$(EXE))
326tests_stress: $(TESTS_STRESS:$(srcroot)%.c=$(objroot)%$(EXE))
327tests: tests_unit tests_integration tests_stress
Jason Evansb267d0f2010-08-13 15:42:29 -0700328
Jason Evans86abd0d2013-11-30 15:25:42 -0800329check_unit_dir:
330 @mkdir -p $(objroot)test/unit
331check_integration_dir:
332 @mkdir -p $(objroot)test/integration
333check_stress_dir:
334 @mkdir -p $(objroot)test/stress
335check_dir: check_unit_dir check_integration_dir check_stress_dir
336
337check_unit: tests_unit check_unit_dir
Jason Evans748dfac2013-12-06 18:27:33 -0800338 $(SHELL) $(objroot)test/test.sh $(TESTS_UNIT:$(srcroot)%.c=$(objroot)%)
Jason Evans86abd0d2013-11-30 15:25:42 -0800339check_integration: tests_integration check_integration_dir
Jason Evans748dfac2013-12-06 18:27:33 -0800340 $(SHELL) $(objroot)test/test.sh $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%)
Jason Evans86abd0d2013-11-30 15:25:42 -0800341check_stress: tests_stress check_stress_dir
Jason Evans748dfac2013-12-06 18:27:33 -0800342 $(SHELL) $(objroot)test/test.sh $(TESTS_STRESS:$(srcroot)%.c=$(objroot)%)
Jason Evans86abd0d2013-11-30 15:25:42 -0800343check: tests check_dir
Jason Evans748dfac2013-12-06 18:27:33 -0800344 $(SHELL) $(objroot)test/test.sh $(TESTS:$(srcroot)%.c=$(objroot)%)
345
346ifeq ($(enable_code_coverage), 1)
347coverage_unit: check_unit
348 $(SHELL) $(srcroot)coverage.sh $(srcroot)src jet $(C_JET_OBJS)
349 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/src unit $(C_TESTLIB_UNIT_OBJS)
350 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/unit unit $(TESTS_UNIT_OBJS)
351
352coverage_integration: check_integration
353 $(SHELL) $(srcroot)coverage.sh $(srcroot)src pic $(C_PIC_OBJS)
354 $(SHELL) $(srcroot)coverage.sh $(srcroot)src integration $(C_UTIL_INTEGRATION_OBJS)
355 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/src integration $(C_TESTLIB_INTEGRATION_OBJS)
356 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/integration integration $(TESTS_INTEGRATION_OBJS)
357
358coverage_stress: check_stress
359 $(SHELL) $(srcroot)coverage.sh $(srcroot)src pic $(C_PIC_OBJS)
360 $(SHELL) $(srcroot)coverage.sh $(srcroot)src jet $(C_JET_OBJS)
361 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/src stress $(C_TESTLIB_STRESS_OBJS)
362 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/stress stress $(TESTS_STRESS_OBJS)
363
364coverage: check
365 $(SHELL) $(srcroot)coverage.sh $(srcroot)src pic $(C_PIC_OBJS)
366 $(SHELL) $(srcroot)coverage.sh $(srcroot)src jet $(C_JET_OBJS)
367 $(SHELL) $(srcroot)coverage.sh $(srcroot)src integration $(C_UTIL_INTEGRATION_OBJS)
368 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/src unit $(C_TESTLIB_UNIT_OBJS)
369 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/src integration $(C_TESTLIB_INTEGRATION_OBJS)
370 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/src stress $(C_TESTLIB_STRESS_OBJS)
Jason Evansad47e892014-02-24 22:00:10 -0800371 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/unit unit $(TESTS_UNIT_OBJS) $(TESTS_UNIT_AUX_OBJS)
Jason Evans748dfac2013-12-06 18:27:33 -0800372 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/integration integration $(TESTS_INTEGRATION_OBJS)
373 $(SHELL) $(srcroot)coverage.sh $(srcroot)test/stress integration $(TESTS_STRESS_OBJS)
374endif
Jason Evansb7924f52009-06-23 19:01:18 -0700375
376clean:
Jason Evans86abd0d2013-11-30 15:25:42 -0800377 rm -f $(C_OBJS)
378 rm -f $(C_PIC_OBJS)
379 rm -f $(C_JET_OBJS)
380 rm -f $(C_TESTLIB_OBJS)
381 rm -f $(C_OBJS:%.$(O)=%.d)
Jason Evans748dfac2013-12-06 18:27:33 -0800382 rm -f $(C_OBJS:%.$(O)=%.gcda)
383 rm -f $(C_OBJS:%.$(O)=%.gcno)
Jason Evans86abd0d2013-11-30 15:25:42 -0800384 rm -f $(C_PIC_OBJS:%.$(O)=%.d)
Jason Evans748dfac2013-12-06 18:27:33 -0800385 rm -f $(C_PIC_OBJS:%.$(O)=%.gcda)
386 rm -f $(C_PIC_OBJS:%.$(O)=%.gcno)
Jason Evans86abd0d2013-11-30 15:25:42 -0800387 rm -f $(C_JET_OBJS:%.$(O)=%.d)
Jason Evans748dfac2013-12-06 18:27:33 -0800388 rm -f $(C_JET_OBJS:%.$(O)=%.gcda)
389 rm -f $(C_JET_OBJS:%.$(O)=%.gcno)
Jason Evans86abd0d2013-11-30 15:25:42 -0800390 rm -f $(C_TESTLIB_OBJS:%.$(O)=%.d)
Jason Evans748dfac2013-12-06 18:27:33 -0800391 rm -f $(C_TESTLIB_OBJS:%.$(O)=%.gcda)
392 rm -f $(C_TESTLIB_OBJS:%.$(O)=%.gcno)
Jason Evans86abd0d2013-11-30 15:25:42 -0800393 rm -f $(TESTS_OBJS:%.$(O)=%$(EXE))
394 rm -f $(TESTS_OBJS)
395 rm -f $(TESTS_OBJS:%.$(O)=%.d)
Jason Evans748dfac2013-12-06 18:27:33 -0800396 rm -f $(TESTS_OBJS:%.$(O)=%.gcda)
397 rm -f $(TESTS_OBJS:%.$(O)=%.gcno)
Jason Evans86abd0d2013-11-30 15:25:42 -0800398 rm -f $(TESTS_OBJS:%.$(O)=%.out)
Arun Sharmaaf5d6982011-02-15 14:13:38 -0800399 rm -f $(DSOS) $(STATIC_LIBS)
Jason Evans748dfac2013-12-06 18:27:33 -0800400 rm -f $(objroot)*.gcov.*
Jason Evansb7924f52009-06-23 19:01:18 -0700401
402distclean: clean
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200403 rm -rf $(objroot)autom4te.cache
Jason Evans86abd0d2013-11-30 15:25:42 -0800404 rm -f $(objroot)bin/jemalloc.sh
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200405 rm -f $(objroot)config.log
406 rm -f $(objroot)config.status
407 rm -f $(objroot)config.stamp
408 rm -f $(cfghdrs_out)
409 rm -f $(cfgoutputs_out)
Jason Evansb7924f52009-06-23 19:01:18 -0700410
411relclean: distclean
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200412 rm -f $(objroot)configure
413 rm -f $(srcroot)VERSION
Jason Evansaee7fd22010-11-24 22:00:02 -0800414 rm -f $(DOCS_HTML)
415 rm -f $(DOCS_MAN3)
Jason Evansb7924f52009-06-23 19:01:18 -0700416
417#===============================================================================
418# Re-configuration rules.
419
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200420ifeq ($(enable_autogen), 1)
421$(srcroot)configure : $(srcroot)configure.ac
422 cd ./$(srcroot) && $(AUTOCONF)
Jason Evansb7924f52009-06-23 19:01:18 -0700423
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200424$(objroot)config.status : $(srcroot)configure
425 ./$(objroot)config.status --recheck
Jason Evansb7924f52009-06-23 19:01:18 -0700426
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200427$(srcroot)config.stamp.in : $(srcroot)configure.ac
428 echo stamp > $(srcroot)config.stamp.in
Jason Evansb7924f52009-06-23 19:01:18 -0700429
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200430$(objroot)config.stamp : $(cfgoutputs_in) $(cfghdrs_in) $(srcroot)configure
431 ./$(objroot)config.status
Jason Evansb7924f52009-06-23 19:01:18 -0700432 @touch $@
433
434# There must be some action in order for make to re-read Makefile when it is
435# out of date.
Mike Hommey2d04f5e2012-04-16 16:30:22 +0200436$(cfgoutputs_out) $(cfghdrs_out) : $(objroot)config.stamp
Jason Evansb7924f52009-06-23 19:01:18 -0700437 @true
438endif