Do not crash on compile errors
[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
da905f9e
MG
11my $ret = fork // die $!;
12if ($ret) {
9577371b
MG
13 $SIG{ALRM} = sub {kill KILL => $ret};
14 alarm 5;
15 wait;
16 exit $? >> 8
da905f9e 17} else {
9577371b 18 given ($format){
69c25408
MG
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 -fabi-version=6 -Wall -Wextra -O2 -o/, $basename, $name when 'CPP';
9577371b
MG
21 exec 'gmcs', '-d:ONLINE_JUDGE', $name when 'MONO';
22 exec 'javac', $name when 'JAVA';
4e02269f 23 exec 'fpc', qw/-dONLINE_JUDGE -O2/, $name when 'PASCAL';
9577371b
MG
24 copy $name, $basename when ['PERL', 'PYTHON']
25 }
da905f9e 26}
69c25408
MG
27
28__END__
29
30=encoding utf-8
31
32=head1 NAME
33
34gruntmaster-compile - Gruntmaster 6000 compiler frontend
35
36=head1 SYNOPSIS
37
38 gruntmaster-compile CPP file.cpp
39 gruntmaster-compile JAVA file.java
40
41=head1 DESCRIPTION
42
43gruntmaster-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.
44
45Compile commands for each format:
46
47=over
48
49=item C
50
51 gcc -DONLINE_JUDGE -std=gnu11 -Wall -Wextra -O2 -o $output $input
52
53=item CPP
54
55 g++ -DONLINE_JUDGE -std=gnu11 -fabi-version=6 -Wall -Wextra -O2 -o $output $input
56
57=item MONO
58
59 gmcs -d:ONLINE_JUDGE $input
60
61=item JAVA
62
63 javac $input
64
65=item PASCAL
66
0005d3ad 67 fpc -dONLINE_JUDGE -O2 $input
69c25408
MG
68
69=item PERL
70
71 cp $input $output
72
73=item PYTHON
74
75 cp $input $output
76
77=back
78
79=head1 AUTHOR
80
81Marius Gavrilescu E<lt>marius@ieval.roE<gt>
82
83=head1 COPYRIGHT AND LICENSE
84
85Copyright (C) 2014 by Marius Gavrilescu
86
87This program is free software: you can redistribute it and/or modify
88it under the terms of the GNU Affero General Public License as published by
89the Free Software Foundation, either version 3 of the License, or
90(at your option) any later version.
91
92
93=cut
This page took 0.015594 seconds and 4 git commands to generate.