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