From f2275b2c13743ff6059068ac8eaa82733bfa2630 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 23 Apr 2015 11:52:27 +0200 Subject: 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 --- Cmds | 9 +++--- INSTALL | 9 ++++-- Makefile | 9 +++--- Misc | 2 -- configure | 87 +++++++++++++++++++++++++++++++++++++++------------- flowtop/Makefile | 6 ++-- ifpps/Makefile | 6 ++-- netsniff-ng/Makefile | 8 ++--- trafgen/Makefile | 8 ++--- 9 files changed, 94 insertions(+), 50 deletions(-) diff --git a/Cmds b/Cmds index aa8c0a2..fdb80ea 100644 --- a/Cmds +++ b/Cmds @@ -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 diff --git a/INSTALL b/INSTALL index d170bc2..3495089 100644 --- a/INSTALL +++ b/INSTALL @@ -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= + $ CROSS_COMPILE=microblazeel-unknown-linux-gnu- \ + SYSROOT= ./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='. Note that some adaptations might be necessary regarding the CFLAGS, since not all might be supported by a different architecture. Probably the most simple diff --git a/Makefile b/Makefile index cf6c9bc..7379aca 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # netsniff-ng build system # Copyright 2012 - 2013 Daniel Borkmann -# Copyright 2013 - 2014 Tobias Klauser +# Copyright 2013 - 2015 Tobias Klauser # 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) $@/$@ diff --git a/Misc b/Misc index 8031c79..cd252f0 100644 --- a/Misc +++ b/Misc @@ -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 ...\" - Additional CFLAGS for compilation" diff --git a/configure b/configure index 2e553cb..b02eb18 100755 --- a/configure +++ b/configure @@ -1,11 +1,11 @@ #!/bin/bash # This isn't a configure generated by autoconf! # netsniff-ng build system -# Copyright 2013 Tobias Klauser +# Copyright 2013-2015 Tobias Klauser # Copyright 2013 Daniel Borkmann # 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= SYSROOT= ./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 -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #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 -- cgit v1.2.3-54-g00ecf