Makefile.in 9.1 KB

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