From af5d6987f829ccd6e14dd1f57586cfb072a533c7 Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Tue, 15 Feb 2011 14:13:38 -0800 Subject: [PATCH] Build both PIC and no PIC static libraries When jemalloc is linked into an executable (as opposed to a shared library), compiling with -fno-pic can have significant advantages, mainly because we don't have to go throught the GOT (global offset table). Users who want to link jemalloc into a shared library that could be dlopened need to link with libjemalloc_pic.a or libjemalloc.so. --- jemalloc/Makefile.in | 25 ++++++++++++++----- .../jemalloc/internal/jemalloc_internal.h.in | 5 ---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/jemalloc/Makefile.in b/jemalloc/Makefile.in index eb8a21f6..6dfaf5b0 100644 --- a/jemalloc/Makefile.in +++ b/jemalloc/Makefile.in @@ -20,7 +20,7 @@ MANDIR := $(DESTDIR)@MANDIR@ # Build parameters. CPPFLAGS := @CPPFLAGS@ -I@srcroot@include -I@objroot@include -CFLAGS := @CFLAGS@ -fPIC -DPIC +CFLAGS := @CFLAGS@ ifeq (macho, @abi@) CFLAGS += -dynamic endif @@ -55,6 +55,7 @@ CSRCS := @srcroot@src/jemalloc.c @srcroot@src/arena.c @srcroot@src/base.c \ ifeq (macho, @abi@) CSRCS += @srcroot@src/zone.c endif +STATIC_LIBS := @objroot@lib/libjemalloc@install_suffix@.a DSOS := @objroot@lib/libjemalloc@install_suffix@.$(SO).$(REV) \ @objroot@lib/libjemalloc@install_suffix@.$(SO) \ @objroot@lib/libjemalloc@install_suffix@_pic.a @@ -75,7 +76,7 @@ CTESTS := @srcroot@test/allocated.c @srcroot@test/allocm.c \ .SECONDARY : $(CTESTS:@srcroot@%.c=@objroot@%.o) # Default target. -all: $(DSOS) +all: $(DSOS) $(STATIC_LIBS) dist: doc @@ -99,15 +100,24 @@ doc: $(DOCS) $(CC) $(CFLAGS) -c $(CPPFLAGS) -o $@ $< @$(SHELL) -ec "$(CC) -MM $(CPPFLAGS) $< | sed \"s/\($(subst /,\/,$(notdir $(basename $@)))\)\.o\([ :]*\)/$(subst /,\/,$(strip $(dir $@)))\1.o \2/g\" > $(@:%.o=%.d)" +@objroot@src/%.pic.o: @srcroot@src/%.c + @mkdir -p $(@D) + $(CC) $(CFLAGS) -fPIC -DPIC -c $(CPPFLAGS) -o $@ $< + @$(SHELL) -ec "$(CC) -MM $(CPPFLAGS) $< | sed \"s/\($(subst /,\/,$(notdir $(basename $@)))\)\.o\([ :]*\)/$(subst /,\/,$(strip $(dir $@)))\1.o \2/g\" > $(@:%.o=%.d)" + %.$(SO) : %.$(SO).$(REV) @mkdir -p $(@D) ln -sf $(