Issue
When attempting to cross compile jemalloc there is an error returned by autoconf. New versions of autoconf must have --host set if cross compiling. Autoconf Hosts-and-Cross Compilation
- Redis Version: 5.0.4
- Autoconf Version: 2.69
Steps to reproduce:
cd depsmake jemalloc CC=arm-linux-gnueabihf-gcc- Relevant error: (See full output at bottom)
<snip> checking whether we are cross compiling... configure: error: in `/home/dev/workspace/redis2/redis-5.0.4/deps/jemalloc': configure: error: cannot run C compiled programs. If you meant to cross compile, use `--host'. </snip>
Proposed fix
Allow setting an ENV variable to pass a host string into the Makefile.
Modify the deps/Makefile as follows:
From
<snip>
JEMALLOC_CFLAGS= -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops $(CFLAGS)
JEMALLOC_LDFLAGS= $(LDFLAGS)
jemalloc: .make-prerequisites
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
cd jemalloc && ./configure --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)"
cd jemalloc && $(MAKE) CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)" lib/libjemalloc.a
.PHONY: jemalloc
</snip>
To
- Add an override to prepend "--host=" to JEMALLOC_HOST if it is set
- Place
$(JEMALLOC_HOST)at the end of thecd jemalloc && ./configureline
<snip>
JEMALLOC_CFLAGS= -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops $(CFLAGS)
JEMALLOC_LDFLAGS= $(LDFLAGS)
ifdef JEMALLOC_HOST
override JEMALLOC_HOST:=--host="$(JEMALLOC_HOST)"
endif
jemalloc: .make-prerequisites
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
cd jemalloc && ./configure --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)" $(JEMALLOC_HOST)
cd jemalloc && $(MAKE) CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)" lib/libjemalloc.a
.PHONY: jemalloc
</snip>
Testing
Cross Compiling with JEMALLOC_HOST set
This now works with the fix.
$make jemalloc CC=arm-linux-gnueabihf-gcc JEMALLOC_HOST=x86_64-linux-gnu
MAKE jemalloc
cd jemalloc && ./configure --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS="" --host=x86_64-linux-gnu
<snip>
Cross Compiling with JEMALLOC_HOST NOT set
This still fails to build but now there is a path to passing in the required information.
$make jemalloc CC=arm-linux-gnueabihf-gcc
MAKE jemalloc
cd jemalloc && ./configure --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS=""
<snip>
checking whether we are cross compiling... configure: error: in `/home/dev/workspace/redis2/redis-5.0.4/deps/jemalloc':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
<snip>
Standard Usage
This works as before.
$make jemalloc
MAKE jemalloc
cd jemalloc && ./configure --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS=""
<snip>
Standard Usage with JEMALLOC_HOST set
This works the same as the Standard Usage
$make jemalloc JEMALLOC_HOST=x86_64-linux-gnuMAKE jemalloc
cd jemalloc && ./configure --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS="" --host=x86_64-linux-gnu
<snip>
Full Output of Error
deps/$ make jemalloc CC=arm-linux-gnueabihf-gcc
MAKE jemalloc
cd jemalloc && ./configure --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS=""
configure: WARNING: unrecognized options: --enable-cc-silence
checking for xsltproc... false
checking for gcc... arm-linux-gnueabihf-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/home/dev/workspace/redis2/redis-5.0.4/deps/jemalloc':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
Makefile:79: recipe for target 'jemalloc' failed
make: *** [jemalloc] Error 1
Comment From: isgallagher
Thanks that definitely helped get the cross compiling working for me.