Description:
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@238 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r57:1706f495c73a - - 1 file changed: 3 inserted, 3 deleted
@@ -1,107 +1,107 | |||||
|
1 | #!/bin/sh |
|
1 | #!/bin/sh |
|
2 |
|
2 | ||
|
3 | ############################## |
|
3 | ############################## |
|
4 | # |
|
4 | # |
|
5 | # Standard Compile Script |
|
5 | # Standard Compile Script |
|
6 | # |
|
6 | # |
|
7 | # Supported compilers: |
|
7 | # Supported compilers: |
|
8 | # gcc, g++, and fpc. |
|
8 | # gcc, g++, and fpc. |
|
9 | # |
|
9 | # |
|
10 | ############################## |
|
10 | ############################## |
|
11 |
|
11 | ||
|
12 | talk () |
|
12 | talk () |
|
13 | { |
|
13 | { |
|
14 | if [ "$TALKATIVE" != "" ]; then |
|
14 | if [ "$TALKATIVE" != "" ]; then |
|
15 | echo "$1" |
|
15 | echo "$1" |
|
16 | fi |
|
16 | fi |
|
17 | } |
|
17 | } |
|
18 |
|
18 | ||
|
19 | export C_COMPILER=/usr/bin/gcc |
|
19 | export C_COMPILER=/usr/bin/gcc |
|
20 | export CPLUSPLUS_COMPILER=/usr/bin/g++ |
|
20 | export CPLUSPLUS_COMPILER=/usr/bin/g++ |
|
21 | export PASCAL_COMPILER=/usr/bin/fpc |
|
21 | export PASCAL_COMPILER=/usr/bin/fpc |
|
22 |
|
22 | ||
|
23 | - export C_OPTIONS="-O2 -s -static -lm -Wall" |
|
23 | + export C_OPTIONS="-O2 -s -static -std=c99 -DCONTEST -lm -Wall" |
|
24 | - export CPLUSPLUS_OPTIONS="-O2 -s -static -lm -Wall" |
|
24 | + export CPLUSPLUS_OPTIONS="-O2 -s -static -DCONTEST -lm -Wall" |
|
25 | - export PASCAL_OPTIONS="-O1 -XS" |
|
25 | + export PASCAL_OPTIONS="-O1 -XS -dCONTEST" |
|
26 |
|
26 | ||
|
27 | # Check for the correct number of arguments. Otherwise, print usage. |
|
27 | # Check for the correct number of arguments. Otherwise, print usage. |
|
28 | if [ $# -eq 0 -o $# -gt 4 ] |
|
28 | if [ $# -eq 0 -o $# -gt 4 ] |
|
29 | then |
|
29 | then |
|
30 | echo "Usage: $0 <language> [<source-file>] [<output-file>] [<message-file>]" |
|
30 | echo "Usage: $0 <language> [<source-file>] [<output-file>] [<message-file>]" |
|
31 | echo |
|
31 | echo |
|
32 | echo "<source-file> is defaulted to \"source\"." |
|
32 | echo "<source-file> is defaulted to \"source\"." |
|
33 | echo "<output-file> is defaulted to \"a.out\"." |
|
33 | echo "<output-file> is defaulted to \"a.out\"." |
|
34 | echo "<message-file> is defaulted to \"compiler_message\"." |
|
34 | echo "<message-file> is defaulted to \"compiler_message\"." |
|
35 | echo |
|
35 | echo |
|
36 | exit 127 |
|
36 | exit 127 |
|
37 | fi |
|
37 | fi |
|
38 |
|
38 | ||
|
39 | # Retrieve the arguments. |
|
39 | # Retrieve the arguments. |
|
40 | if [ $# -ge 1 ] |
|
40 | if [ $# -ge 1 ] |
|
41 | then |
|
41 | then |
|
42 | export PROG_LANG=$1 |
|
42 | export PROG_LANG=$1 |
|
43 | talk "programming language: ${PROG_LANG}" |
|
43 | talk "programming language: ${PROG_LANG}" |
|
44 | fi |
|
44 | fi |
|
45 |
|
45 | ||
|
46 | if [ $# -ge 2 ] |
|
46 | if [ $# -ge 2 ] |
|
47 | then |
|
47 | then |
|
48 | export SOURCE_FILE=$2 |
|
48 | export SOURCE_FILE=$2 |
|
49 | else |
|
49 | else |
|
50 | export SOURCE_FILE=source |
|
50 | export SOURCE_FILE=source |
|
51 | fi |
|
51 | fi |
|
52 | talk " source file: $SOURCE_FILE" |
|
52 | talk " source file: $SOURCE_FILE" |
|
53 |
|
53 | ||
|
54 | if [ $# -ge 3 ] |
|
54 | if [ $# -ge 3 ] |
|
55 | then |
|
55 | then |
|
56 | export OUTPUT_FILE=$3 |
|
56 | export OUTPUT_FILE=$3 |
|
57 | else |
|
57 | else |
|
58 | export OUTPUT_FILE=a.out |
|
58 | export OUTPUT_FILE=a.out |
|
59 | fi |
|
59 | fi |
|
60 | talk " output file: $OUTPUT_FILE" |
|
60 | talk " output file: $OUTPUT_FILE" |
|
61 |
|
61 | ||
|
62 | if [ $# -eq 4 ] |
|
62 | if [ $# -eq 4 ] |
|
63 | then |
|
63 | then |
|
64 | export MESSAGE_FILE=$4 |
|
64 | export MESSAGE_FILE=$4 |
|
65 | else |
|
65 | else |
|
66 | export MESSAGE_FILE=compiler_message |
|
66 | export MESSAGE_FILE=compiler_message |
|
67 | fi |
|
67 | fi |
|
68 | talk " message file: $MESSAGE_FILE" |
|
68 | talk " message file: $MESSAGE_FILE" |
|
69 |
|
69 | ||
|
70 | # Remove any remaining output files or message files. |
|
70 | # Remove any remaining output files or message files. |
|
71 | rm -Rf $OUTPUT_FILE |
|
71 | rm -Rf $OUTPUT_FILE |
|
72 | rm -Rf $MESSAGE_FILE |
|
72 | rm -Rf $MESSAGE_FILE |
|
73 |
|
73 | ||
|
74 | # Check if the source file exists before attempt compiling. |
|
74 | # Check if the source file exists before attempt compiling. |
|
75 | if [ ! -f $SOURCE_FILE ] |
|
75 | if [ ! -f $SOURCE_FILE ] |
|
76 | then |
|
76 | then |
|
77 | talk "ERROR: The source file does not exist!" |
|
77 | talk "ERROR: The source file does not exist!" |
|
78 | echo "ERROR: The source file did not exist." > $MESSAGE_FILE |
|
78 | echo "ERROR: The source file did not exist." > $MESSAGE_FILE |
|
79 | exit 127 |
|
79 | exit 127 |
|
80 | fi |
|
80 | fi |
|
81 |
|
81 | ||
|
82 | # Compile. |
|
82 | # Compile. |
|
83 | if [ $PROG_LANG = "c" ] |
|
83 | if [ $PROG_LANG = "c" ] |
|
84 | then |
|
84 | then |
|
85 | $C_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $C_OPTIONS 2>$MESSAGE_FILE |
|
85 | $C_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $C_OPTIONS 2>$MESSAGE_FILE |
|
86 | elif [ $PROG_LANG = "c++" ] |
|
86 | elif [ $PROG_LANG = "c++" ] |
|
87 | then |
|
87 | then |
|
88 | $CPLUSPLUS_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $CPLUSPLUS_OPTIONS 2>$MESSAGE_FILE |
|
88 | $CPLUSPLUS_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $CPLUSPLUS_OPTIONS 2>$MESSAGE_FILE |
|
89 | elif [ $PROG_LANG = "pas" ] |
|
89 | elif [ $PROG_LANG = "pas" ] |
|
90 | then |
|
90 | then |
|
91 | $PASCAL_COMPILER $SOURCE_FILE -ooutpas $PASCAL_OPTIONS >$MESSAGE_FILE |
|
91 | $PASCAL_COMPILER $SOURCE_FILE -ooutpas $PASCAL_OPTIONS >$MESSAGE_FILE |
|
92 | mv outpas $OUTPUT_FILE |
|
92 | mv outpas $OUTPUT_FILE |
|
93 | else |
|
93 | else |
|
94 | talk "ERROR: Invalid language specified!" |
|
94 | talk "ERROR: Invalid language specified!" |
|
95 | echo "ERROR: Invalid language specified!" > $MESSAGE_FILE |
|
95 | echo "ERROR: Invalid language specified!" > $MESSAGE_FILE |
|
96 | exit 127 |
|
96 | exit 127 |
|
97 | fi |
|
97 | fi |
|
98 |
|
98 | ||
|
99 | # Report success or failure. |
|
99 | # Report success or failure. |
|
100 | if [ -f $OUTPUT_FILE ] |
|
100 | if [ -f $OUTPUT_FILE ] |
|
101 | then |
|
101 | then |
|
102 | talk "Compilation was successful!" |
|
102 | talk "Compilation was successful!" |
|
103 | else |
|
103 | else |
|
104 | talk "ERROR: Something was wrong during the compilation!" |
|
104 | talk "ERROR: Something was wrong during the compilation!" |
|
105 | talk "Dumping compiler message:" |
|
105 | talk "Dumping compiler message:" |
|
106 | #cat $MESSAGE_FILE |
|
106 | #cat $MESSAGE_FILE |
|
107 | fi |
|
107 | fi |
You need to be logged in to leave comments.
Login now