Use make variables instead of preprocessing

This commit is contained in:
Mike Hommey 2012-04-16 16:30:22 +02:00 committed by Jason Evans
parent 6f2ed70f5a
commit 2d04f5e5ff

View File

@ -17,9 +17,13 @@ INCLUDEDIR := $(DESTDIR)@INCLUDEDIR@
LIBDIR := $(DESTDIR)@LIBDIR@ LIBDIR := $(DESTDIR)@LIBDIR@
DATADIR := $(DESTDIR)@DATADIR@ DATADIR := $(DESTDIR)@DATADIR@
MANDIR := $(DESTDIR)@MANDIR@ MANDIR := $(DESTDIR)@MANDIR@
srcroot := @srcroot@
objroot := @objroot@
abs_srcroot := @abs_srcroot@
abs_objroot := @abs_objroot@
# Build parameters. # Build parameters.
CPPFLAGS := @CPPFLAGS@ -I@srcroot@include -I@objroot@include CPPFLAGS := @CPPFLAGS@ -I$(srcroot)include -I$(objroot)include
CFLAGS := @CFLAGS@ CFLAGS := @CFLAGS@
LDFLAGS := @LDFLAGS@ LDFLAGS := @LDFLAGS@
LIBS := @LIBS@ LIBS := @LIBS@
@ -31,42 +35,54 @@ else
WL_SONAME := soname WL_SONAME := soname
endif endif
REV := @rev@ REV := @rev@
ifeq (macho, @abi@) install_suffix := @install_suffix@
TEST_LIBRARY_PATH := DYLD_FALLBACK_LIBRARY_PATH=@objroot@lib ABI := @abi@
XSLTPROC := @XSLTPROC@
AUTOCONF := @AUTOCONF@
RPATH := @RPATH@
cfghdrs_in := @cfghdrs_in@
cfghdrs_out := @cfghdrs_out@
cfgoutputs_in := @cfgoutputs_in@
cfgoutputs_out := @cfgoutputs_out@
enable_autogen := @enable_autogen@
enable_experimental := @enable_experimental@
ifeq (macho, $(ABI))
TEST_LIBRARY_PATH := DYLD_FALLBACK_LIBRARY_PATH=$(objroot)lib
else else
TEST_LIBRARY_PATH := TEST_LIBRARY_PATH :=
endif endif
# Lists of files. # Lists of files.
BINS := @srcroot@bin/pprof @objroot@bin/jemalloc.sh BINS := $(srcroot)bin/pprof $(objroot)bin/jemalloc.sh
CHDRS := @objroot@include/jemalloc/jemalloc@install_suffix@.h \ CHDRS := $(objroot)include/jemalloc/jemalloc$(install_suffix).h \
@objroot@include/jemalloc/jemalloc_defs@install_suffix@.h $(objroot)include/jemalloc/jemalloc_defs$(install_suffix).h
CSRCS := @srcroot@src/jemalloc.c @srcroot@src/arena.c @srcroot@src/atomic.c \ CSRCS := $(srcroot)src/jemalloc.c $(srcroot)src/arena.c $(srcroot)src/atomic.c \
@srcroot@src/base.c @srcroot@src/bitmap.c @srcroot@src/chunk.c \ $(srcroot)src/base.c $(srcroot)src/bitmap.c $(srcroot)src/chunk.c \
@srcroot@src/chunk_dss.c @srcroot@src/chunk_mmap.c \ $(srcroot)src/chunk_dss.c $(srcroot)src/chunk_mmap.c \
@srcroot@src/ckh.c @srcroot@src/ctl.c @srcroot@src/extent.c \ $(srcroot)src/ckh.c $(srcroot)src/ctl.c $(srcroot)src/extent.c \
@srcroot@src/hash.c @srcroot@src/huge.c @srcroot@src/mb.c \ $(srcroot)src/hash.c $(srcroot)src/huge.c $(srcroot)src/mb.c \
@srcroot@src/mutex.c @srcroot@src/prof.c @srcroot@src/quarantine.c \ $(srcroot)src/mutex.c $(srcroot)src/prof.c $(srcroot)src/quarantine.c \
@srcroot@src/rtree.c @srcroot@src/stats.c @srcroot@src/tcache.c \ $(srcroot)src/rtree.c $(srcroot)src/stats.c $(srcroot)src/tcache.c \
@srcroot@src/util.c @srcroot@src/tsd.c $(srcroot)src/util.c $(srcroot)src/tsd.c
ifeq (macho, @abi@) ifeq (macho, $(ABI))
CSRCS += @srcroot@src/zone.c CSRCS += $(srcroot)src/zone.c
endif endif
STATIC_LIBS := @objroot@lib/libjemalloc@install_suffix@.a STATIC_LIBS := $(objroot)lib/libjemalloc$(install_suffix).a
DSOS := @objroot@lib/libjemalloc@install_suffix@.$(SO).$(REV) \ DSOS := $(objroot)lib/libjemalloc$(install_suffix).$(SO).$(REV) \
@objroot@lib/libjemalloc@install_suffix@.$(SO) \ $(objroot)lib/libjemalloc$(install_suffix).$(SO) \
@objroot@lib/libjemalloc@install_suffix@_pic.a $(objroot)lib/libjemalloc$(install_suffix)_pic.a
MAN3 := @objroot@doc/jemalloc@install_suffix@.3 MAN3 := $(objroot)doc/jemalloc$(install_suffix).3
DOCS_XML := @objroot@doc/jemalloc@install_suffix@.xml DOCS_XML := $(objroot)doc/jemalloc$(install_suffix).xml
DOCS_HTML := $(DOCS_XML:@objroot@%.xml=@srcroot@%.html) DOCS_HTML := $(DOCS_XML:$(objroot)%.xml=$(srcroot)%.html)
DOCS_MAN3 := $(DOCS_XML:@objroot@%.xml=@srcroot@%.3) DOCS_MAN3 := $(DOCS_XML:$(objroot)%.xml=$(srcroot)%.3)
DOCS := $(DOCS_HTML) $(DOCS_MAN3) DOCS := $(DOCS_HTML) $(DOCS_MAN3)
CTESTS := @srcroot@test/aligned_alloc.c @srcroot@test/allocated.c \ CTESTS := $(srcroot)test/aligned_alloc.c $(srcroot)test/allocated.c \
@srcroot@test/bitmap.c @srcroot@test/mremap.c \ $(srcroot)test/bitmap.c $(srcroot)test/mremap.c \
@srcroot@test/posix_memalign.c @srcroot@test/thread_arena.c \ $(srcroot)test/posix_memalign.c $(srcroot)test/thread_arena.c \
@srcroot@test/thread_tcache_enabled.c $(srcroot)test/thread_tcache_enabled.c
ifeq (@enable_experimental@, 1) ifeq ($(enable_experimental), 1)
CTESTS += @srcroot@test/allocm.c @srcroot@test/rallocm.c CTESTS += $(srcroot)test/allocm.c $(srcroot)test/rallocm.c
endif endif
.PHONY: all dist doc_html doc_man doc .PHONY: all dist doc_html doc_man doc
@ -74,18 +90,18 @@ endif
.PHONY: install_html install_man install_doc install .PHONY: install_html install_man install_doc install
.PHONY: tests check clean distclean relclean .PHONY: tests check clean distclean relclean
.SECONDARY : $(CTESTS:@srcroot@%.c=@objroot@%.o) .SECONDARY : $(CTESTS:$(srcroot)%.c=$(objroot)%.o)
# Default target. # Default target.
all: build all: build
dist: build_doc dist: build_doc
@srcroot@doc/%.html : @objroot@doc/%.xml @srcroot@doc/stylesheet.xsl @objroot@doc/html.xsl $(srcroot)doc/%.html : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/html.xsl
@XSLTPROC@ -o $@ @objroot@doc/html.xsl $< $(XSLTPROC) -o $@ $(objroot)doc/html.xsl $<
@srcroot@doc/%.3 : @objroot@doc/%.xml @srcroot@doc/stylesheet.xsl @objroot@doc/manpages.xsl $(srcroot)doc/%.3 : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/manpages.xsl
@XSLTPROC@ -o $@ @objroot@doc/manpages.xsl $< $(XSLTPROC) -o $@ $(objroot)doc/manpages.xsl $<
build_doc_html: $(DOCS_HTML) build_doc_html: $(DOCS_HTML)
build_doc_man: $(DOCS_MAN3) build_doc_man: $(DOCS_MAN3)
@ -94,16 +110,16 @@ build_doc: $(DOCS)
# #
# Include generated dependency files. # Include generated dependency files.
# #
-include $(CSRCS:@srcroot@%.c=@objroot@%.d) -include $(CSRCS:$(srcroot)%.c=$(objroot)%.d)
-include $(CSRCS:@srcroot@%.c=@objroot@%.pic.d) -include $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.d)
-include $(CTESTS:@srcroot@%.c=@objroot@%.d) -include $(CTESTS:$(srcroot)%.c=$(objroot)%.d)
@objroot@src/%.o: @srcroot@src/%.c $(objroot)src/%.o: $(srcroot)src/%.c
@mkdir -p $(@D) @mkdir -p $(@D)
$(CC) $(CFLAGS) -c $(CPPFLAGS) -o $@ $< $(CC) $(CFLAGS) -c $(CPPFLAGS) -o $@ $<
@$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.o=%.d) $< @$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.o=%.d) $<
@objroot@src/%.pic.o: @srcroot@src/%.c $(objroot)src/%.pic.o: $(srcroot)src/%.c
@mkdir -p $(@D) @mkdir -p $(@D)
$(CC) $(CFLAGS) -fPIC -DPIC -c $(CPPFLAGS) -o $@ $< $(CC) $(CFLAGS) -fPIC -DPIC -c $(CPPFLAGS) -o $@ $<
@$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.o=%.d) $< @$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.o=%.d) $<
@ -112,30 +128,30 @@ build_doc: $(DOCS)
@mkdir -p $(@D) @mkdir -p $(@D)
ln -sf $(<F) $@ ln -sf $(<F) $@
@objroot@lib/libjemalloc@install_suffix@.$(SO).$(REV) : $(CSRCS:@srcroot@%.c=@objroot@%.pic.o) $(objroot)lib/libjemalloc$(install_suffix).$(SO).$(REV) : $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.o)
@mkdir -p $(@D) @mkdir -p $(@D)
$(CC) -shared -Wl,-$(WL_SONAME),$(@F) $(RPATH_EXTRA:%=@RPATH@%) -o $@ $+ $(LDFLAGS) $(LIBS) $(CC) -shared -Wl,-$(WL_SONAME),$(@F) $(RPATH_EXTRA:%=$(RPATH)%) -o $@ $+ $(LDFLAGS) $(LIBS)
@objroot@lib/libjemalloc@install_suffix@_pic.a : $(CSRCS:@srcroot@%.c=@objroot@%.pic.o) $(objroot)lib/libjemalloc$(install_suffix)_pic.a : $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.o)
@mkdir -p $(@D) @mkdir -p $(@D)
ar crus $@ $+ ar crus $@ $+
@objroot@lib/libjemalloc@install_suffix@.a : $(CSRCS:@srcroot@%.c=@objroot@%.o) $(objroot)lib/libjemalloc$(install_suffix).a : $(CSRCS:$(srcroot)%.c=$(objroot)%.o)
@mkdir -p $(@D) @mkdir -p $(@D)
ar crus $@ $+ ar crus $@ $+
@objroot@test/%.o: @srcroot@test/%.c $(objroot)test/%.o: $(srcroot)test/%.c
@mkdir -p $(@D) @mkdir -p $(@D)
$(CC) $(CFLAGS) -c $(CPPFLAGS) -I@objroot@test -o $@ $< $(CC) $(CFLAGS) -c $(CPPFLAGS) -I$(objroot)test -o $@ $<
@$(CC) -MM $(CPPFLAGS) -I@objroot@test -MT $@ -o $(@:%.o=%.d) $< @$(CC) -MM $(CPPFLAGS) -I$(objroot)test -MT $@ -o $(@:%.o=%.d) $<
@objroot@test/%: @objroot@test/%.o \ $(objroot)test/%: $(objroot)test/%.o \
@objroot@lib/libjemalloc@install_suffix@.$(SO) $(objroot)lib/libjemalloc$(install_suffix).$(SO)
@mkdir -p $(@D) @mkdir -p $(@D)
ifneq (@RPATH@, ) ifneq ($(RPATH), )
$(CC) -o $@ $< @RPATH@@objroot@lib -L@objroot@lib -ljemalloc@install_suffix@ $(LIBS) $(CC) -o $@ $< $(RPATH)$(objroot)lib -L$(objroot)lib -ljemalloc$(install_suffix) $(LIBS)
else else
$(CC) -o $@ $< -L@objroot@lib -ljemalloc@install_suffix@ $(LIBS) $(CC) -o $@ $< -L$(objroot)lib -ljemalloc$(install_suffix) $(LIBS)
endif endif
build_lib_shared: $(DSOS) build_lib_shared: $(DSOS)
@ -158,21 +174,21 @@ done
install_lib_shared: $(DSOS) install_lib_shared: $(DSOS)
install -d $(LIBDIR) install -d $(LIBDIR)
install -m 755 @objroot@lib/libjemalloc@install_suffix@.$(SO).$(REV) $(LIBDIR) install -m 755 $(objroot)lib/libjemalloc$(install_suffix).$(SO).$(REV) $(LIBDIR)
ln -sf libjemalloc@install_suffix@.$(SO).$(REV) $(LIBDIR)/libjemalloc@install_suffix@.$(SO) ln -sf libjemalloc$(install_suffix).$(SO).$(REV) $(LIBDIR)/libjemalloc$(install_suffix).$(SO)
install_lib_static: $(DSOS) $(STATIC_LIBS) install_lib_static: $(DSOS) $(STATIC_LIBS)
install -d $(LIBDIR) install -d $(LIBDIR)
install -m 755 @objroot@lib/libjemalloc@install_suffix@_pic.a $(LIBDIR) install -m 755 $(objroot)lib/libjemalloc$(install_suffix)_pic.a $(LIBDIR)
install -m 755 @objroot@lib/libjemalloc@install_suffix@.a $(LIBDIR) install -m 755 $(objroot)lib/libjemalloc$(install_suffix).a $(LIBDIR)
install_lib: install_lib_shared install_lib_static install_lib: install_lib_shared install_lib_static
install_doc_html: install_doc_html:
install -d $(DATADIR)/doc/jemalloc@install_suffix@ install -d $(DATADIR)/doc/jemalloc$(install_suffix)
@for d in $(DOCS_HTML); do \ @for d in $(DOCS_HTML); do \
echo "install -m 644 $$d $(DATADIR)/doc/jemalloc@install_suffix@"; \ echo "install -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix)"; \
install -m 644 $$d $(DATADIR)/doc/jemalloc@install_suffix@; \ install -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix); \
done done
install_doc_man: install_doc_man:
@ -186,21 +202,21 @@ install_doc: install_doc_html install_doc_man
install: install_bin install_include install_lib install_doc install: install_bin install_include install_lib install_doc
tests: $(CTESTS:@srcroot@%.c=@objroot@%) tests: $(CTESTS:$(srcroot)%.c=$(objroot)%)
check: tests check: tests
@mkdir -p @objroot@test @mkdir -p $(objroot)test
@$(SHELL) -c 'total=0; \ @$(SHELL) -c 'total=0; \
failures=0; \ failures=0; \
echo "========================================="; \ echo "========================================="; \
for t in $(CTESTS:@srcroot@%.c=@objroot@%); do \ for t in $(CTESTS:$(srcroot)%.c=$(objroot)%); do \
total=`expr $$total + 1`; \ total=`expr $$total + 1`; \
/bin/echo -n "$${t} ... "; \ /bin/echo -n "$${t} ... "; \
$(TEST_LIBRARY_PATH) $${t} @abs_srcroot@ @abs_objroot@ \ $(TEST_LIBRARY_PATH) $${t} $(abs_srcroot) $(abs_objroot) \
> @objroot@$${t}.out 2>&1; \ > $(objroot)$${t}.out 2>&1; \
if test -e "@srcroot@$${t}.exp"; then \ if test -e "$(srcroot)$${t}.exp"; then \
diff -w -u @srcroot@$${t}.exp \ diff -w -u $(srcroot)$${t}.exp \
@objroot@$${t}.out >/dev/null 2>&1; \ $(objroot)$${t}.out >/dev/null 2>&1; \
fail=$$?; \ fail=$$?; \
if test "$${fail}" -eq "1" ; then \ if test "$${fail}" -eq "1" ; then \
failures=`expr $${failures} + 1`; \ failures=`expr $${failures} + 1`; \
@ -217,49 +233,49 @@ check: tests
echo "Failures: $${failures}/$${total}"' echo "Failures: $${failures}/$${total}"'
clean: clean:
rm -f $(CSRCS:@srcroot@%.c=@objroot@%.o) rm -f $(CSRCS:$(srcroot)%.c=$(objroot)%.o)
rm -f $(CSRCS:@srcroot@%.c=@objroot@%.pic.o) rm -f $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.o)
rm -f $(CSRCS:@srcroot@%.c=@objroot@%.d) rm -f $(CSRCS:$(srcroot)%.c=$(objroot)%.d)
rm -f $(CSRCS:@srcroot@%.c=@objroot@%.pic.d) rm -f $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.d)
rm -f $(CTESTS:@srcroot@%.c=@objroot@%) rm -f $(CTESTS:$(srcroot)%.c=$(objroot)%)
rm -f $(CTESTS:@srcroot@%.c=@objroot@%.o) rm -f $(CTESTS:$(srcroot)%.c=$(objroot)%.o)
rm -f $(CTESTS:@srcroot@%.c=@objroot@%.d) rm -f $(CTESTS:$(srcroot)%.c=$(objroot)%.d)
rm -f $(CTESTS:@srcroot@%.c=@objroot@%.out) rm -f $(CTESTS:$(srcroot)%.c=$(objroot)%.out)
rm -f $(DSOS) $(STATIC_LIBS) rm -f $(DSOS) $(STATIC_LIBS)
distclean: clean distclean: clean
rm -rf @objroot@autom4te.cache rm -rf $(objroot)autom4te.cache
rm -f @objroot@config.log rm -f $(objroot)config.log
rm -f @objroot@config.status rm -f $(objroot)config.status
rm -f @objroot@config.stamp rm -f $(objroot)config.stamp
rm -f @cfghdrs_out@ rm -f $(cfghdrs_out)
rm -f @cfgoutputs_out@ rm -f $(cfgoutputs_out)
relclean: distclean relclean: distclean
rm -f @objroot@configure rm -f $(objroot)configure
rm -f @srcroot@VERSION rm -f $(srcroot)VERSION
rm -f $(DOCS_HTML) rm -f $(DOCS_HTML)
rm -f $(DOCS_MAN3) rm -f $(DOCS_MAN3)
#=============================================================================== #===============================================================================
# Re-configuration rules. # Re-configuration rules.
ifeq (@enable_autogen@, 1) ifeq ($(enable_autogen), 1)
@srcroot@configure : @srcroot@configure.ac $(srcroot)configure : $(srcroot)configure.ac
cd ./@srcroot@ && @AUTOCONF@ cd ./$(srcroot) && $(AUTOCONF)
@objroot@config.status : @srcroot@configure $(objroot)config.status : $(srcroot)configure
./@objroot@config.status --recheck ./$(objroot)config.status --recheck
@srcroot@config.stamp.in : @srcroot@configure.ac $(srcroot)config.stamp.in : $(srcroot)configure.ac
echo stamp > @srcroot@config.stamp.in echo stamp > $(srcroot)config.stamp.in
@objroot@config.stamp : @cfgoutputs_in@ @cfghdrs_in@ @srcroot@configure $(objroot)config.stamp : $(cfgoutputs_in) $(cfghdrs_in) $(srcroot)configure
./@objroot@config.status ./$(objroot)config.status
@touch $@ @touch $@
# There must be some action in order for make to re-read Makefile when it is # There must be some action in order for make to re-read Makefile when it is
# out of date. # out of date.
@cfgoutputs_out@ @cfghdrs_out@ : @objroot@config.stamp $(cfgoutputs_out) $(cfghdrs_out) : $(objroot)config.stamp
@true @true
endif endif