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
@@ -44,8 +44,10 @@
 
 build_user="$USER"
 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
@@ -81,7 +83,7 @@
 
 if [ -d parrot -a $build_sys = LINUX ]
 then
-	if [ $build_cpu = I386 -o $build_cpu = X86_64 ]
+	if [ $build_cpu = I386 -o $build_cpu = AMD64 ]
 	then
 		echo "parrot IS supported on ${build_sys} ${build_cpu}"
 		include_package_parrot="parrot"
@@ -132,6 +134,8 @@
 mpicompiler=mpicc
 
 ccflags="-D__EXTENSIONS__ -D_LARGEFILE64_SOURCE -D__LARGE64_FILES -Wall -Wextra -Wno-unused-parameter -Wno-unknown-pragmas -Wno-deprecated-declarations -fno-exceptions"
+# accepted CCFLAGS from outside
+ccflags="$ccflags $CFLAGS"
 
 if [ ${build_sys} != CYGWIN ]
 then
@@ -409,15 +413,18 @@
 
 if [ $build_sys = LINUX ]
 then
-        ldflags="-Xlinker -Bstatic -static-libgcc -Xlinker -Bdynamic ${link_as_needed}"
+        ldflags="${link_as_needed}"
 else
         ldflags="-static-libgcc"
 fi
 
+# accept ldflags from outside
+ldflags="$ldflags $LDFLAGS"
+
 ##########################################################################
 # SWITCH TO STATIC LINKING FOR UNCOMMON THIRD-PARTY PACKAGES
 ##########################################################################
-library_search_mode=prefer_static
+library_search_mode=prefer_dynamic
 ##########################################################################
 
 if [ $config_rfio_path != no ] && library_search shift ${rfio_path}
@@ -512,7 +519,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
@@ -546,11 +553,11 @@
 	fi
 fi
 
-if [ $config_mpi_path != no ] && check_file ${mpi_path}/bin/mpicc && check_file ${mpi_path}/include/mpi.h
+if [ $config_mpi_path != no ] && check_file ${mpi_path}/bin/mpicc && check_file ${mpi_path}/include/mpi/mpi.h
 then
         mpilinker=${mpi_path}/bin/mpicc
         usempi="true"
-        ccflags="${ccflags} -I${mpi_path}/include -DHAS_MPI"
+        ccflags="${ccflags} -I${mpi_path}/include/mpi -DHAS_MPI"
 else
 	usempi="false"
 	if [ $config_mpi_path = yes ]
@@ -1034,17 +1041,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}
