Commit | Line | Data |
---|---|---|
da905f9e MG |
1 | #!/usr/bin/perl -w |
2 | use v5.14; | |
3 | no if $] > 5.017011, warnings => 'experimental::smartmatch'; | |
4 | ||
9577371b | 5 | use File::Copy qw/copy/; |
496fffaa MG |
6 | use File::Basename qw/fileparse/; |
7 | ||
8 | my ($format, $name) = @ARGV; | |
9 | my $basename = fileparse $name, qr/\..*/; | |
9577371b | 10 | |
9c1ab914 | 11 | given ($format){ |
5b0c03b6 MG |
12 | exec 'gcc', qw/-DONLINE_JUDGE -std=gnu11 -Wall -Wextra -lm -O2 -o/, $basename, $name when 'C'; |
13 | exec 'g++', qw/-DONLINE_JUDGE -std=gnu++11 -Wall -Wextra -lm -O2 -o/, $basename, $name when 'CPP'; | |
fb85e61f | 14 | |
9c1ab914 MG |
15 | when ('MONO') { |
16 | system 'gmcs', '-d:ONLINE_JUDGE', $name and die "gmcs failed: errno=$! return=$?"; | |
17 | rename "$basename.exe", $basename; | |
18 | chmod 0755, $basename; | |
19 | } | |
27be8560 | 20 | exec 'gmcs', '-d:ONLINE_JUDGE', $name when 'MONO'; |
9c1ab914 | 21 | when ('JAVA') { |
95379e40 | 22 | unlink $_ for <*.class>; |
9c1ab914 | 23 | system 'javac', $name and die "javac failed: errno=$! return=$?"; |
95379e40 | 24 | system 'jar', 'cfe', $basename, $basename, <*.class> and die "jar failed: errno=$! return=$?"; |
9c1ab914 MG |
25 | chmod 0755, $basename; |
26 | exit | |
27 | } | |
28 | exec 'fpc', qw/-dONLINE_JUDGE -O2/, $name when 'PASCAL'; | |
29 | exec 'go', qw/build -compiler gc/, $name when 'GOLANG'; | |
30 | exec 'go', qw/build -compiler gccgo/, $name, when 'GCCGO'; | |
31 | exec 'ghc', qw/-DONLINE_JUDGE -Wall -O2 -o/, $basename, $name when 'HASKELL'; | |
27be8560 | 32 | exec 'rustc', qw/-O -o/, $basename, $name when 'RUST'; |
34e16771 | 33 | exec 'ocamlc', qw/-o/, $basename, $name when 'OCAML'; |
49b65824 | 34 | exec 'dmd', qw/-version=ONLINE_JUDGE -O -release -inline -noboundscheck/, $name when 'D'; |
9c1ab914 | 35 | |
fb85e61f S |
36 | when ('BRAINFUCK') { |
37 | system 'bfc', $name and die "bfc failed: errno=$! return=$?"; | |
38 | rename "a.out", $basename; | |
39 | chmod 0755, $basename; | |
40 | exit | |
41 | } | |
42 | ||
8473542d | 43 | when ([qw/GOLFSCRIPT JULIA PERL PHP PYTHON RUBY SBCL/]){ |
9c1ab914 MG |
44 | open IN, '<', $name; |
45 | open OUT, '>', $basename; | |
8473542d S |
46 | print OUT "#!/usr/bin/golfscript\n" if $_ eq 'GOLFSCRIPT'; |
47 | print OUT "#!/usr/bin/julia -O\n" if $_ eq 'JULIA'; | |
48 | print OUT "#!/usr/bin/perl\n" if $_ eq 'PERL'; | |
49 | print OUT "#!/usr/bin/php -d ONLINE_JUDGE=true\n" if $_ eq 'PHP'; | |
92fbf933 | 50 | print OUT "#!/usr/bin/python2.7\n" if $_ eq 'PYTHON'; |
8473542d S |
51 | print OUT "#!/usr/bin/ruby\n" if $_ eq 'RUBY'; |
52 | print OUT "#!/usr/bin/sbcl --script\n" if $_ eq 'SBCL'; | |
9c1ab914 MG |
53 | print OUT while <IN>; |
54 | close OUT; | |
55 | close IN; | |
56 | chmod 0755, $basename; | |
57 | exit | |
9577371b | 58 | } |
da905f9e | 59 | } |
69c25408 | 60 | |
0e7e545a | 61 | exit 1; |
69c25408 MG |
62 | __END__ |
63 | ||
64 | =encoding utf-8 | |
65 | ||
66 | =head1 NAME | |
67 | ||
68 | gruntmaster-compile - Gruntmaster 6000 compiler frontend | |
69 | ||
70 | =head1 SYNOPSIS | |
71 | ||
72 | gruntmaster-compile CPP file.cpp | |
73 | gruntmaster-compile JAVA file.java | |
74 | ||
75 | =head1 DESCRIPTION | |
76 | ||
27be8560 | 77 | gruntmaster-compile is a very simple frontend to various compilers. It takes two arguments: the file format and the file name, and produces a compiled executable. The executable's name is the basename of the input file. |
69c25408 MG |
78 | |
79 | Compile commands for each format: | |
80 | ||
81 | =over | |
82 | ||
fb85e61f S |
83 | =item BRAINFUCK |
84 | ||
85 | bfc $input | |
86 | ||
69c25408 MG |
87 | =item C |
88 | ||
89 | gcc -DONLINE_JUDGE -std=gnu11 -Wall -Wextra -O2 -o $output $input | |
90 | ||
91 | =item CPP | |
92 | ||
498646e0 | 93 | g++ -DONLINE_JUDGE -std=gnu++11 -fabi-version=6 -Wall -Wextra -O2 -o $output $input |
69c25408 MG |
94 | |
95 | =item MONO | |
96 | ||
97 | gmcs -d:ONLINE_JUDGE $input | |
98 | ||
99 | =item JAVA | |
100 | ||
101 | javac $input | |
102 | ||
6d1f2d94 S |
103 | =item JULIA |
104 | ||
105 | cp $input $output | |
106 | ||
69c25408 MG |
107 | =item PASCAL |
108 | ||
0005d3ad | 109 | fpc -dONLINE_JUDGE -O2 $input |
69c25408 | 110 | |
498646e0 MG |
111 | =item GOLANG |
112 | ||
113 | go build -compiler gc $input | |
114 | ||
115 | =item GCCGO | |
116 | ||
117 | go build -compiler gccgo $input | |
118 | ||
119 | =item HASKELL | |
120 | ||
121 | ghc -DONLINE_JUDGE -Wall -O2 -o $output $input | |
122 | ||
34e16771 S |
123 | =item OCAML |
124 | ||
125 | ocamlc -o $output $input | |
126 | ||
27be8560 S |
127 | =item RUST |
128 | ||
129 | rustc -O -o $output $input | |
130 | ||
69c25408 MG |
131 | =item PERL |
132 | ||
133 | cp $input $output | |
134 | ||
8473542d S |
135 | =item PHP |
136 | ||
137 | cp $input $output | |
138 | ||
69c25408 MG |
139 | =item PYTHON |
140 | ||
141 | cp $input $output | |
142 | ||
143 | =back | |
144 | ||
145 | =head1 AUTHOR | |
146 | ||
147 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
148 | ||
149 | =head1 COPYRIGHT AND LICENSE | |
150 | ||
151 | Copyright (C) 2014 by Marius Gavrilescu | |
152 | ||
153 | This program is free software: you can redistribute it and/or modify | |
154 | it under the terms of the GNU Affero General Public License as published by | |
155 | the Free Software Foundation, either version 3 of the License, or | |
156 | (at your option) any later version. | |
157 | ||
158 | ||
159 | =cut |