@@ -49,9 +49,22 @@ ifneq ($(strip $(BUILD_RACE)),)
4949 BUILD_FLAGS += -race
5050endif
5151
52+ # Set TMPDIR, jemalloc will be built here
53+ ifdef TMPDIR
54+ # no-op
55+ else
56+ TMPDIR := /tmp
57+ endif
58+
5259# jemalloc stuff
53- HAS_JEMALLOC = $(shell test -f /usr/local/lib/libjemalloc.a && echo "jemalloc")
54- JEMALLOC_URL = "https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2"
60+ JEMALLOC_VERSION = 5.3.0
61+ JEMALLOC_BUILD = $(TMPDIR ) /jemalloc-$(JEMALLOC_VERSION ) -u$(USER_ID ) /build
62+ JEMALLOC_TARGET = $(TMPDIR ) /jemalloc-$(JEMALLOC_VERSION ) -u$(USER_ID ) /target
63+ JEMALLOC_INCLUDE = $(JEMALLOC_TARGET ) /include
64+ HAS_JEMALLOC = $(shell test -f ${JEMALLOC_TARGET}/lib/libjemalloc.a && echo "jemalloc")
65+ JEMALLOC_URL = "https://github.com/jemalloc/jemalloc/releases/download/$(JEMALLOC_VERSION ) /jemalloc-$(JEMALLOC_VERSION ) .tar.bz2"
66+ export CGO_CFLAGS = -I$(JEMALLOC_INCLUDE )
67+ export CGO_LDFLAGS = $(JEMALLOC_TARGET ) /lib/libjemalloc.a
5568
5669# go install variables
5770HAS_SHA256SUM = $(shell which sha256sum)
@@ -93,17 +106,11 @@ install: jemalloc
93106
94107jemalloc :
95108 @if [ -z " $( HAS_JEMALLOC) " ] ; then \
96- mkdir -p /tmp/jemalloc-temp && cd /tmp/jemalloc-temp ; \
109+ mkdir -p ${JEMALLOC_BUILD} && cd ${JEMALLOC_BUILD} ; \
97110 echo " Downloading jemalloc" ; \
98111 curl -f -s -L ${JEMALLOC_URL} -o jemalloc.tar.bz2 ; \
99112 tar xjf ./jemalloc.tar.bz2 ; \
100- cd jemalloc-5.3.0 ; \
101- ./configure --with-jemalloc-prefix=' je_' --with-malloc-conf=' background_thread:true,metadata_thp:auto' ; \
102- make ; \
103- if [ " $( USER_ID) " = " 0" ]; then \
104- make install ; \
105- else \
106- echo " ==== Need sudo access to install jemalloc" ; \
107- sudo make install ; \
108- fi \
113+ cd jemalloc-$(JEMALLOC_VERSION ) ; \
114+ ./configure --prefix=${JEMALLOC_TARGET} --with-jemalloc-prefix=' je_' --with-malloc-conf=' background_thread:true,metadata_thp:auto' ; \
115+ make install ; \
109116 fi
0 commit comments