Show More
Commit Description:
allow __NR_time in box...
Commit Description:
allow __NR_time in box
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@266 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
std-script/compile
| 107 lines
| 2.4 KiB
| text/plain
| TextLexer
|
|
r0 | #!/bin/sh | ||
############################## | ||||
# | ||||
# Standard Compile Script | ||||
# | ||||
# Supported compilers: | ||||
|
r53 | # gcc, g++, and fpc. | ||
|
r0 | # | ||
############################## | ||||
|
r22 | talk () | ||
{ | ||||
if [ "$TALKATIVE" != "" ]; then | ||||
echo "$1" | ||||
fi | ||||
} | ||||
|
r0 | export C_COMPILER=/usr/bin/gcc | ||
export CPLUSPLUS_COMPILER=/usr/bin/g++ | ||||
|
r53 | export PASCAL_COMPILER=/usr/bin/fpc | ||
|
r0 | |||
|
r57 | export C_OPTIONS="-O2 -s -static -std=c99 -DCONTEST -lm -Wall" | ||
export CPLUSPLUS_OPTIONS="-O2 -s -static -DCONTEST -lm -Wall" | ||||
export PASCAL_OPTIONS="-O1 -XS -dCONTEST" | ||||
|
r0 | |||
# Check for the correct number of arguments. Otherwise, print usage. | ||||
if [ $# -eq 0 -o $# -gt 4 ] | ||||
then | ||||
echo "Usage: $0 <language> [<source-file>] [<output-file>] [<message-file>]" | ||||
echo | ||||
echo "<source-file> is defaulted to \"source\"." | ||||
echo "<output-file> is defaulted to \"a.out\"." | ||||
echo "<message-file> is defaulted to \"compiler_message\"." | ||||
echo | ||||
exit 127 | ||||
fi | ||||
# Retrieve the arguments. | ||||
if [ $# -ge 1 ] | ||||
then | ||||
export PROG_LANG=$1 | ||||
|
r22 | talk "programming language: ${PROG_LANG}" | ||
|
r0 | fi | ||
if [ $# -ge 2 ] | ||||
then | ||||
export SOURCE_FILE=$2 | ||||
else | ||||
export SOURCE_FILE=source | ||||
fi | ||||
|
r22 | talk " source file: $SOURCE_FILE" | ||
|
r0 | |||
if [ $# -ge 3 ] | ||||
then | ||||
export OUTPUT_FILE=$3 | ||||
else | ||||
export OUTPUT_FILE=a.out | ||||
fi | ||||
|
r22 | talk " output file: $OUTPUT_FILE" | ||
|
r0 | |||
if [ $# -eq 4 ] | ||||
then | ||||
export MESSAGE_FILE=$4 | ||||
else | ||||
export MESSAGE_FILE=compiler_message | ||||
fi | ||||
|
r22 | talk " message file: $MESSAGE_FILE" | ||
|
r0 | |||
# Remove any remaining output files or message files. | ||||
rm -Rf $OUTPUT_FILE | ||||
rm -Rf $MESSAGE_FILE | ||||
# Check if the source file exists before attempt compiling. | ||||
if [ ! -f $SOURCE_FILE ] | ||||
then | ||||
|
r22 | talk "ERROR: The source file does not exist!" | ||
|
r0 | echo "ERROR: The source file did not exist." > $MESSAGE_FILE | ||
exit 127 | ||||
fi | ||||
# Compile. | ||||
if [ $PROG_LANG = "c" ] | ||||
then | ||||
|
r48 | $C_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $C_OPTIONS 2>$MESSAGE_FILE | ||
|
r0 | elif [ $PROG_LANG = "c++" ] | ||
then | ||||
|
r48 | $CPLUSPLUS_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $CPLUSPLUS_OPTIONS 2>$MESSAGE_FILE | ||
|
r53 | elif [ $PROG_LANG = "pas" ] | ||
|
r0 | then | ||
|
r54 | $PASCAL_COMPILER $SOURCE_FILE -ooutpas $PASCAL_OPTIONS >$MESSAGE_FILE | ||
mv outpas $OUTPUT_FILE | ||||
|
r0 | else | ||
|
r22 | talk "ERROR: Invalid language specified!" | ||
|
r0 | echo "ERROR: Invalid language specified!" > $MESSAGE_FILE | ||
exit 127 | ||||
fi | ||||
# Report success or failure. | ||||
if [ -f $OUTPUT_FILE ] | ||||
then | ||||
|
r22 | talk "Compilation was successful!" | ||
|
r0 | else | ||
|
r22 | talk "ERROR: Something was wrong during the compilation!" | ||
talk "Dumping compiler message:" | ||||
#cat $MESSAGE_FILE | ||||
|
r48 | fi | ||