Add Oberon
[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';
34e16771 34 exec 'ocamlc', qw/-o/, $basename, $name when 'OCAML';
49b65824 35 exec 'dmd', qw/-version=ONLINE_JUDGE -O -release -inline -noboundscheck/, $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
8473542d 44 when ([qw/GOLFSCRIPT JULIA PERL PHP PYTHON 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';
8473542d
S
52 print OUT "#!/usr/bin/ruby\n" if $_ eq 'RUBY';
53 print OUT "#!/usr/bin/sbcl --script\n" if $_ eq 'SBCL';
9c1ab914
MG
54 print OUT while <IN>;
55 close OUT;
56 close IN;
57 chmod 0755, $basename;
58 exit
9577371b 59 }
da905f9e 60}
69c25408 61
0e7e545a 62exit 1;
69c25408
MG
63__END__
64
65=encoding utf-8
66
67=head1 NAME
68
69gruntmaster-compile - Gruntmaster 6000 compiler frontend
70
71=head1 SYNOPSIS
72
73 gruntmaster-compile CPP file.cpp
74 gruntmaster-compile JAVA file.java
75
76=head1 DESCRIPTION
77
27be8560 78gruntmaster-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
79
80Compile commands for each format:
81
82=over
83
fb85e61f
S
84=item BRAINFUCK
85
86 bfc $input
87
69c25408
MG
88=item C
89
90 gcc -DONLINE_JUDGE -std=gnu11 -Wall -Wextra -O2 -o $output $input
91
92=item CPP
93
498646e0 94 g++ -DONLINE_JUDGE -std=gnu++11 -fabi-version=6 -Wall -Wextra -O2 -o $output $input
69c25408
MG
95
96=item MONO
97
98 gmcs -d:ONLINE_JUDGE $input
99
100=item JAVA
101
102 javac $input
103
6d1f2d94
S
104=item JULIA
105
106 cp $input $output
107
69c25408
MG
108=item PASCAL
109
0005d3ad 110 fpc -dONLINE_JUDGE -O2 $input
69c25408 111
498646e0
MG
112=item GOLANG
113
114 go build -compiler gc $input
115
116=item GCCGO
117
118 go build -compiler gccgo $input
119
120=item HASKELL
121
122 ghc -DONLINE_JUDGE -Wall -O2 -o $output $input
123
34e16771
S
124=item OCAML
125
126 ocamlc -o $output $input
127
0220f51a
MG
128=item OBERON
129
130 obc -x -o $output $input
131
27be8560
S
132=item RUST
133
134 rustc -O -o $output $input
135
69c25408
MG
136=item PERL
137
138 cp $input $output
139
8473542d
S
140=item PHP
141
142 cp $input $output
143
69c25408
MG
144=item PYTHON
145
146 cp $input $output
147
148=back
149
150=head1 AUTHOR
151
152Marius Gavrilescu E<lt>marius@ieval.roE<gt>
153
154=head1 COPYRIGHT AND LICENSE
155
156Copyright (C) 2014 by Marius Gavrilescu
157
158This program is free software: you can redistribute it and/or modify
159it under the terms of the GNU Affero General Public License as published by
160the Free Software Foundation, either version 3 of the License, or
161(at your option) any later version.
162
163
164=cut
This page took 0.026279 seconds and 4 git commands to generate.