#!/bin/sh ######################################################################## # derived from ccbb # c++bb myfile.c - just get the appropriate C flags and C compiler # # Created Feb 5, 1997 - Martin Lohner # ######################################################################## UNAME=`uname` SCRIPT=`basename $0` C_SRC= CCOPTS= CPPOPTS= DEBUG=0 DLINE=0 NOOP=0 SAVE=0 LINK= #blank means false OUTFILE= #blank means false ##### ##### describe command syntax if no arguments are given ##### if [ -z "$1" ] then echo "$SCRIPT [opts] file" echo 'opts:' echo ' -cpp supplementary cpp options' echo ' -outfile set explicit output file name' echo ' -debug compile for debugging' echo ' -nodebug (default) compile with optimization (nodebugging)' echo ' -dline compile debug lines' echo ' -noop print but do not execute commands' echo ' -save save intermediate file with #includes done' echo ' -link link arguments instead of compiling' echo ' (must be the last ccbb argument on the line)' echo '' echo "$SCRIPT - compile a C file, chosing options appropriate" echo " for the current host." echo '' echo "The follwoing (UNIX) system types are supported:" echo "AIX, HP-UX, IRIX, SunOS 4, Solaris, ULTRIX, OSF1" exit fi ##### ##### read command line arguments ##### while test $# -gt 0 do case $1 in -cpp) CPPOPTS="$CPPOPTS $2"; shift;; -debug) DEBUG=1;; -nodebug) DEBUG=0;; -dline) DLINE=1;; -outfile) OUTFILE="$2"; shift;; -noop) NOOP=1;; -save) SAVE=1;; -link) LINK=true; shift; break;; -*) echo "$SCRIPT: Unknown option: $1" 1>&2; exit 1;; *) C_SRC=$1;; esac shift done if [ $LINK ] then C_SRC=$* else # check command line arguments if [ ! "$C_SRC" ]; then echo "$SCRIPT: C_SRC not specified." 1>&2 exit 1 fi # check that source file exists if [ ! -r $C_SRC ]; then echo "$SCRIPT: $C_SRC not found." exit 1 fi if [ $DEBUG = 1 ] ; then c_out=`echo $C_SRC | sed -e 's/\.cc/\_g\.o/'` else c_out=`echo $C_SRC | sed -e 's/\.cc/\.o/'` fi fi if [ $OUTFILE ] then c_out=$OUTFILE fi ##### ##### machine specific stuff ##### case $UNAME in OSF1) CC=g++ CCOPTS="" [ $LINK ] || CCOPTS="$CCOPTS -c" [ $DLINE = 1 ] && CCOPTS="$CCOPTS -d_lines" if [ $DEBUG = 1 ] ; then CCOPTS="$CCOPTS -g " else CCOPTS="$CCOPTS -O " fi ;; Linux) CC=g++ CCOPTS="" [ $LINK ] || CCOPTS="$CCOPTS -c" if [ $DEBUG = 1 ] ; then CCOPTS="$CCOPTS -g " else CCOPTS="$CCOPTS -O " fi ;; HP-UX) CC=g++ CCOPTS="-Aa -D_HPUX_SOURCE" [ $LINK ] || CCOPTS="$CCOPTS -c" [ $DLINE = 1 ] && CCOPTS="$CCOPTS -D" [ $DEBUG = 1 ] && CCOPTS="$CCOPTS -g" || CCOPTS="$CCOPTS -O" ;; IRIX) CC=g++ RNAME=`uname -r | grep 6` if [ $RNAME ] then CCOPTS="" else CCOPTS="-mips2" fi [ $LINK ] || CCOPTS="$CCOPTS -c" [ $DLINE = 1 ] && CCOPTS="$CCOPTS -d_lines" [ $DEBUG = 1 ] && CCOPTS="$CCOPTS -g " || CCOPTS="$CCOPTS -O" ;; IRIX64) CC=g++ CCOPTS="" [ $LINK ] || CCOPTS="$CCOPTS -c" [ $DLINE = 1 ] && CCOPTS="$CCOPTS -d_lines" [ $DEBUG = 1 ] && CCOPTS="$CCOPTS -g " || CCOPTS="$CCOPTS -O" ;; SunOS) CC=g++ CCOPTS="" [ $LINK ] || CCOPTS="$CCOPTS -c" [ $DLINE = 1 ] && CCOPTS="$CCOPTS -xdl" [ $DEBUG = 1 ] && CCOPTS="$CCOPTS -g" || CCOPTS="$CCOPTS -O" ;; ULTRIX) CC=g++ CCOPTS="" [ $LINK ] || CCOPTS="$CCOPTS -c" [ $DLINE = 1 ] && CCOPTS="$CCOPTS -d_lines" [ $DEBUG = 1 ] && CCOPTS="$CCOPTS -g -C -check_bounds" || CCOPTS="$CCOPTS -O" ;; AIX) CC=g++ CCOPTS="-DAIX" [ $LINK ] || CCOPTS="$CCOPTS -c" [ $DLINE = 1 ] && CCOPTS="$CCOPTS -d_lines" [ $DEBUG = 1 ] && CCOPTS="$CCOPTS -g" || CCOPTS="$CCOPTS -O" ;; esac [ $NOOP = 1 ] && ECHO=echo ##### ##### CC step ##### ##echo "$CC $CCOPTS $CPPOPTS $C_SRC -o $c_out" $ECHO $CC $CCOPTS $CPPOPTS $C_SRC -o $c_out