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