From: Michael Hanke <mih@debian.org>
Subject: Configure Debian build and runtime environment

Modifications include:

* Always build for LINUX, even on non-Linux Debian platforms (e.g. kFreeBSD).
  The test for Linux seems to be more of a test for the GNU libc and all target
  platform in Debian have that.
* Prefer to link against shared libraries.
* Accept externally provided CFLAGS
* Path tweaks for Debian-specific install locations.
* Deal with the difference between netstat APIs on Linux and kFreeBSD

--- a/configure
+++ b/configure
@@ -12,8 +12,10 @@
 
 build_user=`whoami`
 build_host=`uname -n`
-build_sys=`uname -s | tr \[a-z\] \[A-Z\] | awk -F_ '{print $1}'`
-build_cpu=`uname -m | tr \[a-z\] \[A-Z\]`
+# this setting is actually used to identify GNU libc platforms
+# and Debian is all GNU libc, so force "Linux" even on non-Linux systems
+build_sys=LINUX
+build_cpu=`dpkg-architecture -qDEB_BUILD_ARCH | tr \[a-z-\] \[A-Z_\]`
 
 if [ "${build_cpu}" = unknown ]
 then
@@ -68,6 +68,8 @@
 ccompiler=gcc
 cxxcompiler=g++
 ccflags="-D__EXTENSIONS__ -D_LARGEFILE64_SOURCE -D__LARGE64_FILES -Wall -Werror -Wno-unknown-pragmas -Wno-deprecated-declarations -fno-exceptions"
+# accepted CCFLAGS from outside
+ccflags="$ccflags $CFLAGS"
 
 if [ ${build_sys} != CYGWIN ]
 then
@@ -207,7 +209,7 @@
 
 if [ $build_sys = LINUX ]
 then
-	ldflags="-Xlinker -Bstatic -Xlinker -lstdc++ -static-libgcc -Xlinker -Bdynamic -Xlinker --as-needed "
+	ldflags="-Xlinker -lstdc++ -Xlinker --as-needed "
 else
 	ldflags="-lstdc++ -static-libgcc"
 fi
@@ -238,7 +240,7 @@
 ##########################################################################
 # SWITCH TO STATIC LINKING FOR UNCOMMON THIRD-PARTY PACKAGES
 ##########################################################################
-library_search_mode=prefer_static
+library_search_mode=prefer_dynamic
 ##########################################################################
 
 if [ $config_egee_path != no ] && check_file "${egee_path}/lcg/include/lcg_util.h"
@@ -362,7 +364,7 @@
 	fi
 fi
 
-if [ $config_mysql_path != no ] && library_search mysqlclient ${mysql_path} mysql
+if [ $config_mysql_path != no ] && library_search mysqlclient ${mysql_path}
 then
 	if [ ${mysql_path} != /usr ]
 	then
@@ -586,17 +588,17 @@
 CCTOOLS_INSTALL_DIR=${install_path}
 CCTOOLS_PACKAGES=${packages}
 
-CCTOOLS_CC=@echo COMPILE \$@; ${ccompiler}
+CCTOOLS_CC=${ccompiler}
 CCTOOLS_BASE_CCFLAGS=${ccflags}
 CCTOOLS_INTERNAL_CCFLAGS=${internal_ccflags} \${CCTOOLS_BASE_CCFLAGS}
 CCTOOLS_CCFLAGS=-I\${CCTOOLS_INSTALL_DIR}/include/cctools \${CCTOOLS_BASE_CCFLAGS}
 
-CCTOOLS_CXX=@echo COMPILE \$@; ${cxxcompiler}
+CCTOOLS_CXX=${cxxcompiler}
 CCTOOLS_BASE_CXXFLAGS=${ccflags}
 CCTOOLS_INTERNAL_CXXFLAGS=${internal_ccflags} \${CCTOOLS_BASE_CXXFLAGS}
 CCTOOLS_CXXFLAGS=-I\${CCTOOLS_INSTALL_DIR}/include/cctools \${CCTOOLS_BASE_CXXFLAGS}
 
-CCTOOLS_LD=@echo LINK \$@; ${linker}
+CCTOOLS_LD=${linker}
 CCTOOLS_BASE_LDFLAGS=${ldflags}
 CCTOOLS_INTERNAL_LDFLAGS= ${internal_ldflags} \${CCTOOLS_BASE_LDFLAGS}
 CCTOOLS_LDFLAGS=-L\${CCTOOLS_INSTALL_DIR}/lib \${CCTOOLS_BASE_LDFLAGS}
diff --git a/dttools/src/test_runner.common.sh b/dttools/src/test_runner.common.sh
index 6972e60..b59da92 100755
--- a/dttools/src/test_runner.common.sh
+++ b/dttools/src/test_runner.common.sh
@@ -23,7 +23,8 @@ dispatch()
 find_free_port()
 {
     case `uname -s` in
-    	Darwin)
+    	# Darwin in GNU/kFreeBSD have the same netstat API
+    	Darwin|GNU/kFreeBSD)
     	netstat -n -f inet | grep tcp | awk '{print $4}' | awk -F . '{print $5}' | sort -n | awk 'BEGIN {n = 9000} {if (n != $1) { print n; exit; } else { n = n+1; } }'
     	;;
     	Linux)
