Refactor object and library build, and only build PIC libraries when PIC_CFLAGS is defined
This commit is contained in:
parent
85221d5d75
commit
188da7c3f5
75
Makefile.in
75
Makefile.in
@ -48,6 +48,7 @@ enable_autogen := @enable_autogen@
|
|||||||
enable_experimental := @enable_experimental@
|
enable_experimental := @enable_experimental@
|
||||||
DSO_LDFLAGS = @DSO_LDFLAGS@
|
DSO_LDFLAGS = @DSO_LDFLAGS@
|
||||||
SOREV = @SOREV@
|
SOREV = @SOREV@
|
||||||
|
PIC_CFLAGS = @PIC_CFLAGS@
|
||||||
|
|
||||||
ifeq (macho, $(ABI))
|
ifeq (macho, $(ABI))
|
||||||
TEST_LIBRARY_PATH := DYLD_FALLBACK_LIBRARY_PATH=$(objroot)lib
|
TEST_LIBRARY_PATH := DYLD_FALLBACK_LIBRARY_PATH=$(objroot)lib
|
||||||
@ -73,8 +74,10 @@ ifeq (macho, $(ABI))
|
|||||||
CSRCS += $(srcroot)src/zone.c
|
CSRCS += $(srcroot)src/zone.c
|
||||||
endif
|
endif
|
||||||
STATIC_LIBS := $(objroot)lib/$(LIBJEMALLOC).$(A)
|
STATIC_LIBS := $(objroot)lib/$(LIBJEMALLOC).$(A)
|
||||||
DSOS := $(objroot)lib/$(LIBJEMALLOC)_pic.$(A) \
|
ifdef PIC_CFLAGS
|
||||||
$(objroot)lib/$(LIBJEMALLOC).$(SOREV)
|
STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_pic.$(A)
|
||||||
|
endif
|
||||||
|
DSOS := $(objroot)lib/$(LIBJEMALLOC).$(SOREV)
|
||||||
ifneq ($(SOREV),$(SO))
|
ifneq ($(SOREV),$(SO))
|
||||||
DSOS += $(objroot)lib/$(LIBJEMALLOC).$(SO)
|
DSOS += $(objroot)lib/$(LIBJEMALLOC).$(SO)
|
||||||
endif
|
endif
|
||||||
@ -91,12 +94,16 @@ ifeq ($(enable_experimental), 1)
|
|||||||
CTESTS += $(srcroot)test/allocm.c $(srcroot)test/rallocm.c
|
CTESTS += $(srcroot)test/allocm.c $(srcroot)test/rallocm.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
COBJS := $(CSRCS:$(srcroot)%.c=$(objroot)%.$(O))
|
||||||
|
CPICOBJS := $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.$(O))
|
||||||
|
CTESTOBJS := $(CTESTS:$(srcroot)%.c=$(objroot)%.$(O))
|
||||||
|
|
||||||
.PHONY: all dist doc_html doc_man doc
|
.PHONY: all dist doc_html doc_man doc
|
||||||
.PHONY: install_bin install_include install_lib
|
.PHONY: install_bin install_include install_lib
|
||||||
.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 : $(CTESTOBJS)
|
||||||
|
|
||||||
# Default target.
|
# Default target.
|
||||||
all: build
|
all: build
|
||||||
@ -116,47 +123,41 @@ build_doc: $(DOCS)
|
|||||||
#
|
#
|
||||||
# Include generated dependency files.
|
# Include generated dependency files.
|
||||||
#
|
#
|
||||||
-include $(CSRCS:$(srcroot)%.c=$(objroot)%.d)
|
-include $(COBJS:%.$(O)=%.d)
|
||||||
-include $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.d)
|
-include $(CPICOBJS:%.$(O)=%.d)
|
||||||
-include $(CTESTS:$(srcroot)%.c=$(objroot)%.d)
|
-include $(CTESTOBJS:%.$(O)=%.d)
|
||||||
|
|
||||||
$(objroot)src/%.$(O): $(srcroot)src/%.c
|
$(COBJS): $(objroot)src/%.$(O): $(srcroot)src/%.c
|
||||||
|
$(CPICOBJS): $(objroot)src/%.pic.$(O): $(srcroot)src/%.c
|
||||||
|
$(CPICOBJS): CFLAGS += $(PIC_CFLAGS)
|
||||||
|
$(CTESTOBJS): $(objroot)test/%.$(O): $(srcroot)test/%.c
|
||||||
|
$(CTESTOBJS): CPPFLAGS += -I$(objroot)test
|
||||||
|
|
||||||
|
$(COBJS) $(CPICOBJS) $(CTESTOBJS): %.$(O):
|
||||||
@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
|
|
||||||
@mkdir -p $(@D)
|
|
||||||
$(CC) $(CFLAGS) -fPIC -DPIC -c $(CPPFLAGS) -o $@ $<
|
|
||||||
@$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $<
|
|
||||||
|
|
||||||
ifneq ($(SOREV),$(SO))
|
ifneq ($(SOREV),$(SO))
|
||||||
%.$(SO) : %.$(SOREV)
|
%.$(SO) : %.$(SOREV)
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
ln -sf $(<F) $@
|
ln -sf $(<F) $@
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(objroot)lib/$(LIBJEMALLOC).$(SOREV) : $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.$(O))
|
$(objroot)lib/$(LIBJEMALLOC).$(SOREV) : $(if $(PIC_CFLAGS),$(CPICOBJS),$(COBJS))
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(CC) $(DSO_LDFLAGS) $(call RPATH,$(RPATH_EXTRA)) -o $@ $+ $(LDFLAGS) $(LIBS)
|
$(CC) $(DSO_LDFLAGS) $(call RPATH,$(RPATH_EXTRA)) -o $@ $+ $(LDFLAGS) $(LIBS)
|
||||||
|
|
||||||
$(objroot)lib/$(LIBJEMALLOC)_pic.$(A) : $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.$(O))
|
$(objroot)lib/$(LIBJEMALLOC)_pic.$(A) : $(CPICOBJS)
|
||||||
|
$(objroot)lib/$(LIBJEMALLOC).$(A) : $(COBJS)
|
||||||
|
|
||||||
|
$(STATIC_LIBS):
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
ar crus $@ $+
|
ar crus $@ $+
|
||||||
|
|
||||||
$(objroot)lib/$(LIBJEMALLOC).$(A) : $(CSRCS:$(srcroot)%.c=$(objroot)%.$(O))
|
|
||||||
@mkdir -p $(@D)
|
|
||||||
ar crus $@ $+
|
|
||||||
|
|
||||||
$(objroot)test/%.$(O): $(srcroot)test/%.c
|
|
||||||
@mkdir -p $(@D)
|
|
||||||
$(CC) $(CFLAGS) -c $(CPPFLAGS) -I$(objroot)test -o $@ $<
|
|
||||||
@$(CC) -MM $(CPPFLAGS) -I$(objroot)test -MT $@ -o $(@:%.$(O)=%.d) $<
|
|
||||||
|
|
||||||
$(objroot)test/bitmap$(EXE): $(objroot)src/bitmap.$(O)
|
$(objroot)test/bitmap$(EXE): $(objroot)src/bitmap.$(O)
|
||||||
|
|
||||||
$(objroot)test/%$(EXE): $(objroot)test/%.$(O) $(objroot)src/util.$(O) \
|
$(objroot)test/%$(EXE): $(objroot)test/%.$(O) $(objroot)src/util.$(O) $(DSOS)
|
||||||
$(objroot)lib/$(LIBJEMALLOC).$(SO)
|
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(CC) -o $@ $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) -L$(objroot)lib -ljemalloc$(install_suffix) $(LIBS)
|
$(CC) -o $@ $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) -L$(objroot)lib -ljemalloc$(install_suffix) $(LIBS)
|
||||||
|
|
||||||
@ -185,10 +186,12 @@ ifneq ($(SOREV),$(SO))
|
|||||||
ln -sf $(LIBJEMALLOC).$(SOREV) $(LIBDIR)/$(LIBJEMALLOC).$(SO)
|
ln -sf $(LIBJEMALLOC).$(SOREV) $(LIBDIR)/$(LIBJEMALLOC).$(SO)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
install_lib_static: $(DSOS) $(STATIC_LIBS)
|
install_lib_static: $(STATIC_LIBS)
|
||||||
install -d $(LIBDIR)
|
install -d $(LIBDIR)
|
||||||
install -m 755 $(objroot)lib/$(LIBJEMALLOC)_pic.$(A) $(LIBDIR)
|
@for l in $(STATIC_LIBS); do \
|
||||||
install -m 755 $(objroot)lib/$(LIBJEMALLOC).$(A) $(LIBDIR)
|
echo "install -m 755 $$l $(LIBDIR)"; \
|
||||||
|
install -m 755 $$l $(LIBDIR); \
|
||||||
|
done
|
||||||
|
|
||||||
install_lib: install_lib_shared install_lib_static
|
install_lib: install_lib_shared install_lib_static
|
||||||
|
|
||||||
@ -241,14 +244,14 @@ check: tests
|
|||||||
echo "Failures: $${failures}/$${total}"'
|
echo "Failures: $${failures}/$${total}"'
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(CSRCS:$(srcroot)%.c=$(objroot)%.$(O))
|
rm -f $(COBJS)
|
||||||
rm -f $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.$(O))
|
rm -f $(CPICOBJS)
|
||||||
rm -f $(CSRCS:$(srcroot)%.c=$(objroot)%.d)
|
rm -f $(COBJS:%.$(O)=%.d)
|
||||||
rm -f $(CSRCS:$(srcroot)%.c=$(objroot)%.pic.d)
|
rm -f $(CPICOBJS:%.$(O)=%.d)
|
||||||
rm -f $(CTESTS:$(srcroot)%.c=$(objroot)%$(EXE))
|
rm -f $(CTESTOBJS:%.$(O)=%$(EXE))
|
||||||
rm -f $(CTESTS:$(srcroot)%.c=$(objroot)%.$(O))
|
rm -f $(CTESTOBJS)
|
||||||
rm -f $(CTESTS:$(srcroot)%.c=$(objroot)%.d)
|
rm -f $(CTESTOBJS:%.$(O)=%.d)
|
||||||
rm -f $(CTESTS:$(srcroot)%.c=$(objroot)%.out)
|
rm -f $(CTESTOBJS:%.$(O)=%.out)
|
||||||
rm -f $(DSOS) $(STATIC_LIBS)
|
rm -f $(DSOS) $(STATIC_LIBS)
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean
|
||||||
|
@ -202,6 +202,7 @@ lib="lib"
|
|||||||
DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
|
DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
|
||||||
RPATH='-Wl,-rpath,$(1)'
|
RPATH='-Wl,-rpath,$(1)'
|
||||||
SOREV='$(SO).$(REV)'
|
SOREV='$(SO).$(REV)'
|
||||||
|
PIC_CFLAGS='-fPIC -DPIC'
|
||||||
|
|
||||||
dnl Heap profiling uses the log(3) function.
|
dnl Heap profiling uses the log(3) function.
|
||||||
LIBS="$LIBS -lm"
|
LIBS="$LIBS -lm"
|
||||||
@ -287,6 +288,7 @@ AC_SUBST([exe])
|
|||||||
AC_SUBST([lib])
|
AC_SUBST([lib])
|
||||||
AC_SUBST([DSO_LDFLAGS])
|
AC_SUBST([DSO_LDFLAGS])
|
||||||
AC_SUBST([SOREV])
|
AC_SUBST([SOREV])
|
||||||
|
AC_SUBST([PIC_CFLAGS])
|
||||||
|
|
||||||
JE_COMPILABLE([__attribute__ syntax],
|
JE_COMPILABLE([__attribute__ syntax],
|
||||||
[static __attribute__((unused)) void foo(void){}],
|
[static __attribute__((unused)) void foo(void){}],
|
||||||
|
Loading…
Reference in New Issue
Block a user