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 | |
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>
-rw-r--r-- | Cmds | 9 | ||||
-rw-r--r-- | INSTALL | 9 | ||||
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | Misc | 2 | ||||
-rwxr-xr-x | configure | 87 | ||||
-rw-r--r-- | flowtop/Makefile | 6 | ||||
-rw-r--r-- | ifpps/Makefile | 6 | ||||
-rw-r--r-- | netsniff-ng/Makefile | 8 | ||||
-rw-r--r-- | trafgen/Makefile | 8 |
9 files changed, 94 insertions, 50 deletions
@@ -5,14 +5,13 @@ Q = @ SHELL := $(shell if [ -x /bin/bash ]; then echo /bin/bash; else echo /bin/sh; fi) # Compiler related stuff -CC = gcc -LDQ = $(Q)echo -e " LD\t$@" && $(CCACHE) $(CROSS_COMPILE)$(CC) -CCNQ = $(CCACHE) $(CROSS_COMPILE)$(CC) +LDQ = $(Q)echo -e " LD\t$@" && $(CCACHE) $(CC) +CCNQ = $(CCACHE) $(CC) CCQ = $(Q)echo -e " CC\t$<" && $(CCNQ) ifeq ($(DEBUG), 1) - STRIP = $(Q)true + STRIPQ = $(Q)true else - STRIP = $(Q)echo -e " STRIP\t$@" && $(CROSS_COMPILE)strip + STRIPQ = $(Q)echo -e " STRIP\t$@" && $(STRIP) endif # sparse related @@ -160,8 +160,13 @@ variable first, e.g.: And then, build the toolkit like this: - $ make CROSS_COMPILE=microblazeel-unknown-linux-gnu- \ - CROSS_LD_LIBRARY_PATH=<cc-lib-search-path> + $ CROSS_COMPILE=microblazeel-unknown-linux-gnu- \ + SYSROOT=<sysroot-path> ./configure + $ make + +SYSROOT should be set to the path where your cross-compiled libraries are +stored, i.e. the path you specify as prefix when configuring the library using +`./configure --prefix=<prefix>'. Note that some adaptations might be necessary regarding the CFLAGS, since not all might be supported by a different architecture. Probably the most simple @@ -1,6 +1,6 @@ # netsniff-ng build system # Copyright 2012 - 2013 Daniel Borkmann <borkmann@gnumaniacs.org> -# Copyright 2013 - 2014 Tobias Klauser <tklauser@distanz.ch> +# Copyright 2013 - 2015 Tobias Klauser <tklauser@distanz.ch> # Subject to the GNU GPL, version 2. -include Config @@ -120,14 +120,13 @@ VERSION_STRING = "$(VERSION_SHORT)$(CONFIG_RC)" VERSION_LONG = "$(VERSION_SHORT)$(CONFIG_RC) ($(NAME))" export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION -export CROSS_COMPILE export DEBUG HARDENING bold = $(shell tput bold) normal = $(shell tput sgr0) -ifeq ("$(origin CROSS_COMPILE)", "command line") - WHAT := Cross compiling +ifneq ("$(CROSS_COMPILE)", "") + WHAT := Cross-compiling else WHAT := Building endif @@ -178,4 +177,4 @@ $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool)))) $(TOOLS): $(LDQ) $(LDFLAGS) -o $@/$@ $@/*.o $($@-libs) - $(STRIP) $@/$@ + $(STRIPQ) $@/$@ @@ -107,8 +107,6 @@ help: $(Q)echo " HARDENING=1 - Enable GCC hardening of executables" $(Q)echo " PREFIX=/path - Install path prefix" $(Q)echo " DESTDIR=/path - Alternative install destination path" - $(Q)echo " CROSS_COMPILE=arch-prefix - Kernel-like cross-compiling architecture prefix" - $(Q)echo " CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling" $(Q)echo " CC=cgcc - Use sparse compiler wrapper" $(Q)echo " CFLAGS=\"-O2 -Wall ...\" - Overwrite CFLAGS for compilation" $(Q)echo " CPPFLAGS=\"-I <path> ...\" - Additional CFLAGS for compilation" @@ -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 diff --git a/flowtop/Makefile b/flowtop/Makefile index 41865c7..1bd5a0f 100644 --- a/flowtop/Makefile +++ b/flowtop/Makefile @@ -1,8 +1,8 @@ flowtop-libs = -lurcu \ -lnetfilter_conntrack \ - $(shell pkg-config --libs ncurses 2> /dev/null \ + $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs ncurses 2> /dev/null \ || echo '-lncurses') \ - $(shell pkg-config --libs tinfo 2> /dev/null ) \ + $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs tinfo 2> /dev/null ) \ -lpthread ifeq ($(CONFIG_GEOIP), 1) @@ -29,7 +29,7 @@ flowtop-objs += geoip.o \ ioops.o endif -flowtop-eflags = $(shell pkg-config --cflags ncurses) +flowtop-eflags = $(shell $(PKG_CONFIG) --cflags ncurses) flowtop-confs = tcp.conf \ udp.conf \ diff --git a/ifpps/Makefile b/ifpps/Makefile index 1625ea9..110e6aa 100644 --- a/ifpps/Makefile +++ b/ifpps/Makefile @@ -1,6 +1,6 @@ -ifpps-libs = $(shell pkg-config --libs ncurses 2> /dev/null \ +ifpps-libs = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs ncurses 2> /dev/null \ || echo '-lncurses') \ - $(shell pkg-config --libs tinfo 2> /dev/null ) + $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs tinfo 2> /dev/null ) ifpps-objs = xmalloc.o \ ioops.o \ @@ -13,6 +13,6 @@ ifpps-objs = xmalloc.o \ die.o \ ifpps.o -ifpps-eflags = $(shell pkg-config --cflags ncurses 2> /dev/null) +ifpps-eflags = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags ncurses 2> /dev/null) ifpps-confs = diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile index 63bf58f..9fe2ffe 100644 --- a/netsniff-ng/Makefile +++ b/netsniff-ng/Makefile @@ -1,5 +1,5 @@ -netsniff-ng-libs = $(shell pkg-config --libs libnl-3.0) \ - $(shell pkg-config --libs libnl-genl-3.0) \ +netsniff-ng-libs = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libnl-3.0) \ + $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libnl-genl-3.0) \ -lpthread ifeq ($(CONFIG_LIBPCAP), 1) @@ -76,8 +76,8 @@ ifeq ($(CONFIG_HWTSTAMP), 1) netsniff-ng-objs += tstamping.o endif -netsniff-ng-eflags = $(shell pkg-config --cflags libnl-3.0) \ - $(shell pkg-config --cflags libnl-genl-3.0) \ +netsniff-ng-eflags = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnl-3.0) \ + $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnl-genl-3.0) \ -DNEED_TCPDUMP_LIKE_FILTER netsniff-ng-confs = ether.conf \ diff --git a/trafgen/Makefile b/trafgen/Makefile index b37e62d..3cb8497 100644 --- a/trafgen/Makefile +++ b/trafgen/Makefile @@ -1,5 +1,5 @@ -trafgen-libs = $(shell pkg-config --libs libnl-3.0) \ - $(shell pkg-config --libs libnl-genl-3.0) \ +trafgen-libs = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libnl-3.0) \ + $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libnl-genl-3.0) \ -lm trafgen-objs = xmalloc.o \ @@ -25,8 +25,8 @@ trafgen-lex = trafgen_lexer.yy.o trafgen-yaac = trafgen_parser.tab.o -trafgen-eflags = $(shell pkg-config --cflags libnl-3.0) \ - $(shell pkg-config --cflags libnl-genl-3.0) \ +trafgen-eflags = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnl-3.0) \ + $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnl-genl-3.0) \ -I.. trafgen-confs = trafgen_stddef.h |