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