229eb9887ec0797bd9ad5ae72ae562b6b4783daa
[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 my $ret = fork // die $!;
12 if ($ret) {
13 $SIG{ALRM} = sub {kill KILL => $ret};
14 alarm 5;
15 wait;
16 exit $? >> 8
17 } else {
18 given ($format){
19 exec 'gcc', qw/-DONLINE_JUDGE -std=gnu11 -Wall -Wextra -O2 -o/, $basename, $name when 'C';
20 exec 'g++', qw/-DONLINE_JUDGE -std=gnu++11 -Wall -Wextra -O2 -o/, $basename, $name when 'CPP';
21 when ('MONO') {
22 system 'gmcs', '-d:ONLINE_JUDGE', $name and die "gmcs failed: errno=$! return=$?";
23 rename "$basename.exe", $basename;
24 chmod 0755, $basename;
25 }
26 exec 'gmcs', '-d:ONLINE_JUDGE', $name when 'MONO';
27 when ('JAVA') {
28 system 'javac', $name and die "javac failed: errno=$! return=$?";
29 system 'jar', 'cfe', $basename, $basename, "$basename.class" and die "jar failed: errno=$! return=$?";
30 chmod 0755, $basename;
31 exit
32 }
33 exec 'fpc', qw/-dONLINE_JUDGE -O2/, $name when 'PASCAL';
34 exec 'go', qw/build -compiler gc/, $name when 'GOLANG';
35 exec 'go', qw/build -compiler gccgo/, $name, when 'GCCGO';
36 exec 'ghc', qw/-DONLINE_JUDGE -Wall -O2 -o/, $basename, $name when 'HASKELL';
37
38 when ([qw/PERL PYTHON/]){
39 open IN, '<', $name;
40 open OUT, '>', $basename;
41 print OUT "#!/usr/bin/perl\n" if $_ eq 'PERL';
42 print OUT "#!/usr/bin/python\n" if $_ eq 'PYTHON';
43 print OUT while <IN>;
44 close OUT;
45 close IN;
46 chmod 0755, $basename;
47 exit
48 }
49 }
50 }
51
52 exit 1;
53 __END__
54
55 =encoding utf-8
56
57 =head1 NAME
58
59 gruntmaster-compile - Gruntmaster 6000 compiler frontend
60
61 =head1 SYNOPSIS
62
63 gruntmaster-compile CPP file.cpp
64 gruntmaster-compile JAVA file.java
65
66 =head1 DESCRIPTION
67
68 gruntmaster-compile is a very simple frontend to various comilers. 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.
69
70 Compile commands for each format:
71
72 =over
73
74 =item C
75
76 gcc -DONLINE_JUDGE -std=gnu11 -Wall -Wextra -O2 -o $output $input
77
78 =item CPP
79
80 g++ -DONLINE_JUDGE -std=gnu++11 -fabi-version=6 -Wall -Wextra -O2 -o $output $input
81
82 =item MONO
83
84 gmcs -d:ONLINE_JUDGE $input
85
86 =item JAVA
87
88 javac $input
89
90 =item PASCAL
91
92 fpc -dONLINE_JUDGE -O2 $input
93
94 =item GOLANG
95
96 go build -compiler gc $input
97
98 =item GCCGO
99
100 go build -compiler gccgo $input
101
102 =item HASKELL
103
104 ghc -DONLINE_JUDGE -Wall -O2 -o $output $input
105
106 =item PERL
107
108 cp $input $output
109
110 =item PYTHON
111
112 cp $input $output
113
114 =back
115
116 =head1 AUTHOR
117
118 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
119
120 =head1 COPYRIGHT AND LICENSE
121
122 Copyright (C) 2014 by Marius Gavrilescu
123
124 This program is free software: you can redistribute it and/or modify
125 it under the terms of the GNU Affero General Public License as published by
126 the Free Software Foundation, either version 3 of the License, or
127 (at your option) any later version.
128
129
130 =cut
This page took 0.05855 seconds and 4 git commands to generate.