#!/bin/bash # # prepix -- Automatically generate shell script "epix" from Makefile. # # September 15, 2002 Andrew D. Hwang # ## Don't modify anything below unless you know what you're doing :) ## EPIX_OUTFILE=${EPIX_SCRIPT:-epix} ## Unquoted HERE document ## cat <
$EPIX_OUTFILE #!/bin/bash # # epix: wrapper script for ePiX # # Options: --help for usage, --version for version and license # # Compiler flags may be specified on the command line or in the config # file ~/.epixrc. The script attempts to deal intelligently with missing # or multiple extensions. If the input file has extension .c, .cc, .C, or # .cpp, there's no issue. If only the root name is given, the # script searches for files named infile.c, etc., with above suffixes in # the given order of preference. A warning is issued for multiple matches. # If no output file is specified, its name is obtained from the input file # name. # # Copyright (C) 2001, 2002, Andrew D. Hwang # ## Auto-generated file; modify as necessary ## INSTALL_DIR=${EPIX_ROOTDIR:-/usr/local} COMPILER=${EPIX_CXX:-g++} PROG=$EPIX_OUTFILE HEADER # End of header # Now for phase two... cat <<"EOF" >> $EPIX_OUTFILE ## Nothing below here should need modification ## EPIX_CONFIG_FILE="$HOME/.epixrc" export EPIX_MYINCLUDES export EPIX_MYLIBDIRS export EPIX_MYLIBS export EPIX_MYWARNS export EPIX_MYFLAGS function epix_die { echo "$PROG: ERROR: $1" >&2 exit 1 } function epix_warn { echo "$PROG: WARNING: $1" >&2 } # Parse command line/config file for compiler flags/options function epix_parse_options { while [ "$1" != "${1#"-"}" ]; do case "$1" in -I*) EPIX_MYINCLUDES="$EPIX_MYINCLUDES $1"; shift; continue ;; -L*) EPIX_MYLIBDIRS="$EPIX_MYLIBDIRS $1"; shift; continue ;; -l*) EPIX_MYLIBS="$EPIX_MYLIBS $1"; shift; continue ;; -W*) EPIX_MYWARNS="$EPIX_MYWARNS $1"; shift; continue ;; -V|-i*|-u|-x) EPIX_MYFLAGS="$EPIX_MYFLAGS $1 $2"; shift 2; continue ;; -b|-o) epix_warn "Skipping option \"$1 $2\"" shift 2; continue ;; -h|--help) epix_help; # exit normally ;; -v|--version) epix_version; # exit normally ;; *) EPIX_MYFLAGS="$EPIX_MYFLAGS $1"; shift; continue ;; esac done } # End of epix_parse_options # Path to standard header and library HDR_PATH=$INSTALL_DIR/include LIB_PATH=$INSTALL_DIR/lib # Standard libraries LIBS="-lm -lepix" declare INFILE declare INROOT # get file's root name, assuming extension is one of .c, .cc, .C, or NULL function epix_get_fileroot { # Skip compiler flags while [ "$1" != "${1#"-"}" ]; do case "$1" in -V|-b|-i*|-o|-u|-x) shift 2; ;; *) shift; ;; esac done # Assume next parameter is input file INFILE=$1 if [ "$INFILE" = "" ]; then epix_die "You must specify an input file!" elif [ $1 = ${1%%".c"}.c ] then INROOT=${1%%".c"} elif [ $1 = ${1%%".cc"}.cc ] then INROOT=${1%%".cc"} elif [ $1 = ${1%%".C"}.C ] then INROOT=${1%%".C"} elif [ $1 = ${1%%".cpp"}.cpp ] then INROOT=${1%%".cpp"} else # No recognized extension supplied INROOT=$1 local infile_count infile_count=0 # Look for completions; last match wins if [ -f $INROOT.cpp ]; then let infile_count=infile_count+1 INFILE=$INROOT.cpp fi if [ -f $INROOT.C ]; then let infile_count=infile_count+1 INFILE=$INROOT.C fi if [ -f $INROOT.cc ]; then let infile_count=infile_count+1 INFILE=$INROOT.cc fi if [ -f $INROOT.c ]; then let infile_count=infile_count+1 INFILE=$INROOT.c fi if [ $infile_count -eq 0 ] then epix_die "No completions of \"$INROOT\" found" elif [ $infile_count -ge 2 ] then epix_warn "Found $infile_count completions of \"$INROOT\", using $INFILE" # else one file found, INFILE already set fi fi # remaining parameter (if any) assumed to be output file if [ "$2" != "" ]; then OUTFILE=$2 OUTROOT=${OUTFILE%%".eepic"} else OUTROOT=$INROOT fi } # end of epix_get_fileroot function epix_help { cat <&1 Usage: $PROG [options] [.c|.cc|.C|.cpp] [[.eepic]] Options specific to $PROG are: -h, --help Print this help message -v, --version Print version and license information All other options are treated as compiler flags HELP exit 0 } # End of epix_help function epix_version { cat <&1 $PROG is part of ePiX, Version 0.8.7 Copyright (C) 2001, 2002 Andrew D. Hwang Department of Mathematics and Computer Science College of the Holy Cross Worcester, MA, 01610-2395, USA ePiX 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 of the License, or (at your option) any later version. ePiX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ePiX; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA VERSION exit 0 } # End of epix_version ## Script proper starts here ## if [ $# -eq 0 ]; then epix_help; else # Command line options epix_parse_options $@ # Remaining option(s) assumed to be input (and output) file(s) epix_get_fileroot $@ # Append options from the config file, if any if [ -f $EPIX_CONFIG_FILE ]; then for line in $(cat $EPIX_CONFIG_FILE | grep -v "#"); do epix_parse_options $line done fi # Suppress all warnings if none are requested if [ "$EPIX_MYWARNS" = "" ]; then EPIX_MYWARNS="-w"; fi fi # Give temporary binary a unique name (insecurely...) PID=$$ TEMP_BIN=$INROOT-$PID.exe # Compile executable (temporary binary written in cwd) $COMPILER $INFILE $EPIX_MYWARNS -o $TEMP_BIN -static \ -I$HDR_PATH -I. $EPIX_MYINCLUDES -L$LIB_PATH $EPIX_MYLIBDIRS \ $LIBS $EPIX_MYLIBS $EPIX_MYFLAGS if [ ! -f "$TEMP_BIN" ]; then epix_die "Compilation failed"; fi # Write eepic file if [ -x "$TEMP_BIN" ]; then echo "%% Generated from $INFILE on $(date) by" > $OUTROOT.eepic ./$TEMP_BIN >> $OUTROOT.eepic # Clean up stale binary rm -f $TEMP_BIN exit 0; fi if [ ! -f "$OUTROOT.eepic" ]; then rm -f $TEMP_BIN && epix_die "Could not create $OUTROOT.eepic" fi EOF ## end of script ##