swh:1:snp:d38c873ef0dedf048d0da5af92fe2789c661cbfa
Raw File
Tip revision: 2fa04d636052a1acda171c2db2752b48fdeec60c authored by Benjamin Tovar on 13 April 2015, 18:29:33 UTC
uuid custom path
Tip revision: 2fa04d6
configure
#!/bin/sh

uname -a

if [ -z "$USER" ]; then
  USER=`whoami`
  export USER
fi

. ./configure.tools

save_arguments $0 $@

major=4
minor=4
micro=0rc2

# On a release, type would be changed from TRUNK to RELEASE.  TRUNK is a useful
# signal that the user is not using a blessed (tagged) release.
type="TRUNK"

version="$major.$minor.$micro-$type"

# The release date is set automatically at configure time (the default).
# For a tagged release, this should be the hard-coded date of the release.
release_date=`date +%m/%d/%Y`

# Bourne shell is tricky when you use backtick command substitution backslash
# has special meaning even when surrounded by single-quotes. It is necessary to
# escape the backslash.
# Here's what we want to exec literally:
#   echo "$*" | sed s/#/\\#/ | sed s/\$/$$/
# The above sed commands are to escape the output for the Makefile.
# Arguments to configure which can be printed for version/debug information.
configure_arguments=`echo "$*" | sed 's/#/\\\\#/' | sed 's/\\$/$$/'`

