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