From e64da1f791f180a99ee6f598ef5fbeae6e3ec119 Mon Sep 17 00:00:00 2001 From: "Eric J. Korpela" Date: Thu, 28 Apr 2005 21:42:05 +0000 Subject: [PATCH] New autoconf macros: SAH_CHECK_LIB: Like AC_CHECK_LIB(), except it checks STATIC_LIB_LIST for libraries that should be linked statically. Static libraries are attempted to be linked with fully qualified path. If that fails, the static flags (-Wl,-Bstatic) are used. If no static library is found, the library is linked dynamically. SAH_STATICIZE_LDFLAGS: Goes through a given set of LDFLAGS and determines with libraries should be linked statically based upon STATIC_LIB_LIST, then calls SAH_CHECK_LIB on every library. SAH_DEFAULT_BITNESS: On architectures that support both 32 and 64 bit executables, this determines the current default model (including any CFLAGS settings). SAH_OPTION_BITNESS: Sets up a configure option to set the compiler -m64 or -m32 (or equivalent) flags for 32/64 bit compilation. svn path=/trunk/boinc/; revision=5957 --- m4/sah_check_lib.m4 | 449 ++++++++++++++++++++++++++++++++++++ m4/sah_grx.m4 | 9 +- m4/sah_libext.m4 | 33 +++ m4/sah_select_bitness.m4 | 56 +++++ m4/sah_staticize_ldflags.m4 | 41 ++++ 5 files changed, 586 insertions(+), 2 deletions(-) create mode 100644 m4/sah_check_lib.m4 create mode 100644 m4/sah_libext.m4 create mode 100644 m4/sah_select_bitness.m4 create mode 100644 m4/sah_staticize_ldflags.m4 diff --git a/m4/sah_check_lib.m4 b/m4/sah_check_lib.m4 new file mode 100644 index 0000000000..183aa45a12 --- /dev/null +++ b/m4/sah_check_lib.m4 @@ -0,0 +1,449 @@ + +AC_DEFUN([SAH_CHECK_LIB],[ + alib="$1" + # check to see if it is in our static list + for slib in ${STATIC_LIB_LIST}; do + lib_is_static="no" + tmp_pattern=`echo s/x${slib}// | sed 's/\*/.*/'` + if test -z "`echo x${alib} | sed ${tmp_pattern}`" + then + SAH_STATIC_LIB_REQUIRED(${alib},[$2],[ + lib_is_static="yes" + sah_lib_last="${sah_static_lib_last}" + $3 + ],[$4]) + break; + fi + done + if test "${lib_is_static}" = "no" ; then + SAH_DYNAMIC_LIB_REQUIRED(${alib},[$2],[ + sah_lib_last="${sah_dynamic_lib_last}" + ],[$4]) + fi +]) + + + + +AC_DEFUN([SAH_CHECK_LDFLAG],[ + sv_ldflags="${LDFLAGS}" + AC_MSG_CHECKING(if compiler works with $1 flag) + LDFLAGS="${LDFLAGS} $1" + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([[ + #define CONFIG_TEST + int foo() {return 1;} + ]], + [ return foo(); ])], + [ + AC_MSG_RESULT(yes) + $2 + ], + [ + AC_MSG_RESULT(no) + LDFLAGS="${sv_ldflags}" + $3 + ] + ) +]) + +AC_DEFUN([SAH_LINKAGE_FLAGS],[ + AC_ARG_ENABLE(static_client, + AC_HELP_STRING([--disable-static-linkage], + [disable static linking of certain libraries]), + [ + disable_static_linkage=yes + enable_client_release=no + ], + [ + disable_static_linkage=no + enable_client_release=yes + ]) + if test "${disable_static_linkage}" = "yes" + then + ld_static_option="" + ld_dynamic_option="" + LD_EXPORT_DYNAMIC="" + else + if test -z "${ld_static_option}" + then + case $target in + *linux* | *solaris* | *cygwin* ) + AC_MSG_CHECKING([${CC} flags for static linkage ...]) + ld_static_option="-Wl,-Bstatic" + AC_MSG_RESULT($ld_static_option) + AC_MSG_CHECKING([${CC} flags for dynamic linkage ...]) + ld_dynamic_option="-Wl,-Bdynamic" + AC_MSG_RESULT($ld_dynamic_option) + ;; + *) + if test -z "${dummy_ld_variable_gfdsahjf}" + then + dummy_ld_variable_gfdsahjf="been there done that" + AC_MSG_CHECKING([${CC} flags for static linkage ...]) + AC_MSG_RESULT(unknown) + AC_MSG_CHECKING([${CC} flags for dynamic linkage ...]) + AC_MSG_RESULT(unknown) + fi + ;; + esac + AC_MSG_CHECKING([${CC} flags for exporting dynamic symbols from an executable ...]) + case $target in + *cygwin*) + LD_EXPORT_DYNAMIC="-Wl,--export-all-symbols" + AC_MSG_RESULT(${LD_EXPORT_DYNAMIC}) + ;; + *linux*) + AC_MSG_RESULT(-rdynamic) + LD_EXPORT_DYNAMIC="-rdynamic" + ;; + *) + AC_MSG_RESULT(none required) + LD_EXPORT_DYNAMIC= + ;; + esac + fi + fi + if test -z "${LIBEXT}"; + then + SAH_LIBEXT + fi + if test -z "${DLLEXT}"; + then + SAH_DLLEXT + fi + AC_SUBST(LD_EXPORT_DYNAMIC) +]) + + +# use this function in order to find a library that we require to be static. +# we will check in the following order.... +# 1) files named lib{name}.a +# 2) files named {name}.a +# 3) linking with the static flags "$STATIC_FLAGS -l{name}" +AC_DEFUN([SAH_STATIC_LIB_REQUIRED],[ +SAH_LINKAGE_FLAGS +# upercase the library name for our definition +ac_uc_defn=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` +# Build our cache variable names +STATIC_LIB_LIST="${STATIC_LIB_LIST} $1" +varname=`echo sah_cv_static_lib_$1_$2 | $as_tr_sh` +var2=`echo sah_cv_static_lib_$1_fopen | $as_tr_sh` +if test "$2" != "fopen" ; then + tmp_msg="for $2 in static library $1" +else + tmp_msg="for static library $1" +fi +AC_CACHE_CHECK([$tmp_msg], + [$varname], +[ + tmp_res="no" +# +# check if we want to actually do all this. + if test "${disable_static_linkage}" = "yes" + then + sah_static_checklibs="-l$1" + else + sah_static_checklibs="lib$1.${LIBEXT} $1.${LIBEXT} -l$1" + fi + sah_save_libs="${LIBS}" + for libname in ${sah_static_checklibs} + do + SAH_FIND_STATIC_LIB(${libname}) + if test -n "${tmp_lib_name}" + then + LIBS="${sah_save_libs} ${tmp_lib_name}" + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([[ + #define CONFIG_TEST 1 + #ifdef __cplusplus + extern "C" { + #endif + char $2 (); + #ifdef __cplusplus + } + #endif + ]], + [ $2 (); ])], + [ + tmp_res="${tmp_lib_name}" + ] + ) + fi + if test "${tmp_res}" != "no" + then + break + fi + done + LIBS="${sah_save_libs}" + eval ${varname}='"'${tmp_res}'"' + eval ${var2}='"'${tmp_res}'"' + ]) +# +# save the result for use by the caller +sah_static_lib_last="`eval echo '${'$varname'}'`" +# +if test "${sah_static_lib_last}" != "no" +then + LIBS="${LIBS} ${sah_static_lib_last}" + AC_DEFINE_UNQUOTED([$ac_uc_defn], [1], + [Define to 1 if the $1 library has the function $2] + ) + $3 +else + $4 + echo > /dev/null +fi +]) + +# use this function in order to find a library that we require to be dynamic. +# we will check in the following order.... +# 1) linking with the dynamic flags "$DYNAMIC_FLAGS -l{name}" +# 2) linking with no flags "-l{name}" +AC_DEFUN([SAH_DYNAMIC_LIB_REQUIRED],[ +SAH_LINKAGE_FLAGS +# upercase the library name for our definition +ac_uc_defn=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` +# Build our cache variable names +DYNAMIC_LIB_LIST="${DYNAMIC_LIB_LIST} $1" +varname=`echo sah_cv_dynamic_lib_$1_$2 | $as_tr_sh` +var2=`echo sah_cv_dynamic_lib_$1_fopen | $as_tr_sh` +if test "$2" != "fopen" ; then + tmp_msg="for $2 in dynamic library $1" +else + tmp_msg="for dynamic library $1" +fi +AC_CACHE_CHECK([$tmp_msg], + [$varname], +[ + tmp_res="no" +# +# check if we want to actually do all this. + if test "${disable_static_linkage}" = "yes" + then + sah_dynamic_checklibs="-l$1 -l$1.${DLLEXT}" + else + sah_dynamic_checklibs="-l$1" + fi + sah_save_libs="${LIBS}" + for libname in ${sah_dynamic_checklibs} + do + tmp_lib_name="${libname}" + LIBS="${sah_save_libs} ${ld_dynamic_option} ${tmp_lib_name}" + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([[ + #define CONFIG_TEST 1 + #ifdef __cplusplus + extern "C" { + #endif + char $2 (); + #ifdef __cplusplus + } + #endif + ]], + [ $2 (); ]) + ], + [ + tmp_res="${ld_dynamic_option} ${tmp_lib_name}" + ]) + if test "${tmp_res}" = "no" + then + tmp_lib_name="${libname}" + LIBS="${sah_save_libs} ${tmp_lib_name}" + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([[ + #define CONFIG_TEST 1 + #ifdef __cplusplus + extern "C" { + #endif + char $2 (); + #ifdef __cplusplus + } + #endif + ]], + [ $2 (); ]) + ], + [ + tmp_res="${tmp_lib_name}" + ]) + fi + done + LIBS="${sah_save_libs}" + eval ${varname}='"'${tmp_res}'"' + eval ${var2}='"'${tmp_res}'"' +]) +# +# save the result for use by the caller +sah_dynamic_lib_last="`eval echo '${'$varname'}'`" +# +if test "${sah_dynamic_lib_last}" != "no" +then + LIBS="${LIBS} ${sah_dynamic_lib_last}" + AC_DEFINE_UNQUOTED([$ac_uc_defn], [1], + [Define to 1 if the $1 library has the function $2] + ) + $3 +else + $4 + echo > /dev/null +fi +]) + +AC_DEFUN([SAH_STATIC_LIB],[ + SAH_STATIC_LIB_REQUIRED([$1],[$2]) + sah_lib_last="${sah_static_lib_last}" + if test "${sah_lib_last}" = "no" ; then + SAH_DYNAMIC_LIB_REQUIRED([$1],[$2]) + sah_lib_last=${sah_dynamic_lib_last} + fi + if test "${sah_lib_last}" != "no" ; then + $3 + echo > /dev/null + else + $4 + echo > /dev/null + fi +]) + +AC_DEFUN([SAH_DYNAMIC_LIB],[ + SAH_DYNAMIC_LIB_REQUIRED([$1],[$2]) + sah_lib_last="${sah_dynamic_lib_last}" + if test "${sah_lib_last}" = "no" ; then + SAH_STATIC_LIB_REQUIRED([$1],[$2]) + sah_lib_last=${sah_static_lib_last} + fi + if test "${sah_lib_last}" != "no" ; then + $3 + echo > /dev/null + else + $4 + echo > /dev/null + fi +]) + +#The SAH_FIND_STATIC_LIB macro searches the LD_LIBRARY_PATH or equivalent +#in order to find a static version of the library being loaded. +AC_DEFUN([SAH_FIND_STATIC_LIB],[ +# libtool sets up the variable shlibpath_var which holds the name of the +# LIB_PATH variable +tmp_libpath=`eval echo '${'$shlibpath_var'}'` + +# in cygwin, the DLLs are in the path, but the static libraries are elsewhere. +# Here's an educated guess. +if test "${shlibpath_var}" = "PATH" +then + tmp_libpath=`echo ${PATH} | sed 's/\/bin/\/lib/g'` + tmp_libpath="${tmp_libpath}:${PATH}" +fi + +gcc_version=`${CC} -v 2>&1 | grep "gcc version" | awk '{print $[]3}'` + +for gcc_host in `${CC} -v 2>&1 | grep host` --host=${ac_cv_target} +do + if test -n "`echo x$gcc_host | grep x--host=`" + then + gcc_host="`echo $gcc_host | sed 's/--host=//'`" + break + fi +done + +for dirs in `${CC} -v 2>&1 | grep prefix` --prefix=/usr/local +do + if test -n "`echo x$dirs | grep x--prefix=`" + then + gcc_prefix="`echo $dirs | sed 's/--prefix=//'`" + gcc_specs=`${CC} -v 2>&1 | grep specs | awk '{print $[]4}' | sed 's/\/specs//'` + tmp_libpath="${gcc_specs}:${gcc_prefix}/lib:${gcc_prefix}/lib/gcc-lib/${gcc_host}/${gcc_version}:${tmp_libpath}" + break + fi +done + +# Put machine/arch specific tweaks to the libpath here. +if test -z "${COMPILER_MODEL_BITS}" +then + SAH_DEFAULT_BITNESS +fi +case $target in + x86_64-*-linux*) + if test -n "${COMPILER_MODEL_BITS}" + then + tmp_pattern="s/\/lib/\/lib${COMPILER_MODEL_BITS}/g" + tmp_pattern_b="s/${COMPILER_MODEL_BITS}${COMPILER_MODEL_BITS}/${COMPILER_MODEL_BITS}/g" + abcd_q=`echo ${tmp_libpath} | sed ${tmp_pattern} | sed ${tmp_pattern_b} ` + case ${COMPILER_MODEL_BITS} in + 32) + gcc_host_dirs=`echo ${gcc_prefix}/lib/gcc*/i[3456]86*linux*/${gcc_version}` + ;; + 64) + gcc_host_dirs=`echo ${gcc_prefix}/lib/gcc-lib/x86_64*linux*/${gcc_version}` + ;; + esac + tmp_libpath="${abcd_q}:${tmp_libpath}" + for tmp_dir in ${gcc_host_dirs} + do + tmp_libpath="${tmp_dir}:${tmp_libpath}" + done + fi + ;; + sparc*-sun-solaris*) + if test -n "${COMPILER_MODEL_BITS}" + then + tmp_pattern="s/\/lib/\/lib\/${COMPILER_MODEL_BITS}/g" + tmp_pattern_b="s/${COMPILER_MODEL_BITS}\/${COMPILER_MODEL_BITS}/${COMPILER_MODEL_BITS}/g" + abcd_q=`echo ${tmp_libpath} | sed ${tmp_pattern} | sed ${tmp_pattern_b}` + case ${COMPILER_MODEL_BITS} in + 64) + tmp_arch="sparcv9" + ;; + 32) + tmp_arch= + ;; + esac + abcd_r= + for tmp_dir in `echo ${tmp_libpath} | sed 's/\:/ /g'` + do + abcd_r="${abcd_r}:${tmp_dir}/${tmp_arch}" + done + tmp_libpath="${abcd_r}:${abcd_q}:${tmp_libpath}" + fi + ;; + *) + echo > /dev/null + ;; +esac + + +if test -n "`echo x$1 | grep x-l`" +then + # in the -l case, don't search, just use the ld_static_option (usually + # -Wl,-B static + tmp_lib_name="${ld_static_option} $1" +else + # we also want to check the system config files for library dirs. + tmp_dir_list= + if test -e /etc/ld.so.conf + then + tmp_dir_list=`cat /etc/ld.so.conf` + else + if test -e /var/ld/ld.config + then + tmp_dir_list=`cat /var/ld/ld.config` + fi + fi + + tmp_dir_list=`echo ${tmp_libpath}:/lib:/usr/lib:/usr/ucb/lib:/usr/local/lib:/opt/misc/lib:${tmp_dir_list} | awk -F: '{for (i=1;i<(NF+1);i++) { print $[]i; }}'` + + tmp_lib_name= + # now that we know where we are looking, find our library + for tmp_dir in $tmp_dir_list + do + if test -e $tmp_dir/$1 + then + tmp_lib_name=${tmp_dir}/$1 + break + fi + done +fi +]) diff --git a/m4/sah_grx.m4 b/m4/sah_grx.m4 index b9b6deeb57..6c7dd98412 100644 --- a/m4/sah_grx.m4 +++ b/m4/sah_grx.m4 @@ -3,8 +3,10 @@ AC_DEFUN([SAH_GRX_LIBS],[ AC_LANG_PUSH(C) sah_save_libs="$LIBS" - GRXLIBS= - AC_CHECK_LIB([X11], [XCreateGC], [ GRXLIBS="-lX11" ; AC_DEFINE([HAVE_X11],1,[Define to 1 if you have X11 libraries])]) + AC_PATH_PROG(XLSFONTS,[xlsfonts],[/usr/X11/bin:/usr/X11R6/bin:/usr/X11R5/bin:/usr/X11R4/bin:$PATH]) + sah_xpath=`echo $XLSFONTS | sed 's/bin\/xlsfonts//' ` + LIBS=`echo $LIBS "-L$sah_xpath"` + AC_CHECK_LIB([X11], [XCreateGC], [ GRXLIBS="-L$sah_xpath/lib -lX11" ; AC_DEFINE([HAVE_X11],1,[Define to 1 if you have X11 libraries])]) AC_CHECK_LIB([Xaw], [XawTextReplace], GRXLIBS="$GRXLIBS -lXaw") AC_CHECK_LIB([Xext], [XShmGetImage], GRXLIBS="$GRXLIBS -lXext") AC_CHECK_LIB([Xmu], [XmuMakeAtom], GRXLIBS="$GRXLIBS -lXmu") @@ -21,6 +23,9 @@ AC_DEFUN([SAH_GRX_LIBS],[ AC_DEFUN([SAH_GRX_INCLUDES],[ AC_LANG_PUSH(C++) + AC_PATH_PROG(XLSFONTS,[xlsfonts],[/usr/X11/bin:/usr/X11R6/bin:/usr/X11R5/bin:/usr/X11R4/bin:$PATH]) + sah_xpath=`echo $XLSFONTS | sed 's/bin\/xlsfonts//' ` + CFLAGS=`echo $CFLAGS "-I$sah_xpath/include"` AC_CHECK_HEADERS([gl.h glu.h glut.h glaux.h GL/gl.h GL/glu.h GL/glut.h GL/glaux.h OpenGL/gl.h OpenGL/glu.h OpenGL/glut.h OpenGL/glaux.h GLUT/glut.h MesaGL/gl.h MesaGL/glu.h MesaGL/glut.h MesaGL/glaux.h]) AC_LANG_POP ]) diff --git a/m4/sah_libext.m4 b/m4/sah_libext.m4 new file mode 100644 index 0000000000..4f569e7be8 --- /dev/null +++ b/m4/sah_libext.m4 @@ -0,0 +1,33 @@ +# SETI_BOINC is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any later +# version. + +AC_DEFUN([SAH_LIBEXT],[ + AC_MSG_CHECKING(library extension) + if test -n `echo $AR | grep ar` + then + LIBEXT=a + else + LIBEXT=lib + fi + AC_MSG_RESULT($LIBEXT) + AC_SUBST(LIBEXT) +]) + +AC_DEFUN([SAH_DLLEXT],[ + AC_MSG_CHECKING(shared object extension) + case "${host}" in + *-*-emx* | *-*-mingw* | *-*-cygwin* | *-*-rmx*) + DLLEXT="dll" + ;; + *-*-darwin*) + DLLEXT="dylib" + ;; + *) + DLLEXT="so" + ;; + esac + AC_MSG_RESULT($DLLEXT) + AC_SUBST(DLLEXT) +]) diff --git a/m4/sah_select_bitness.m4 b/m4/sah_select_bitness.m4 new file mode 100644 index 0000000000..f96a6bb8ff --- /dev/null +++ b/m4/sah_select_bitness.m4 @@ -0,0 +1,56 @@ +AC_DEFUN([SAH_DEFAULT_BITNESS],[ + if test -z "${COMPILER_MODEL_BITS}" + then + AC_MSG_CHECKING(default bitness of compiler) + echo "int main() { return 0; }" >conftest.c + ${CC} ${CFLAGS} -c conftest.c >&5 + COMPILER_MODEL_BITS=32 + if test -f conftest.${OBJEXT} ; then + if test -n "`file conftest.${OBJEXT} | grep -i 64-bit`" + then + COMPILER_MODEL_BITS=64 + else + if test -n "`file conftest.${OBJEXT} | grep -i 16-bit`" + then + COMPILER_MODEL_BITS=16 + fi + fi + fi + /bin/rm conftest.c + AC_MSG_RESULT($COMPILER_MODEL_BITS) + fi +]) + + +AC_DEFUN([SAH_SELECT_BITNESS],[ + AC_LANG_PUSH(C) + SAH_DEFAULT_BITNESS + AC_MSG_CHECKING(Selecting $1 bit model) + echo "int main() { return 0; }" >conftest.$ac_ext + if test "$1" != "${COMPILER_MODEL_BITS}" + then + ${CC} ${CFLAGS} ${CPPFLAGS} -m$1 -c conftest.$ac_ext >&5 + if test -f conftest.${OBJEXT} ; then + if test -n "`file conftest.${OBJEXT} | grep -i $1-bit`" + then + CFLAGS="${CFLAGS} -m$1" + AC_MSG_RESULT(-m$1) + COMPILER_MODEL_BITS=$1 + fi + AC_MSG_RESULT(failed) + fi + else + AC_MSG_RESULT(ok) + fi + AC_LANG_POP(C) +]) + +AC_DEFUN([SAH_OPTION_BITNESS],[ + AC_ARG_ENABLE(bitness, + AC_HELP_STRING([--enable-bitness=(32,64)], + [enable 32 or 64 bit object/executable files] + ), + [SAH_SELECT_BITNESS(${enableval})], + [SAH_DEFAULT_BITNESS] + ) +]) diff --git a/m4/sah_staticize_ldflags.m4 b/m4/sah_staticize_ldflags.m4 new file mode 100644 index 0000000000..1c67ab0519 --- /dev/null +++ b/m4/sah_staticize_ldflags.m4 @@ -0,0 +1,41 @@ +AC_DEFUN([SAH_STATICIZE_LDFLAGS],[ + STATIC_LIB_LIST="${STATIC_LIB_LIST} $3" + liblist=`echo $1 | awk '{for (i=1;i<(NF+1);i++) {print $[]i;}}' | grep -v "Wl,[sd]" ` + ssl_sah_save_libs="${LIBS}" + echo "DEBUG: before mangling $2:$1" + sah_outputlibs= + for somelib in ${liblist}; do + # look for the -l to find the libraries + alib=`echo x${somelib} | grep x-l | sed 's/x-l//'` + if test -n "${alib}" + then + # check to see if it is in our static list + for slib in ${STATIC_LIB_LIST}; do + lib_is_static="no" + tmp_pattern=`echo s/x${slib}// | sed 's/\*/.*/'` + if test -z "`echo x${alib} | sed ${tmp_pattern}`" + then + SAH_STATIC_LIB(${alib},[fopen],[sah_outputlibs="${sah_outputlibs} ${sah_lib_last}"]) + lib_is_static="yes" + break; + fi + done + if test "${lib_is_static}" = "no" ; then + SAH_DYNAMIC_LIB(${alib},[fopen],[sah_outputlibs="${sah_outputlibs} ${sah_lib_last}"]) + fi + else + tmp_pattern_a="s/x${ld_dynamic_option}//" + tmp_pattern_b="s/x${ld_static_option}//" + if test -n "`echo x${somelib} | sed ${tmp_pattern_a}`" -a \ + -n "`echo x${somelib} | sed ${tmp_pattern_b}`" + then + sah_outputlibs="${sah_outputlibs} ${somelib}" + LIBS="${LIBS} ${somelib}" + fi + fi + done + echo "DEBUG: final link-line for $2:${sah_outputlibs}" + $2=${sah_outputlibs} + LIBS="${ssl_sah_save_libs}" +]) +