diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2015-04-23 11:52:27 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2015-04-23 11:54:43 +0200 |
commit | f2275b2c13743ff6059068ac8eaa82733bfa2630 (patch) | |
tree | 2086b3a543b0132755cf04bf53b010b4c3e4afe0 /configure | |
parent | 6a7762bd6ab5eaeec23fa05a22c1edf4d9ab0804 (diff) |
build: Restore support for cross-compiling the netsniff-ng toolkit
Ever since we switched to the hand-crafted ./configure script, support
for cross-compiling the netsniff-ng toolkit was basically broken.
Restore the abaility to cross-compile our tools by making ./configure
consider the CROSS_COMPILE and SYSROOT variables.
Example for cross-compiling on arm:
$ CROSS_COMPILE=arm-linux-gnueabihf- \
SYSROOT=/usr/arm-linux-gnueabihf \
./configure
$ make
assuming the cross-compiled libraries (and their respective pkg-config
information) are in /usr/arm-linux-gnueabihf.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'configure')
-rwxr-xr-x | configure | 87 |
1 files changed, 65 insertions, 22 deletions
@@ -1,11 +1,11 @@ #!/bin/bash # This isn't a configure generated by autoconf! # netsniff-ng build system -# Copyright 2013 Tobias Klauser <tklauser@distanz.ch> +# Copyright 2013-2015 Tobias Klauser <tklauser@distanz.ch> # Copyright 2013 Daniel Borkmann <borkmann@gnumaniacs.org> # Subject to the GNU GPL, version 2. -MISSING_PKG_CONFIG=0 +MISSING_TOOLCHAIN=0 MISSING_DEFS=0 MISSING_NACL=0 @@ -18,7 +18,15 @@ HAVE_LIBGEOIP=0 HAVE_LIBZ=0 HAVE_TPACKET3=0 -[ -z $CC ] && CC=cc +# use "CROSS_COMPILE=<prefix> SYSROOT=<path> ./configure && make" for cross compilation + +[ -z $CC ] && CC="${CROSS_COMPILE}gcc" +[ -z $LD ] && LD="${CROSS_COMPILE}gcc" +[ -z $STRIP ] && STRIP="${CROSS_COMPILE}strip" +if [ "x$SYSROOT" != "x" ] ; then + PKG_CONFIG_PATH="$SYSROOT/usr/lib/pkgconfig:$PKG_CONFIG_PATH" +fi +[ -z $PKG_CONFIG ] && PKG_CONFIG="${CROSS_COMPILE}pkg-config" TMPDIR=$(mktemp -d config.XXXXXX) trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM @@ -43,16 +51,50 @@ tools_remove() TOOLS_NOBUILD=${TOOLS_NOBUILD# } } -check_pkg_config() +check_toolchain() { - echo -n "[*] Checking pkg-config ... " + if [ "x$CROSS_COMPILE" != "x" ] ; then + echo "[*] Cross-compiling for $($CC -print-multiarch)" + echo "CROSS_COMPILE=$CROSS_COMPILE" >> Config + fi + + echo -n "[*] Checking compiler $CC ... " + if [ "x$(which $CC 2>> config.log)" == "x" ] ; then + echo "[NO]" + MISSING_TOOLCHAIN=1 + else + echo "[YES]" + echo "CC=$CC" >> Config + fi - if [ "x$(which pkg-config 2>> config.log)" == "x" ] ; then + echo -n "[*] Checking linker $LD ... " + if [ "x$(which $LD 2>> config.log)" == "x" ] ; then echo "[NO]" - MISSING_PKG_CONFIG=1 + MISSING_TOOLCHAIN=1 else echo "[YES]" + echo "LD=$LD" >> Config fi + + echo -n "[*] Checking $PKG_CONFIG ... " + if [ "x$(which $PKG_CONFIG 2>> config.log)" == "x" ] ; then + echo "[NO]" + MISSING_TOOLCHAIN=1 + else + echo "[YES]" + echo "PKG_CONFIG=$PKG_CONFIG" >> Config + echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> Config + fi + + echo -n "[*] Checking $STRIP ... " + if [ "x$(which $STRIP 2>> config.log)" == "x" ] ; then + echo "[NO]" + MISSING_TOOLCHAIN=1 + else + echo "[YES]" + echo "STRIP=$STRIP" >> Config + fi + } check_flex() @@ -131,12 +173,12 @@ check_libnl() echo -n "[*] Checking libnl ... " cat > $TMPDIR/libnltest.c << EOF -#include <libnl3/netlink/genl/genl.h> -#include <libnl3/netlink/genl/family.h> -#include <libnl3/netlink/genl/ctrl.h> -#include <libnl3/netlink/msg.h> -#include <libnl3/netlink/attr.h> -#include <libnl3/netlink/version.h> +#include <netlink/genl/genl.h> +#include <netlink/genl/family.h> +#include <netlink/genl/ctrl.h> +#include <netlink/msg.h> +#include <netlink/attr.h> +#include <netlink/version.h> #if LIBNL_VER_NUM < LIBNL_VER(3,0) # error incompatible libnl version @@ -153,12 +195,12 @@ int main(void) EOF $CC \ - $(pkg-config --cflags libnl-3.0 2>> config.log) \ - $(pkg-config --cflags libnl-genl-3.0 2>> config.log) \ + $($PKG_CONFIG --cflags libnl-3.0 2>> config.log) \ + $($PKG_CONFIG --cflags libnl-genl-3.0 2>> config.log) \ -o $TMPDIR/libnltest \ $TMPDIR/libnltest.c \ - $(pkg-config --libs libnl-3.0 2>> config.log) \ - $(pkg-config --libs libnl-genl-3.0 2>> config.log) \ + $($PKG_CONFIG --libs libnl-3.0 2>> config.log) \ + $($PKG_CONFIG --libs libnl-genl-3.0 2>> config.log) \ >> config.log 2>&1 if [ ! -x $TMPDIR/libnltest ] ; then echo "[NO]" @@ -248,9 +290,9 @@ int main(void) EOF $CC \ - $(pkg-config --cflags ncurses 2>> config.log) \ + $($PKG_CONFIG --cflags ncurses 2>> config.log) \ -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \ - $(pkg-config --libs ncurses 2>> config.log \ + $($PKG_CONFIG --libs ncurses 2>> config.log \ || echo '-lncurses' ) \ >> config.log 2>&1 if [ ! -x $TMPDIR/ncursestest ] ; then @@ -570,10 +612,11 @@ EOF rm -f config.log echo "# This file is autogenerated by the configure script" > Config -check_pkg_config +check_toolchain -if [ "$MISSING_PKG_CONFIG" == "1" ] ; then - echo "[!] pkg-config is not installed on your system or not in the PATH" +if [ "$MISSING_TOOLCHAIN" == "1" ] ; then + echo "[!] One or more of the toolchain tools couldn't be found in your" + echo " \$PATH. Please check the file config.log for details." exit 1 fi |