Show More
Commit Description:
[grader] hack on language for output-only task...
Commit Description:
[grader] hack on language for output-only task
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@190 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
std-script/compile
| 106 lines
| 2.3 KiB
| text/plain
| TextLexer
|
|
r0 | #!/bin/sh | ||
############################## | ||||
# | ||||
# Standard Compile Script | ||||
# | ||||
# Supported compilers: | ||||
# gcc, g++, and gpc. | ||||
# | ||||
############################## | ||||
|
r22 | talk () | ||
{ | ||||
if [ "$TALKATIVE" != "" ]; then | ||||
echo "$1" | ||||
fi | ||||
} | ||||
|
r0 | export C_COMPILER=/usr/bin/gcc | ||
export CPLUSPLUS_COMPILER=/usr/bin/g++ | ||||
export PASCAL_COMPILER=/usr/bin/gpc | ||||
|
r48 | export C_OPTIONS="-O2 -s -static -lm -Wall" | ||
export CPLUSPLUS_OPTIONS="-O2 -s -static -lm -Wall" | ||||
export PASCAL_OPTIONS="-O2 -XS -lm -Wall" | ||||
|
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 | ||
|
r0 | elif [ $PROG_LANG = "pascal" ] | ||
then | ||||
|
r48 | $PASCAL_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $PASCAL_OPTIONS 2>$MESSAGE_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 | ||