summaryrefslogtreecommitdiff
path: root/debian/gcj-wrapper-BV
blob: 4648d7996a277b9db3665dd7b26dce5033959929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/perl -w
#
# Starts the GNU Java compiler.
#
# Command-line arguments should be in the style of Sun's Java compiler;
# these will be converted to gcj arguments before being passed to the
# gcj itself.
#
# Copyright (C) 2002-2003 by Ben Burton <bab@debian.org>
# Based on the original gcj-wrapper-3.2 shell script.

use strict;

# The real Java compiler:
my $javaCompiler = '/usr/bin/gcj-@BV@';

# The command-line arguments to pass to the real Java compiler:
my @commandLine;

# The warning flags to pass to the GNU Java compiler:
my $warnings = '-Wall';

# Build the command-line from the arguments given.
my $parsingOptions = 1;
my $copyNextArg = 0;
my $ignoreNextArg = 0;
my $appendNextArg = '';
foreach my $arg (@ARGV) {
    # See if we already know what to do with this argument.
    if ($ignoreNextArg) {
        # Throw it away.
        $ignoreNextArg = 0;
        next;
    } elsif ($copyNextArg or not $parsingOptions) {
        # Copy it directly.
        push @commandLine, $arg;
        $copyNextArg = 0;
        next;
    } elsif ($appendNextArg) {
        # Append it to $appendNextArg and then copy directly.
        push @commandLine, ($appendNextArg . $arg);
        $appendNextArg = '';
        next;
    }

    # Try to interpret Sun-style options.
    if ($arg eq '-version') {
        push @commandLine, '--version';
    } elsif ($arg eq '-h' or $arg eq '-help') {
        push @commandLine, '--help';
    } elsif ($arg eq '-classpath' or $arg eq '--classpath' or $arg eq '--cp') {
        $appendNextArg = '--classpath=';
    } elsif ($arg eq '-encoding' or $arg eq '-bootclasspath' or
             $arg eq '-extdirs') {
        $appendNextArg = '-' . $arg . '=';
    } elsif ($arg eq '-d') {
        push @commandLine, '-d';
        $copyNextArg = 1;
    } elsif ($arg eq '-nowarn') {
        $warnings = '';
    } elsif ($arg =~ /^-g/) {
        # Some kind of debugging option - just switch debugging on.
        push @commandLine, '-g' if ($arg ne '-g:none');
    } elsif ($arg eq '-O') {
        push @commandLine, '-O2';
    } elsif ($arg eq '-Xss') {
        push @commandLine, $arg;
    } elsif ($arg =~ /^-X/) {
        # An extended Sun option (which we don't support).
        push @commandLine, '--help' if ($arg eq '-X');
    } elsif ($arg eq '-source' or $arg eq '-sourcepath' or $arg eq '-target') {
        # An unsupported option with a following argument.
        $ignoreNextArg = 1;
    } elsif ($arg =~ /^-/) {
        # An unsupported standalone option.
    } else {
        # Some non-option argument has been given.
        # Stop parsing options at this point.
        push @commandLine, $arg;
        $parsingOptions = 0;
    }
}

# Was there a partial argument that was never completed?
push @commandLine, $appendNextArg if ($appendNextArg);

# Call the real Java compiler.
my @fullCommandLine = ( $javaCompiler, '-C' );
push @fullCommandLine, $warnings if ($warnings);
push @fullCommandLine, @commandLine;
exec @fullCommandLine or exit(1);