#!/bin/ksh # # Script for running the C/C++ compiler when building python modules # # # # Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # MYNAME=`basename $0` # name of the compiler executable CCEXE='cc' # name of the GNU compiler executable GCCEXE='gcc' # name of the programming language CLANG='C' # name of the env variable for setting the compiler path CVAR='CC' if [ "x$PYCC_CC" != x ]; then CC="$PYCC_CC" fi if [ "x$MYNAME" = xpyCC ]; then CCEXE='CC' GCCEXE='g++' CLANG='C++' CC="$CXX" CVAR='CXX' if [ "x$PYCC_CXX" != x ]; then CC="$PYCC_CXX" fi fi SAVED_IFS="$IFS" IFS=: # check if the CC env variable is set if [ "x$CC" != x ]; then # verify that it doesn't point to this script if /usr/bin/cmp -s "$CC" $0; then echo "WARNING: "$CVAR" is set to this script; ignoring this value to avoid an infinite loop" CC= fi fi # check again if the CC env variable is set if [ "x$CC" != x ]; then case "$CC" in /* ) # $CC is an absolute path name # check if $CC exists if [ ! -e "$CC" ]; then echo "WARNING: pycc: $CC not found" 1>&2 CC= else # check if $CC is an executable if [ ! -x "$CC" -o ! -f "$CC" ]; then echo "WARNING: pycc: $CC is not an executable" 1>&2 CC= fi fi ;; * ) # try to find $CC in the PATH NEW_CC= for dir in $PATH; do if [ -x "$dir/$CC" ]; then NEW_CC="$dir/$CC" break fi done if [ "x$NEW_CC" = x ]; then echo "WARNING: pycc: $CC not found" 1>&2 CC= else CC="$NEW_CC" fi ;; esac fi if [ "x$CC" = x ]; then # Look for the Sun Studio compiler in the PATH for dir in $PATH; do if [ -x "$dir/$CCEXE" ]; then CC="$dir/$CCEXE" break fi done fi if [ "x$CC" = x ]; then # Look for gcc in the PATH for dir in $PATH; do if [ -x "$dir/$GCCEXE" ]; then CC="$dir/$GCCEXE" break fi done fi if [ "x$CC" = x ]; then # Check for Sun Studio in /opt/SUNWspro (default install location) if [ -x /opt/SUNWspro/bin/$CCEXE ]; then CC=/opt/SUNWspro/bin/$CCEXE fi fi if [ "x$CC" = x ]; then # Check for the GNU compiler in /usr/sfw/bin if [ -x /usr/sfw/bin/$GCCEXE ]; then CC=/usr/sfw/bin/$GCCEXE fi fi if [ "x$CC" = x ]; then # Cannot continue without a C compiler echo "ERROR: no $CLANG compiler not found; update your PATH or set the $CVAR env variable" 1>&2 exit 1 fi IFS="$SAVED_IFS" # We need to make some modifications to adapt correctly to compiler options # that differ between GCC and Studio. extra_flags= is_gcc=no $CC --version >/dev/null 2>&1 && is_gcc=yes if [ "$is_gcc" = yes ]; then for flag in "${@}"; do # need -shared to link shared objects properly if [ "$flag" = "-G" ]; then extra_flags="$extra_flags -shared" fi done # force PIC compilation extra_flags="$extra_flags -fPIC -DPIC" else extra_flags="$extra_flags -KPIC" fi exec "$CC" $extra_flags "${@}"