# # $Id: link.in,v 1.49 2004/03/24 18:36:01 jmmv Exp $ # C/C++ object linking functions. # # buildtool # Copyright (c) 2003, 2004 Julio M. Merino Vidal. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # 3. Neither the name of the author nor the names of contributors may # be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # BT_TARGET_VARS+="BT_FLAGS_LD BT_LIBS" btown_link_parse_args() { local arg= local res= local archives= libs= objs= targets= local dirs_libs= dirs_rpath= local flags_L= flags_other= flags_rpath= flags_unknown= local shared=no [ -n "${LogFile}" ] && echo "[link: original call] $*" >> ${LogFile} while [ $# -gt 0 ]; do arg=$(echo ${1} | sed -e 's|"|\\"|g') case ${arg} in -L*) arg=$(echo ${arg} | sed -e s/-L//) if [ -d ${arg} ]; then arg=$(cd ${arg} && pwd) flags_L+=-L${arg} dirs_libs+=${arg} [ ${arg##${BT_WORKDIR}} = ${arg} ] && dirs_rpath+=${arg} fi ;; -Wl,-r*|-Wl,-R*|-rpath=*) arg=$(echo ${arg} | sed -e s/-Wl,-r// -e s/-Wl,-R// \ -e s/-rpath=//) [ -d ${arg} ] && arg=$(cd ${arg} && pwd) dirs_rpath+=${arg} ;; -export-dynamic) flags_other+=${BT_LIB_FLAG_EXPORTDYNAMIC} ;; -l*) if [ ${BT_LIB_MKPIC} = yes ]; then libs+=${arg} else local d found=no arg=$(echo ${arg} | sed -e s/-l//) for d in ${dirs_libs}; do if [ -f ${d}/lib${arg}.a ]; then archives+=${d}/lib${arg}.a found=yes break fi done [ ${found} = no ] && libs="${libs} ${arg}" fi ;; -o) target=${2}; shift ;; -shared) shared=yes ;; -soname=*) arg=$(echo ${arg} | sed -e 's/-soname=//') if [ ${BT_LIB_PIC_SONAME} = yes ]; then flags_other="-Wl,-soname=${arg}" fi shared=yes ;; *) if echo ${arg} | grep '^-' >/dev/null; then btcmn_warn "link: passing unhandled option \`${arg}'" flags_unknown+=${arg} elif echo ${arg} | grep '.a$' >/dev/null; then archives+=${arg} else objects+=${arg} fi ;; esac shift done if [ ${BT_FEATURE_RPATH} = yes ]; then local d for d in ${BT_DIR_LIB} ${dirs_rpath}; do flags_rpath+=${BT_LINK_FLAG_RPATH}${d} done fi if [ ${shared} = yes ]; then flags_other="-shared ${flags_other}" fi res="${flags_L} ${flags_rpath} ${flags_other} ${flags_unknown} -o ${target} ${objects} ${archives} ${libs}" # NOLINT [ -n "${LogFile}" ] && echo "[link: call rewrote as] ${res}" >> ${LogFile} echo ${res} } bt_link_c() { local cmd [ -z ${BT_PROG_CC} ] && btcmn_err \ "link: no C linker available (BT_PROG_CC is not set)" \ " add a call to bt_check_env_c in your config script" cmd="${BT_PROG_CC} $(btown_link_parse_args $*)" echo "[link] ${cmd}" ${cmd} || bt_die } bt_link_cxx() { local cmd [ -z ${BT_PROG_CXX} ] && btcmn_err \ "link: no C++ linker available (BT_PROG_CXX is not set)" \ " add a call to bt_check_env_c in your config script" cmd="${BT_PROG_CXX} $(btown_link_parse_args $*)" echo "[link] ${cmd}" ${cmd} || bt_die } # Local Variables: *** # mode: shell-script *** # End: *** # vim: syntax=sh