]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl -w | |
2 | use v5.14; | |
3 | no if $] > 5.017011, warnings => 'experimental::smartmatch'; | |
4 | ||
5 | use File::Copy qw/copy/; | |
6 | use File::Basename qw/fileparse/; | |
7 | ||
8 | my ($format, $name) = @ARGV; | |
9 | my $basename = fileparse $name, qr/\..*/; | |
10 | ||
11 | given ($format){ | |
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'; | |
14 | when ('MONO') { | |
15 | system 'gmcs', '-d:ONLINE_JUDGE', $name and die "gmcs failed: errno=$! return=$?"; | |
16 | rename "$basename.exe", $basename; | |
17 | chmod 0755, $basename; | |
18 | } | |
19 | exec 'gmcs', '-d:ONLINE_JUDGE', $name when 'MONO'; | |
20 | when ('JAVA') { | |
21 | unlink $_ for <*.class>; | |
22 | system 'javac', $name and die "javac failed: errno=$! return=$?"; | |
23 | system 'jar', 'cfe', $basename, $basename, <*.class> and die "jar failed: errno=$! return=$?"; | |
24 | chmod 0755, $basename; | |
25 | exit | |
26 | } | |
27 | exec 'fpc', qw/-dONLINE_JUDGE -O2/, $name when 'PASCAL'; | |
28 | exec 'go', qw/build -compiler gc/, $name when 'GOLANG'; | |
29 | exec 'go', qw/build -compiler gccgo/, $name, when 'GCCGO'; | |
30 | exec 'ghc', qw/-DONLINE_JUDGE -Wall -O2 -o/, $basename, $name when 'HASKELL'; | |
31 | exec 'rustc', qw/-O -o/, $basename, $name when 'RUST'; | |
32 | ||
33 | when ([qw/GOLFSCRIPT PERL PYTHON RUBY SBCL/]){ | |
34 | open IN, '<', $name; | |
35 | open OUT, '>', $basename; | |
36 | print OUT "#!/usr/bin/golfscript\n" if $_ eq 'GOLFSCRIPT'; | |
37 | print OUT "#!/usr/bin/perl\n" if $_ eq 'PERL'; | |
38 | print OUT "#!/usr/bin/python\n" if $_ eq 'PYTHON'; | |
39 | print OUT "#!/usr/bin/ruby\n" if $_ eq 'RUBY'; | |
40 | print OUT "#!/usr/bin/sbcl --script\n" if $_ eq 'SBCL'; | |
41 | print OUT while <IN>; | |
42 | close OUT; | |
43 | close IN; | |
44 | chmod 0755, $basename; | |
45 | exit | |
46 | } | |
47 | } | |
48 | ||
49 | exit 1; | |
50 | __END__ | |
51 | ||
52 | =encoding utf-8 | |
53 | ||
54 | =head1 NAME | |
55 | ||
56 | gruntmaster-compile - Gruntmaster 6000 compiler frontend | |
57 | ||
58 | =head1 SYNOPSIS | |
59 | ||
60 | gruntmaster-compile CPP file.cpp | |
61 | gruntmaster-compile JAVA file.java | |
62 | ||
63 | =head1 DESCRIPTION | |
64 | ||
65 | 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. | |
66 | ||
67 | Compile commands for each format: | |
68 | ||
69 | =over | |
70 | ||
71 | =item C | |
72 | ||
73 | gcc -DONLINE_JUDGE -std=gnu11 -Wall -Wextra -O2 -o $output $input | |
74 | ||
75 | =item CPP | |
76 | ||
77 | g++ -DONLINE_JUDGE -std=gnu++11 -fabi-version=6 -Wall -Wextra -O2 -o $output $input | |
78 | ||
79 | =item MONO | |
80 | ||
81 | gmcs -d:ONLINE_JUDGE $input | |
82 | ||
83 | =item JAVA | |
84 | ||
85 | javac $input | |
86 | ||
87 | =item PASCAL | |
88 | ||
89 | fpc -dONLINE_JUDGE -O2 $input | |
90 | ||
91 | =item GOLANG | |
92 | ||
93 | go build -compiler gc $input | |
94 | ||
95 | =item GCCGO | |
96 | ||
97 | go build -compiler gccgo $input | |
98 | ||
99 | =item HASKELL | |
100 | ||
101 | ghc -DONLINE_JUDGE -Wall -O2 -o $output $input | |
102 | ||
103 | =item RUST | |
104 | ||
105 | rustc -O -o $output $input | |
106 | ||
107 | =item PERL | |
108 | ||
109 | cp $input $output | |
110 | ||
111 | =item PYTHON | |
112 | ||
113 | cp $input $output | |
114 | ||
115 | =back | |
116 | ||
117 | =head1 AUTHOR | |
118 | ||
119 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
120 | ||
121 | =head1 COPYRIGHT AND LICENSE | |
122 | ||
123 | Copyright (C) 2014 by Marius Gavrilescu | |
124 | ||
125 | This program is free software: you can redistribute it and/or modify | |
126 | it under the terms of the GNU Affero General Public License as published by | |
127 | the Free Software Foundation, either version 3 of the License, or | |
128 | (at your option) any later version. | |
129 | ||
130 | ||
131 | =cut |