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