# Bourne shell is tricky when you use backtick command substitution backslash
# has special meaning even when surrounded by single-quotes. It is necessary to
# escape the backslash.
# Here's what we want to exec literally:
#   uname -a | sed s/#/\\#/ | sed s/\$/$$/
# The above sed commands are to escape the output for the Makefile.
system_information=`uname -a | sed 's/#/\\\\#/' | sed 's/\\$/$$/'`

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\]`

if [ "${build_cpu}" = UNKNOWN ]
then
	build_cpu=`uname -p | tr \[a-z\] \[A-Z\]`
fi

case "$build_cpu" in
	I[0-9]86)
	build_cpu=I386
	;;
	POWER\ MACINTOSH)
	build_cpu=POWERPC
	;;
	SUN4V)
	build_cpu=SPARC
	;;
esac

include_package_sand="sand"
include_package_allpairs="allpairs"
include_package_wavefront="wavefront"
include_package_makeflow="makeflow"
include_package_ftplite="ftp_lite"
include_package_chirp="chirp"
include_package_resource_monitor="resource_monitor"
include_package_resource_monitor_visualizer="resource_monitor_visualizer"
include_package_weaver="weaver"
include_package_doc="doc"

work_queue_bindings=""

echo "checking for package compatibility..."

if [ -d parrot -a $build_sys = LINUX ]
then
	if [ $build_cpu = I386 -o $build_cpu = X86_64 ]
	then
		echo "parrot IS supported on ${build_sys} ${build_cpu}"
		include_package_parrot="parrot"
	else
		echo "parrot is NOT supported on ${build_sys} ${build_cpu}"
		include_package_parrot=""
	fi
else
	echo "parrot is NOT supported on ${build_sys} for any cpu type"
	include_package_parrot=""
fi

if [ -d resource_monitor ]
then
	if [ $build_sys = LINUX -o $build_sys = DARWIN ]
	then
		echo "resource_monitor IS supported on ${build_sys}"
		include_package_resource_monitor="resource_monitor"
	else
		echo "resource_monitor is NOT (yet) supported on ${build_sys}"
		include_package_resource_monitor=""
	fi
fi

install_path="$HOME/cctools"

readline_path="/usr"
globus_path="/usr"
fuse_path="/usr"
irods_path="/usr"
mysql_path="/usr"
perl_path="/usr"
python_path="/usr"
python3_path="/usr"
xrootd_path="/usr"
cvmfs_path="/usr"
uuid_path="/usr"
zlib_path="/usr"
swig_path="/usr"

xrootd_arch=auto
globus_flavor=auto

ccompiler=gcc
cxxcompiler=g++

ccflags="-D__EXTENSIONS__ -D_LARGEFILE64_SOURCE -D__LARGE64_FILES -Wall -Wextra"

config_readline_path=auto
config_globus_path=auto
config_fuse_path=auto
config_mysql_path=auto
config_perl_path=auto
config_python_path=auto
config_python3_path=auto
config_zlib_path=yes

config_irods_path=no
config_xrootd_path=no
config_cvmfs_path=no
config_swig_path=auto

if [ "X${GLOBUS_LOCATION}" != "X" ]
then
	globus_path=${GLOBUS_LOCATION}
fi

IFS=" ="
export IFS

while [ $# -gt 0 ]
do
	case $1 in
		--debug)
			optdebug=1
			optstrict=1
			;;
		--prefix)
			shift
			install_path=$1
			;;
		--strict)
			optstrict=1
			;;
		--with-globus-path)
			shift
			globus_path=$1
			config_globus_path=yes
			;;
		--globus-flavor)
			shift
			globus_flavor=$1
			;;
		--with-readline-path)
			shift
			readline_path=$1
			config_readline_path=yes
			;;
		--with-fuse-path)
			shift
			fuse_path=$1
			config_fuse_path=yes
			;;
		--with-irods-path)
			shift
			irods_path=$1
			config_irods_path=yes
			;;
		--with-mysql-path)
			shift
			mysql_path=$1
			config_mysql_path=yes
			;;
		--with-perl-path)
			shift
			perl_path=$1
			config_perl_path=yes
			;;
		--with-python-path)
			shift
			python_path=$1
			config_python_path=yes
			;;
		--with-python3-path)
			shift
			python3_path=$1
			config_python3_path=yes
			;;
		--with-xrootd-path)
			shift
			xrootd_path=$1
			config_xrootd_path=yes
			;;
		--with-cvmfs-path)
			shift
			cvmfs_path=$1
			config_cvmfs_path=yes
			;;
		--with-uuid-path)
			shift
			uuid_path=$1
			;;
		--with-zlib-path)
			shift
			zlib_path=$1
			config_zlib_path=yes
			;;
		--with-swig-path)
			shift
			swig_path=$1
			config_swig_path=yes
			;;
		--without-system-sand)
			include_package_sand=""
			if [ $include_package_allpairs != "" ]
			then
				echo "*** skipping system 'allpairs' because of dependencies"
				include_package_allpairs=""
			fi
			;;
		--without-system-allpairs)
			include_package_allpairs=""
			;;
		--without-system-wavefront)
			include_package_wavefront=""
			;;
		--without-system-makeflow)
			include_package_makeflow=""
			;;
		--without-system-ftp-lite)
			include_package_ftplite=""
			;;
		--without-system-chirp)
			include_package_chirp=""
			;;
		--without-system-parrot)
			include_package_parrot=""
			;;
		--without-system-resource_monitor)
			include_package_resource_monitor=""
			;;
		--without-system-resource_monitor_visualizer)
			include_package_resource_monitor_visualizer=""
			;;
		--without-system-weaver)
			include_package_weaver=""
			;;
		--without-system-doc)
			include_package_doc=""
			;;
		--xrootd-arch)
			shift
			xrootd_arch=$1
			;;
		--with-*-path)
			echo "ignoring unknown package $1"
			shift
			;;
		--tcp-low-port)
			shift
			ccflags="${ccflags} -DTCP_LOW_PORT_DEFAULT=$1"
			;;
		--tcp-high-port)
			shift
			ccflags="${ccflags} -DTCP_HIGH_PORT_DEFAULT=$1"
			;;
		-h | -help | --h | --help)
			cat <<EOF
Use: configure [options]
Where options are:
  --help
  --prefix             <path>
  --debug
  --strict
  --globus-flavor      <flavor>
  --xrootd-arch        <arch>
  --tcp-low-port       <port>
  --tcp-high-port      <port>
  --with-PACKAGE-path  <path>
  --without-system-SYSTEM

Where PACKAGE may be:
    readline
    fuse
    globus
    irods
    mysql
    perl
    python
    python3
    xrootd
    zlib
    cvmfs
    uuid
    swig

And SYSTEM may be:
    sand
    allpairs
    wavefront
    makeflow
    ftp-lite
    chirp
    parrot
    resource_monitor
    resource_monitor_visualizer
    doc
EOF
			exit 0
			;;
		*)
			echo "Unknown argument $1"
			exit 1
			;;
	esac
	shift
done

if [ "$optstrict" = 1 ]; then
	ccflags="${ccflags} -Werror"
fi

IFS=" "
export IFS

potential_packages="dttools ${include_package_makeflow} work_queue ${include_package_sand} ${include_package_allpairs} ${include_package_wavefront} ${include_package_ftplite} ${include_package_parrot} ${include_package_resource_monitor} ${include_package_resource_monitor_visualizer} ${include_package_chirp} ${include_package_weaver} ${include_package_doc}"

check_multiarch

rm -f config.mk
echo "checking for all the things I know how to build..."
for p in $potential_packages
do
	if [ -d $p ]
	then
		echo "package $p found"
		packages="${packages} $p"
		if [ -d `pwd`/$p/src ]
		then
			internal_ccflags="${internal_ccflags} -I`pwd`/$p/src"
		fi
	else
		echo "package $p not found (that's ok)"
	fi
done

require_path ${ccompiler}
require_path ${cxxcompiler}
require_gnu_make

# Lots of warnings are enabled by default, but several are too strict
# and crop up in third-party code, so we disable those checks.
# However, not all compilers support these flags, so we check each one.

for flag in no-unused-parameter no-unknown-pragmas no-deprecated-declarations no-unused-const-variable
do
	if check_compiler_flag -W$flag
	then
		ccflags="${ccflags} -W$flag"
	fi
done

# Cygwin has some compiler oddities.
# 1 - Sloppy definitions of the ctype.h functions cause spurious warnings
# about char -> int conversions.
# 2 - All code is PIC by default, and adding the flag causes more warnings.

if [ ${build_sys} = CYGWIN ]
then
	ccflags="${ccflags} -Wno-char-subscripts"
else
	ccflags="${ccflags} -fPIC"
fi

#
# Currently, we rely on the linker --as-needed flag to sort out
# which dynamic libraries each executable actually needs.
# This is apparently a recent addition to gnu ld.
# A better solution would be to explicitly specify which libraries
# are needed by which executable, but this will come in a later version.
#

echon "checking if ld supports the --as-needed flag..."
if ld --help 2>&1 | grep -- --as-needed 2>&1 >/dev/null 
then
        echo "yes"
        link_as_needed="-Xlinker --as-needed"
        link_no_as_needed="-Xlinker --no-as-needed"
else
        echo "no"
fi

if [ $build_sys = LINUX ]
then
        ldflags="-Xlinker -Bstatic -static-libgcc -Xlinker -Bdynamic ${link_as_needed}"
elif [ $build_sys = DARWIN ]
then
        ldflags=""
else
        ldflags="-static-libgcc"
fi

##########################################################################
# SWITCH TO STATIC LINKING FOR UNCOMMON THIRD-PARTY PACKAGES
##########################################################################
library_search_mode=prefer_static
##########################################################################

if [ x$globus_flavor = xauto ]
then
	if [ $build_cpu = X86_64 ] 
	then
		globus_flavor=gcc64
	else
		globus_flavor=gcc32
	fi
fi

echo "using a globus flavor of '$globus_flavor' (if this is wrong, use the --globus-flavor argument)"

if [ $config_globus_path != no ]
then
	if check_file ${globus_path}/include/${globus_flavor}/globus_common.h
	then
		ccflags="${ccflags} -I${globus_path}/include -I${globus_path}/include/${globus_flavor} -DHAS_GLOBUS_GSS"
		ldflags="${ldflags} -L${globus_path}/lib64 -L${globus_path}/lib"
		for library in globus_gss_assist globus_gssapi_gsi globus_gsi_proxy_core globus_gsi_credential globus_gsi_callback globus_oldgaa globus_gsi_sysconfig globus_gsi_cert_utils globus_openssl globus_openssl_error globus_callout globus_proxy_ssl globus_common ltdl
		do
			library_search ${library}_${globus_flavor} ${globus_path}
		done
	elif check_file ${globus_path}/include/globus/globus_common.h
	then
		ccflags="${ccflags} -I${globus_path}/lib/globus/include -I${globus_path}/include/globus -DHAS_GLOBUS_GSS"
		ldflags="${ldflags} -L${globus_path}/lib64 -L${globus_path}/lib"
		for library in globus_gss_assist globus_gssapi_gsi globus_gsi_proxy_core globus_gsi_credential globus_gsi_callback globus_oldgaa globus_gsi_sysconfig globus_gsi_cert_utils globus_openssl globus_openssl_error globus_callout globus_proxy_ssl globus_common ltdl
		do
			library_search $library ${globus_path}
		done
	else
		if [ $config_globus_path = yes ]
		then
			echo "*** Sorry, I couldn't find Globus in $globus_path"
			echo "*** Check --with-globus-path and try again."
			exit 1
		else
			echo "*** skipping globus support"
		fi
	fi
else
	echo "*** skipping globus support"
fi

# irods 4.0 moved all its source to the iRODS subdirectory

if [ $config_irods_path != no ]
then
	if library_search RodsAPIs "${irods_path}/lib/core/obj"
	then
		echo "detected irods 3.x installation"

		ccflags="${ccflags} -DHAS_IRODS"

		for d in ${irods_path}/lib/*/include ${irods_path}/server/*/include
		do
			ccflags="${ccflags} -I$d"
		done

	elif library_search RodsAPIs "${irods_path}/iRODS/lib/core/obj"
	then
		echo "detected irods 4.x installation"

		# irods 4.x uses .so plugins which are found in /var/lib/irods.
		# These require the parrot is linked with -rdynamic so that
		# the plugins can refer to symbols in libRodsAPI.a in parrot.

		# irods 4.x changed the API from C to C++, so we must look
		# for .hpp files instead of .h files.

		ccflags="${ccflags} -DHAS_IRODS -DIRODS_USES_PLUGINS -DIRODS_USES_HPP"
		ldflags="-rdynamic"

		echo "*** warning: irods 4.0 requires plugins installed in /var/lib"

		for d in ${irods_path}/iRODS/lib/*/include ${irods_path}/iRODS/server/*/include
		do
			ccflags="${ccflags} -I$d"
		done

		# irods 4.x depends on a specific version of boost:

		boost_path=`ls -d ${irods_path}/external/boost_*`
		if [ ! -d ${boost_path} ]
		then
			echo "*** Could not find irods boost in ${irods_path}/external !"
			exit 1
		fi

		echo "found irods boost in $boost_path"
		boost_lib="${boost_path}/stage/lib"
		for subtype in system thread chrono filesystem regex
		do
			lib=${boost_lib}/libboost_${subtype}.a
			if [ -f $lib ]
			then
				echo "found $lib"
				external_archives="${external_archives} $lib"
			fi
		done

		jansson_path=`ls -d ${irods_path}/external/jansson-*`
		if [ ! -d ${jansson_path} ]
		then
			echo "*** Could not find irods jansson in ${irods_path}/external !"
			exit 1
		fi

		echo "found irods jansson in $jansson_path"
		jansson_lib="${jansson_path}/src/.libs"
		external_archives="${external_archives} ${jansson_lib}/libjansson.a"

	elif [ $config_irods_path = yes ]
	then
		echo "*** Sorry, I couldn't find IRODS in $irods_path"
		echo "*** Check --with-irods-path and try again."
		exit 1
	else
		echo "*** skipping irods support"
	fi
else
	echo "*** skipping irods support"
fi

if [ $config_mysql_path != no ] && library_search mysqlclient ${mysql_path} mysql
then
	if [ ${mysql_path} != /usr ]
	then
		ccflags="${ccflags} -I${mysql_path}/include"
	fi

	ccflags="${ccflags} -DHAS_MYSQL -DHAS_BXGRID"
else
	if [ $config_mysql_path = yes ]
	then
		echo "*** Sorry, I couldn't find MySQL in $mysql_path"
		echo "*** Check --with-mysql-path and try again."
		exit 1
	else
		echo "*** skipping mysql support"
	fi
fi

config_xrootd_success=1
if [ $config_xrootd_path != no ]
then
	if [ x$xrootd_arch = xauto ]
	then
		if [ $build_cpu = X86_64 ] 
		then
			xrootd_arch=x86_64_linux_26
		else
			xrootd_arch=i386_linux26
		fi
	fi
	
	echo "using an xrootd arch of '$xrootd_arch' (if this is wrong, use the --xrootd-arch argument)"
	if check_file ${xrootd_path}/include/xrootd/XrdVersion.hh
	then
	    for library in XrdPosix XrdClient XrdSys XrdNet XrdNetUtil XrdOuc
	    do
		if ! library_search $library ${xrootd_path} ${xrootd_arch}
		then
		    echo "*** Couldn't find $library in ${xrootd_path}"
		    config_xrootd_success=0
		fi
	    done
	else
	    config_xrootd_success=0
	fi
else
    config_xrootd_success=0
fi

if [ $config_xrootd_success = 1 ]
then
    ccflags="${ccflags} -I${xrootd_path}/include/xrootd -DHAS_XROOTD"
else
    echo "*** skipping xrootd support"
    
    if [ $config_xrootd_path = yes ]
    then
	echo "*** Sorry, I couldn't find xrootd in ${xrootd_path}"
	echo "*** Check --with-xrootd-path and try again."
	exit 1
    fi
fi



config_cvmfs_success=1
if [ $config_cvmfs_path != no ]
then
    if check_file ${cvmfs_path}/include/libcvmfs.h
    then
	for library in cvmfs 
	do
		if ! library_search $library ${cvmfs_path}
		then
			echo "*** Couldn't find $library in ${cvmfs_path}"
			config_cvmfs_success=0
		fi
	done
    else
	config_cvmfs_success=0
    fi
else
    config_cvmfs_success=0
fi

if [ $config_cvmfs_success = 1 ]
then
	cvmfs_version=$(sed -n 's/^#define LIBCVMFS_VERSION \+\([0-9]\+\)/\1/p' ${cvmfs_path}/include/libcvmfs.h)
	if [ $cvmfs_version -gt 1 ] 
	then
		if ! library_search uuid $uuid_path
		then
			echo "*** Couldn't find libuuid"
			echo "*** Check --with-uuid-path and try again."
			exit 1
		fi
	fi
fi

if [ $config_cvmfs_success = 1 ]
then
   ccflags="${ccflags} -I${cvmfs_path}/include -DHAS_CVMFS"
else
    if [ $config_cvmfs_path = yes ]
    then
	echo "*** Sorry, I couldn't find cvmfs in ${cvmfs_path}"
	echo "*** Check --with-cvmfs-path and try again."
	exit 1
    else
	echo "*** skipping cvmfs support"
    fi
fi

config_fuse_success=1
if [ $config_fuse_path != no ]
then
    if check_file ${fuse_path}/include/fuse.h
    then
	for library in fuse
	do
		if ! library_search $library ${fuse_path}
		then
		    echo "*** Couldn't find $library in ${fuse_path}"
		    config_fuse_success=0
		fi
	done
    else
	config_fuse_success=0
    fi
else
    config_fuse_success=0
fi

if [ $config_fuse_success = 1 ]
then
    ccflags="${ccflags} -I${fuse_path}/include -DHAS_FUSE"
else
	if [ $config_fuse_path = yes ]
	then
		echo "*** Sorry, I couldn't find Fuse in $fuse_path"
		echo "*** Check --with-fuse-path and try again."
		exit 1
	else
		echo "*** skipping fuse support"
	fi
fi

##########################################################################
# SWITCH BACK TO DYNAMIC LINKING FOR COMMON SYSTEM LIBRARIES
##########################################################################
library_search_mode=prefer_dynamic
##########################################################################

if [ $config_readline_path != no ] && library_search readline ${readline_path}
then
	if [ ${readline_path} != /usr ]
	then
		ccflags="${ccflags} -I${readline_path}/include"
	fi
	
	ccflags="${ccflags} -DHAS_LIBREADLINE"

	# We rely on the --as-needed flag to figure out what dynamic
	# libraries are actually used by each executable.
	# However, libreadline doesn't properly specify a dependency
	# on ncurses, termcap, and history, so we must force them to link.

	if [ $build_sys = LINUX ]
	then
		# Remove the -lreadline that was added by "library_search readline" above
		ldflags=`echo $ldflags | sed "s/-lreadline//"`

		# Put the readline flags in a separate variable to be used only where needed.
		cctools_readline_ldflags="-lreadline ${link_no_as_needed} -lncurses -lhistory ${link_as_needed}"
	else 
		library_search ncurses ${readline_path}
		library_search termcap ${readline_path}
		library_search history ${readline_path}
	fi
else	
	echo "*** skipping readline..."
fi


if [ $config_perl_path != no ]
then
	if check_file ${perl_path}/bin/perl
	then
		perl=${perl_path}/bin/perl
	else
		perl=0
	fi

	if [ $perl != 0 ]
	then
		perl_version=`${perl} -e 'printf "%vd\n",$^V;'`
		if [ $? = 0 ]
		then
			echo "perl version is ${perl_version}"
		else
			perl=0
		fi
	fi

	if [ $perl != 0 ]
	then
		perl_ccflags=`${perl} -MExtUtils::Embed -e ccopts`
		perl_ldflags=`${perl} -MExtUtils::Embed -e ldopts`

		if [ $? = 0 ]
		then
			# On OSX, the ExtUtils::Embed options contain options
			# to generate triple-fat binaries, which fails when
			# we attempt to bring in our thin binaries.

			# To avoid this problem, remove all of the -arch XXX
			# arguments, so that the compiler produces the default,
			# which will be compatible with the other objects we compile.

			if [ ${build_sys} = DARWIN ]
			then
				perl_ccflags=`echo ${perl_ccflags} | sed 's/-arch [^ ]* *//g'`
				perl_ldflags=`echo ${perl_ldflags} | sed 's/-arch [^ ]* *//g'`
			fi

			work_queue_bindings="$work_queue_bindings perl"
		else
			perl=0
		fi
	fi

	if [ $perl = 0 ]
	then
                if [ $config_perl_path = yes ]
                then
                        echo "*** Sorry, I couldn't find the perl libraries in $perl_path"
                        echo "*** Check --with-perl-path and try again."
                        exit 1
                else
                        echo "*** skipping perl support"
                fi
	fi
fi

if [ $config_python_path != no ]
then
	if [ -n "$PYTHON" ] && check_file ${PYTHON}
	then	
		python=${PYTHON}
	elif check_file ${python_path}/bin/python2
	then	
		python=${python_path}/bin/python2
	elif check_file ${python_path}/bin/python
 	then
		python=${python_path}/bin/python
	else
		python=0
	fi

	if [ $python != 0 ]
	then
		python_version=`${python} -V 2>&1 | cut -d " " -f 2`
		echo "python version is ${python_version}"
		python_major_version=`echo ${python_version} | cut -d . -f 1`
		python_minor_version=`echo ${python_version} | cut -d . -f 2 | cut -d . -f 1,2`
		if [ "$python_major_version" -eq 2 -a "$python_minor_version" -ge 4 ]
		then
			if check_file ${python_path}/include/python2.$python_minor_version/Python.h
			then
				echo "found python development libraries"
				python_ccflags_file=`mktemp tmp.XXXXXX`
				python_ldflags_file=`mktemp tmp.XXXXXX`

				env HOME=/var/empty ${python} > $python_ccflags_file <<EOF
from distutils import sysconfig
flags = ['-I' + sysconfig.get_python_inc(),
	 '-I' + sysconfig.get_python_inc(plat_specific=True)]
syscfgflags = sysconfig.get_config_var('CFLAGS')
if not syscfgflags is None:
    flags.extend(syscfgflags.split())
print ' '.join(flags)
EOF
				env HOME=/var/empty ${python} > $python_ldflags_file <<EOF
from distutils import sysconfig
libs = sysconfig.get_config_var('LIBS').split() + sysconfig.get_config_var('SYSLIBS').split()
if not sysconfig.get_config_var('Py_ENABLE_SHARED'):
    libs.insert(0, '-L' + sysconfig.get_config_var('LIBPL'))
print ' '.join(libs)
EOF
				python_ccflags=`cat $python_ccflags_file`
				python_ldflags=`cat $python_ldflags_file`
				rm $python_ccflags_file
				rm $python_ldflags_file

				# On OSX, the ExtUtils::Embed options contain options
				# to generate triple-fat binaries, which fails when
				# we attempt to bring in our thin binaries.

				# To avoid this problem, remove all of the -arch XXX
				# arguments, so that the compiler produces the default,
				# which will be compatible with the other objects we compile.

	                        if [ ${build_sys} = DARWIN ]
				then
					python_ccflags=`echo ${python_ccflags} | sed 's/-arch [^ ]* *//g'`
					python_ldflags=`echo ${python_ldflags} | sed 's/-arch [^ ]* *//g'`
				fi

				if [ $build_sys = DARWIN ]
				then
				    python_ldflags="$python_ldflags -undefined dynamic_lookup"
				fi

				work_queue_bindings="$work_queue_bindings python"
			else
				python=0
			fi
		else
			echo "*** Sorry, we require Python >= 2.4"
			python=0
		fi
	fi

	if [ $python = 0 ]
	then
                if [ $config_python_path = yes ]
                then
                        echo "*** Sorry, I couldn't find the Python >= 2.4 libraries in $python_path"
                        echo "*** Check --with-python-path and try again."
                        exit 1
                else
                        echo "*** skipping python support"
                fi
	fi
fi


# If python is not found, then leave out weaver.
if [ $python != 0 -a $python_major_version = 2 -a $python_minor_version -ge 6 ]
then
	echo "python version is suitable for weaver"
else
	echo "weaver requires python >= 2.6"
	packages=`echo ${packages} | sed 's/weaver//g'`
fi

if [ $config_python3_path != no ]
then
	if [ -n "$PYTHON3" ] && check_file ${PYTHON3}
	then
		python3=${PYTHON3}
	elif check_file ${python3_path}/bin/python3
	then
		python3=${python3_path}/bin/python3
	elif check_file ${python3_path}/bin/python
	then
		python3=${python3_path}/bin/python
	else
		python3=0
	fi

	if check_file ${python3_path}/bin/2to3
	then
		python3_2to3=${python3_path}/bin/2to3
	else
		python3=0
	fi

	if [ $python3 != 0 ]
	then
		python3_version=`${python3} -V 2>&1 | cut -d " " -f 2`
		echo "python3 version is ${python3_version}"
		python3_major_version=`echo ${python3_version} | cut -d . -f 1`
		python3_minor_version=`echo ${python3_version} | cut -d . -f 2 | cut -d . -f 1,2`
		if [ "$python3_major_version" -eq 3 ]
		then
			python3_include=`${python3} -c 'from distutils import sysconfig; print(sysconfig.get_python_inc())'`
			if check_file ${python3_include}/Python.h && check_file ${python3}-config
			then
				echo "found python3 development libraries"
				python3_ccflags=`${python3}-config --cflags`
				python3_ldflags=`${python3}-config --ldflags`

				# On OSX, the ExtUtils::Embed options contain options
				# to generate triple-fat binaries, which fails when
				# we attempt to bring in our thin binaries.

				# To avoid this problem, remove all of the -arch XXX
				# arguments, so that the compiler produces the default,
				# which will be compatible with the other objects we compile.

				if [ ${build_sys} = DARWIN ]
				then
					python3_ccflags=`echo ${python3_ccflags} | sed 's/-arch [^ ]* *//g'`
					python3_ldflags=`echo ${python3_ldflags} | sed 's/-arch [^ ]* *//g'`
				fi

				if [ $build_sys = DARWIN ]
				then
				    python3_ldflags="$python3_ldflags -undefined dynamic_lookup"
				fi

				work_queue_bindings="$work_queue_bindings python3"
			else
				python3=0
			fi
		else
			echo "*** Sorry, we require Python3 >= 3.0"
			python3=0
		fi
	fi

	if [ $python3 = 0 ]
	then
		if [ $config_python3_path = yes ]
		then
			echo "*** Sorry, I couldn't find the Python3 >= 3.0 libraries in $python3_path"
			echo "*** Check --with-python3-path and try again."
			exit 1
		else
			echo "*** skipping python3 support"
		fi
	fi
fi

found_swig=no
if [ $config_swig_path != no ]
then
	swig=""
	if check_file ${swig_path}/bin/swig
	then
		swig=${swig_path}/bin/swig
	else
		if check_path swig
		then
			swig=`which swig`
		else
			echo "*** skipping swig bindings for work queue"
		fi
	fi

	if [ -n "$swig" ]
	then
		swig_version=`${swig} -version | grep -i version | awk '{print $3}'`
		if [ "$python" != 1 -a ! \( "$python_major_version" -eq 2 -a "$python_minor_version" -eq 4 \) -a `format_version $swig_version` -eq `format_version 1.3.29` ]
		then
			echo "*** Sorry, Swig 1.3.29 does not work with Python $python_version."
			echo "*** skipping swig bindings for work queue"
		elif [ "$python3" != 0 -a `format_version $swig_version` -lt `format_version 2.0.4` ]
		then
			# Python 3 requires Swig version >= 2.0.4; cf.
			# http://sourceforge.net/p/swig/bugs/1104/ and
			# http://sourceforge.net/p/swig/news/?page=1
			echo "*** Sorry, Swig $swig_version does not work with Python 3 version $python3_version."
			echo "*** Specifically, Swig >= 2.0.4 is needed for Python 3 support."
			echo "*** skipping swig bindings for work queue"
		elif [ `format_version $swig_version` -ge `format_version 1.3.29` ]
		then
			found_swig=yes
		else
			echo "*** Sorry, I need swig >= 1.3.29"
			echo "*** skipping swig bindings for work queue"
		fi
	fi
else
	if [ $config_swig_path = yes ]
	then
		echo "*** Sorry, I couldn't find swig in $swig_path"
		echo "*** Check --with=swig-path and try again."
		exit 1
	else
		echo "*** skipping swig bindings for work queue"
	fi
fi

if [ $found_swig != yes ]
then
	work_queue_bindings=""
fi

linker="gcc"

library_search ssl	/usr
library_search crypto	/usr
library_search resolv   /usr
library_search socket   /usr
library_search nsl      /usr

# Finally, add in standard system libraries found everywhere

if [ $build_sys != DARWIN ]
then
	external_dynlibs="${external_dynlibs} -lrt"
fi

if [ $build_sys != FREEBSD ]
then
	external_dynlibs="${external_dynlibs} -ldl"
fi

if library_search z ${zlib_path}
then
	if [ X${zlib_path} != X/usr ]
	then
		    
		ccflags="${ccflags} -I${zlib_path}/include"
		ldflags="${ldflags} -L${zlib_path}/lib"
	fi
else
	echo "*** Sorry, I couldn't find zlib in $zlib_path"
	echo "*** Check --with-zlib-path and try again."
	exit 1
fi

if [ ${build_sys} != CYGWIN ]
then
	external_dynlibs="${external_dynlibs} -lstdc++ -lpthread -lz -lc -lm"
else
	external_dynlibs="${external_dynlibs} -lstdc++ -lpthread -lz -lm"
fi

if [ $build_sys = DARWIN ]
then
	cctools_dynamic_suffix=dylib
	cctools_dynamic_flag=-dynamiclib
else
	cctools_dynamic_suffix=so
	cctools_dynamic_flag=-shared
fi

# sqlite3 uses define "HAVE_*"
optional_function isnan /usr/include/math.h HAS_ISNAN HAVE_ISNAN SQLITE_HAVE_ISNAN
optional_function pread /usr/include/unistd.h HAS_PREAD
optional_function pwrite /usr/include/unistd.h HAS_PWRITE
optional_function strsignal /usr/include/string.h HAS_STRSIGNAL
optional_function usleep /usr/include/unistd.h HAS_USLEEP HAVE_USLEEP
optional_function utime /usr/include/utime.h HAS_UTIME HAVE_UTIME

# sqlite3 uses define "HAVE_*"
optional_include attr/xattr.h HAS_ATTR_XATTR_H
optional_include fts.h HAS_FTS_H
optional_include inttypes.h HAS_INTTYPES_H HAVE_INTTYPES_H
optional_include stdint.h HAS_STDINT_H HAVE_STDINT_H
optional_include sys/statfs.h HAS_SYS_STATFS_H
optional_include sys/statvfs.h HAS_SYS_STATVFS_H
optional_include sys/xattr.h HAS_SYS_XATTR_H
optional_include syslog.h HAS_SYSLOG_H


#if optional_library_function systemd/sd-journal.h sd_journal_print systemd HAS_SYSTEMD_JOURNAL_H; then
#	external_dynlibs="${external_dynlibs} -lsystemd"
#fi

cctools_doctargets=

if check_path doxygen
then
	cctools_doctargets="${cctools_doctargets} apipages"
else
	echo "*** not building API documentation"
fi

if check_path m4
then
	cctools_doctargets="${cctools_doctargets} htmlpages"
	if check_path nroff
	then
		cctools_doctargets="${cctools_doctargets} manpages"
	else
		echo "*** not building man pages"
	fi
else
	echo "*** not building html or man pages"
fi

# We always compile with debugging enabled,
# however on Solaris, the -g option results in a different
# debugging format that causes linking errors in getopt code.

if [ $build_sys = SUNOS ]
then
	debug_flag="-gstabs+"
else
	debug_flag="-g"
fi

ccflags="${ccflags} -DINSTALL_PATH='\"${install_path}\"' $debug_flag -D_REENTRANT -D_GNU_SOURCE -DBUILD_USER='\"$build_user\"' -DBUILD_HOST='\"$build_host\"' -DCCTOOLS_VERSION_MAJOR=$major -DCCTOOLS_VERSION_MINOR=$minor -DCCTOOLS_VERSION_MICRO='\"$micro\"' -DCCTOOLS_VERSION='\"$version\"' -DCCTOOLS_RELEASE_DATE='\"$release_date\"' -DCCTOOLS_CONFIGURE_ARGUMENTS='\"$configure_arguments\"' -DCCTOOLS_SYSTEM_INFORMATION='\"$system_information\"' -DCCTOOLS_OPSYS_${build_sys} -DCCTOOLS_CPU_${build_cpu}"
ldflags="${ldflags} ${debug_flag}"

if [ X$include_package_parrot = "Xparrot" ]
then

	cat <<EOF > libparrot.test.c
int main() { return 0; }
EOF
	echon "testing creation of 64-bit libparrot_helper.so..."
	$ccompiler $internal_ccflags -m64 libparrot.test.c -o libparrot.test > /dev/null 2>&1 
	if [ $? = 0 ]
	then
		build_lib64parrot_helper="yes"
	else
		build_lib64parrot_helper="no"
	fi
	echo $build_lib64parrot_helper

	echon "testing creation of 32-bit libparrot_helper.so..."
	$ccompiler $internal_ccflags -m32 libparrot.test.c -o libparrot.test > /dev/null 2>&1 
	if [ $? = 0 ]
	then
		build_lib32parrot_helper="yes"
	else
		build_lib32parrot_helper="no"
	fi
	echo $build_lib32parrot_helper

	rm -f libparrot.test.c libparrot.test
fi


echo "Creating config.mk..."

if [ "$optdebug" = 1 ]; then
	CCTOOLS_CC="${ccompiler}"
	CCTOOLS_CXX="${cxxcompiler}"
	CCTOOLS_LD="${linker}"
else
	CCTOOLS_CC='@echo COMPILE $@;'"${ccompiler}"
	CCTOOLS_CXX='@echo COMPILE $@;'"${cxxcompiler}"
	CCTOOLS_LD='@echo LINK $@;'"${linker}"
fi

cat <<EOF >>config.mk
# Generated at `date` by $USER@`uname -n`

CCTOOLS_INSTALL_DIR=${install_path}
CCTOOLS_PACKAGES=${packages}

CCTOOLS_CC=${CCTOOLS_CC}

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=${CCTOOLS_CXX}

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 = ${CCTOOLS_LD}

CCTOOLS_BASE_LDFLAGS = ${ldflags}

CCTOOLS_INTERNAL_LDFLAGS = \$(CCTOOLS_BASE_LDFLAGS) ${internal_ldflags}

CCTOOLS_EXTERNAL_LINKAGE = ${external_archives} ${external_dynlibs}

CCTOOLS_LDFLAGS = -L\$(CCTOOLS_INSTALL_DIR)/lib \$(CCTOOLS_BASE_LDFLAGS)

CCTOOLS_READLINE_LDFLAGS=${cctools_readline_ldflags}

CCTOOLS_DYNAMIC_SUFFIX=${cctools_dynamic_suffix}
CCTOOLS_DYNAMIC_FLAG=${cctools_dynamic_flag}

CC=\$(CCTOOLS_CC)
CCFLAGS=\$(CCTOOLS_CCFLAGS)
LD=\$(CCTOOLS_LD)
LDFLAGS=\$(CCTOOLS_LDFLAGS)
CXX=\$(CCTOOLS_CXX)
CXXFLAGS=\$(CCTOOLS_CXXFLAGS)

CCTOOLS_AR=ar

CCTOOLS_SWIG=${swig}

CCTOOLS_PERL=${perl}
CCTOOLS_PERL_CCFLAGS=${perl_ccflags}
CCTOOLS_PERL_LDFLAGS=${perl_ldflags}
CCTOOLS_PERL_VERSION=${perl_version}

CCTOOLS_PYTHON=${python}
CCTOOLS_PYTHON_CCFLAGS=${python_ccflags}
CCTOOLS_PYTHON_LDFLAGS=${python_ldflags}
CCTOOLS_PYTHON_VERSION=${python_major_version}.${python_minor_version}

CCTOOLS_PYTHON3=${python3}
CCTOOLS_PYTHON3_CCFLAGS=${python3_ccflags}
CCTOOLS_PYTHON3_LDFLAGS=${python3_ldflags}
CCTOOLS_PYTHON3_VERSION=${python3_major_version}.${python3_minor_version}
CCTOOLS_PYTHON3_2TO3=${python3_2to3}

CCTOOLS_WORK_QUEUE_BINDINGS=${work_queue_bindings}

CCTOOLS_DOCTARGETS=${cctools_doctargets}

CCTOOLS_M4_ARGS=-DCCTOOLS_VERSION=${major}.${minor}.${micro} -DCCTOOLS_RELEASE_DATE=${release_date}

CCTOOLS_BUILD_LIB64PARROT_HELPER=${build_lib64parrot_helper}
CCTOOLS_BUILD_LIB32PARROT_HELPER=${build_lib32parrot_helper}

CCTOOLS_VERSION=${version}
CCTOOLS_RELEASEDATE=${release_date}

EOF

echo ""
echo "To re-configure, type './configure.rerun'"
echo "To build, type '${MAKE}'"
echo "To build and install, type '${MAKE} install'"
echo ""

exit 0

# vim: set noexpandtab tabstop=4:
back to top