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