Mercurial > octave-nkf
view mkoctfile.in @ 3847:92fb162eba24
[project @ 2001-08-10 17:18:17 by jwe]
author | jwe |
---|---|
date | Fri, 10 Aug 2001 17:20:24 +0000 |
parents | 08cd791cd613 |
children | 890a7e4c1362 |
line wrap: on
line source
#! /bin/sh # # mkoctfile -- create a .oct file suitable for dynamic linking by # Octave. # Exit immediately on any error. set -e # Default values for these variables are filled in when Octave is # compiled. : ${CPPFLAGS=%OCTAVE_CONF_CPPFLAGS%} : ${INCFLAGS=%OCTAVE_CONF_MKOCTFILE_INCFLAGS%} : ${F2C=%OCTAVE_CONF_F2C%} : ${F2CFLAGS=%OCTAVE_CONF_F2CFLAGS%} : ${F77=%OCTAVE_CONF_F77%} : ${FFLAGS=%OCTAVE_CONF_FFLAGS%} : ${FPICFLAG=%OCTAVE_CONF_FPICFLAG%} : ${CC=%OCTAVE_CONF_CC%} : ${CFLAGS=%OCTAVE_CONF_CFLAGS%} : ${CPICFLAG=%OCTAVE_CONF_CPICFLAG%} : ${CXX=%OCTAVE_CONF_CXX%} : ${CXXFLAGS=%OCTAVE_CONF_CXXFLAGS%} : ${CXXPICFLAG=%OCTAVE_CONF_CXXPICFLAG%} : ${XTRA_CFLAGS=%OCTAVE_CONF_XTRA_CFLAGS%} : ${XTRA_CXXFLAGS=%OCTAVE_CONF_XTRA_CXXFLAGS%} : ${DEPEND_FLAGS=%OCTAVE_CONF_DEPEND_FLAGS%} : ${DEPEND_EXTRA_SED_PATTERN=%OCTAVE_CONF_DEPEND_EXTRA_SED_PATTERN%} : ${SH_LD=%OCTAVE_CONF_SH_LD%} : ${SH_LDFLAGS=%OCTAVE_CONF_SH_LDFLAGS%} : ${ALL_FFLAGS="$FFLAGS"} : ${ALL_CFLAGS="$INCFLAGS $XTRA_CFLAGS $CFLAGS"} : ${ALL_CXXFLAGS="$INCFLAGS $XTRA_CXXFLAGS $CXXFLAGS"} # Local variables. usage_msg="usage: mkoctfile [options] file ..." cfiles= ccfiles= f77files= objfiles= octfiles= octfile= incflags= defs= ldflags= dbg=: strip=false link=true depend=false compile=true if [ $# -eq 0 ]; then echo $usage_msg 1>&2 exit 1 fi while [ $# -gt 0 ]; do file= case "$1" in *.c) file=$1 cfiles="$cfiles $file" ;; *.cc | *.C | *.cpp) file=$1 ccfiles="$ccfiles $file" ;; *.f | *.F) file=$1 f77files="$f77files $file" ;; *.o) file=$1 objfiles="$objfiles $file" ;; -d | --debug | -v | --verbose) dbg=echo ;; -h | -\? | --help) echo $usage_msg 1>&2 cat << EOF Options: -h, -?, --help Print this message. -IDIR Add -IDIR to compile commands. -DDEF Add -DDEF to compile commands. -lLIB Add library LIB to link command. -LDIR Add -LDIR to link command. -M, --depend Generate dependency files (.d) for C and C++ source files. -c Compile, but do not link. -o FILE, --output FILE Output file name. Default extension is .oct. -p VAR, --print VAR Print configuration variable VAR. Recognized variables are: CPPFLAGS CPICFLAG INCFLAGS CXX F2C CXXFLAGS F2CFLAGS CXXPICFLAG F77 XTRA_CFLAGS FFLAGS XTRA_CXXFLAGS FPICFLAG SHLEXT CC SH_LD CFLAGS SH_LDFLAGS -s, --strip Strip output file. -v, --verbose Echo commands as they are executed. FILE Compile or link FILE. Recognized file types are: .c C source .cc C++ source .C C++ source .cpp C++ source .f Fortran source .F Fortran source .o object file EOF exit 0 ;; -I*) incflags="$incflags $1" ;; -D*) defs="$defs $1" ;; -[lL]*) ldflags="$ldflags $1" ;; -M | --depend) depend=true compile=false ;; -o | --output) shift if [ $# -gt 0 ]; then octfile=`echo $1 | sed 's,\.[^.]*$,,'`.oct else echo "mkoctfile: output file name missing" 1>&2 fi ;; -p | --print) shift if [ $# -gt 0 ]; then eval echo \${$1} exit 0 else echo "mkoctfile: --print requires argument" 1>&2 exit 1 fi ;; -s | --strip) strip=true ;; -c) link=false ;; *) echo "mkoctfile: unrecognized argument $1" 1>&2 exit 1 ;; esac if [ -n "$file" ]; then if [ -z "$octfile" ]; then octfile=`echo $file | sed 's,\.[^.]*$,,'`.oct fi fi shift done # Generate dependency files for C and C++ files. if $depend; then if [ -n "$cfiles" ]; then for f in $cfiles; do b=`echo $f | sed 's,\.c$,,'` d=$b.d cmd="rm -f $d" $dbg $cmd eval $cmd cmd="$CC $DEPEND_FLAGS $CPPFLAGS $ALL_CFLAGS $f | sed $DEPEND_EXTRA_SED_PATTERN -e 's,^[^:]*/\(.*\.o\):,\1:,' -e 's,$b\.o,pic/& & $d,g' > $d-t && mv $d-t $d" $dbg $cmd eval $cmd done fi if [ -n "$ccfiles" ]; then for f in $ccfiles; do case $f in *.cc) b=`echo $f | sed 's,\.cc$,,'` ;; *.C) b=`echo $f | sed 's,\.C$,,'` ;; *.cpp) b=`echo $f | sed 's,\.cpp$,,'` ;; esac d=$b.d cmd="rm -f $d" $dbg $cmd eval $cmd cmd="$CXX $DEPEND_FLAGS $CPPFLAGS $ALL_CXXFLAGS $f | sed $DEPEND_EXTRA_SED_PATTERN -e 's,^[^:]*/\(.*\.o\):,\1:,' -e 's,$b\.o,pic/& & $d,g' > $d-t && mv $d-t $d" $dbg $cmd eval $cmd done fi # If generating dependencies, that's all we do. exit 0 fi # Compile Fortran, C, and C++ files. Add the name of each object file # that is produced to the overall list of object files. if [ -n "$f77files" ]; then for f in $f77files; do case $f in *.f) b=`echo $f | sed 's,\.f$,,'` ;; *.F) b=`echo $f | sed 's,\.F$,,'` ;; esac if [ -n "$F77" ]; then o=$b.o objfiles="$objfiles $o" cmd="$F77 -c $FPICFLAG $ALL_FFLAGS $f -o $o" $dbg $cmd eval $cmd elif [ -n "$F2C" ]; then c=$b.c cfiles="$cfiles $c" cmd="$F2C $F2CFLAGS < $f > $c" $dbg $cmd eval $cmd else echo "mkoctfile: no way to compile Fortran file $f" 1>&2 fi done fi if [ -n "$cfiles" ]; then for f in $cfiles; do if [ -n "$CC" ]; then b=`echo $f | sed 's,\.c$,,'` o=$b.o objfiles="$objfiles $o" cmd="$CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $incflags $defs $f -o $o" $dbg $cmd eval $cmd else echo "mkoctfile: no way to compile C++ file $f" 1>&2 fi done fi if [ -n "$ccfiles" ]; then for f in $ccfiles; do if [ -n "$CXX" ]; then case $f in *.cc) b=`echo $f | sed 's,\.cc$,,'` ;; *.C) b=`echo $f | sed 's,\.C$,,'` ;; *.cpp) b=`echo $f | sed 's,\.cpp$,,'` ;; esac o=$b.o objfiles="$objfiles $o" cmd="$CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $incflags $defs $f -o $o" $dbg $cmd eval $cmd else echo "mkoctfile: no way to compile C++ file $f" 1>&2 fi done fi ## Uncomment the following group of lines if you get `Text file busy' ## errors from ld. This may happen if the .oct file is currently ## running while you are trying to recompile it. We try moving first, ## since on some systems (HP-UX, maybe others) it is possible to ## rename running programs but not remove them. ## if [ -f "$octfile" ]; then ## cmd="mv $octfile $octfile.bak" ## $dbg $cmd ## eval $cmd ## cmd="rm -f $octfile.bak" ## $dbg $cmd ## eval $cmd ## fi # Link all the object files. if $link; then cmd="$SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags" $dbg $cmd eval $cmd # Maybe strip it. if $strip; then cmd="strip $octfile" $dbg $cmd eval $cmd fi fi exit 0