]>
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'; |
9c1ab914 | 33 | |
fb85e61f S |
34 | when ('BRAINFUCK') { |
35 | system 'bfc', $name and die "bfc failed: errno=$! return=$?"; | |
36 | rename "a.out", $basename; | |
37 | chmod 0755, $basename; | |
38 | exit | |
39 | } | |
40 | ||
6d1f2d94 | 41 | when ([qw/GOLFSCRIPT JULIA PERL PYTHON RUBY SBCL/]){ |
9c1ab914 MG |
42 | open IN, '<', $name; |
43 | open OUT, '>', $basename; | |
f8b954a9 | 44 | print OUT "#!/usr/bin/golfscript\n" if $_ eq 'GOLFSCRIPT'; |
6d1f2d94 | 45 | print OUT "#!/usr/bin/julia -O\n" if $_ eq 'JULIA'; |
dbd5d64f MG |
46 | print OUT "#!/usr/bin/perl\n" if $_ eq 'PERL'; |
47 | print OUT "#!/usr/bin/python\n" if $_ eq 'PYTHON'; | |
c4d90e6f | 48 | print OUT "#!/usr/bin/ruby\n" if $_ eq 'RUBY'; |
dbd5d64f | 49 | print OUT "#!/usr/bin/sbcl --script\n" if $_ eq 'SBCL'; |
9c1ab914 MG |
50 | print OUT while <IN>; |
51 | close OUT; | |
52 | close IN; | |
53 | chmod 0755, $basename; | |
54 | exit | |
9577371b | 55 | } |
da905f9e | 56 | } |
69c25408 | 57 | |
0e7e545a | 58 | exit 1; |
69c25408 MG |
59 | __END__ |
60 | ||
61 | =encoding utf-8 | |
62 | ||
63 | =head1 NAME | |
64 | ||
65 | gruntmaster-compile - Gruntmaster 6000 compiler frontend | |
66 | ||
67 | =head1 SYNOPSIS | |
68 | ||
69 | gruntmaster-compile CPP file.cpp | |
70 | gruntmaster-compile JAVA file.java | |
71 | ||
72 | =head1 DESCRIPTION | |
73 | ||
27be8560 | 74 | 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 |
75 | |
76 | Compile commands for each format: | |
77 | ||
78 | =over | |
79 | ||
fb85e61f S |
80 | =item BRAINFUCK |
81 | ||
82 | bfc $input | |
83 | ||
69c25408 MG |
84 | =item C |
85 | ||
86 | gcc -DONLINE_JUDGE -std=gnu11 -Wall -Wextra -O2 -o $output $input | |
87 | ||
88 | =item CPP | |
89 | ||
498646e0 | 90 | g++ -DONLINE_JUDGE -std=gnu++11 -fabi-version=6 -Wall -Wextra -O2 -o $output $input |
69c25408 MG |
91 | |
92 | =item MONO | |
93 | ||
94 | gmcs -d:ONLINE_JUDGE $input | |
95 | ||
96 | =item JAVA | |
97 | ||
98 | javac $input | |
99 | ||
6d1f2d94 S |
100 | =item JULIA |
101 | ||
102 | cp $input $output | |
103 | ||
69c25408 MG |
104 | =item PASCAL |
105 | ||
0005d3ad | 106 | fpc -dONLINE_JUDGE -O2 $input |
69c25408 | 107 | |
498646e0 MG |
108 | =item GOLANG |
109 | ||
110 | go build -compiler gc $input | |
111 | ||
112 | =item GCCGO | |
113 | ||
114 | go build -compiler gccgo $input | |
115 | ||
116 | =item HASKELL | |
117 | ||
118 | ghc -DONLINE_JUDGE -Wall -O2 -o $output $input | |
119 | ||
27be8560 S |
120 | =item RUST |
121 | ||
122 | rustc -O -o $output $input | |
123 | ||
69c25408 MG |
124 | =item PERL |
125 | ||
126 | cp $input $output | |
127 | ||
128 | =item PYTHON | |
129 | ||
130 | cp $input $output | |
131 | ||
132 | =back | |
133 | ||
134 | =head1 AUTHOR | |
135 | ||
136 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
137 | ||
138 | =head1 COPYRIGHT AND LICENSE | |
139 | ||
140 | Copyright (C) 2014 by Marius Gavrilescu | |
141 | ||
142 | This program is free software: you can redistribute it and/or modify | |
143 | it under the terms of the GNU Affero General Public License as published by | |
144 | the Free Software Foundation, either version 3 of the License, or | |
145 | (at your option) any later version. | |
146 | ||
147 | ||
148 | =cut |