summaryrefslogtreecommitdiff
path: root/debian/gij-wrapper-BV
blob: 114ec1bed9d095a62fe81a631e9f46dc6ded4401 (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
92
93
94
95
96
97
98
#!/usr/bin/perl -w
#
# Starts the GNU Java interpreter.
#
# Command-line arguments should be in the style of Sun's Java runtime;
# these will be converted to gij arguments before being passed to the
# gij itself.
#
# The Debian JNI module directory and any other specified JNI
# directories will be included on the JNI search path.
#
# Copyright (C) 2002-2003 by Ben Burton <bab@debian.org>
# Based on the original gij-wrapper-3.2 shell script.

use strict;

# The real Java runtime:
my $javaRuntime = '/usr/bin/gij-@BV@';

# The debian JNI module directory:
my $debianJNIDir = '/usr/lib/jni';

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

# The full JNI search path to use:
my $JNIPath = '';

# Build the command-line from the arguments given.
my $parsingOptions = 1;

# Flag used to copy argument to -classpath or -cp.
my $copyNext = 0;
foreach my $arg (@ARGV) {
  if (not $parsingOptions) {
    # We're done parsing options; just copy all remaining arguments directly.
    push @commandLine, $arg;
    next;
  }
  if ($copyNext) {
    push @commandLine, $arg;
    $copyNext = 0;
    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 '-cp' or $arg eq '--cp') {
    push @commandLine, '-cp';
    $copyNext = 1;
  } elsif ($arg eq '-classpath' or $arg eq '--classpath') {
    push @commandLine, '-classpath';
    $copyNext = 1;
  } elsif ($arg =~ /^-Djava.library.path=(.+)$/) {
    # A component of the JNI search path has been given.
    if ($JNIPath) {
      $JNIPath = $JNIPath . ':' . $1;
    } else {
      $JNIPath = $1;
    }
  } elsif ($arg eq '-jar' or $arg =~ /^-D/) {
    # Copy the argument directly.
    push @commandLine, $arg;
  } elsif ($arg =~ /^-/) {
    # An unrecognised option has been passed - just drop it.
  } else {
    # Some non-option argument has been given.
    # Stop parsing options at this point.
    push @commandLine, $arg;
    $parsingOptions = 0;
  }
}

# Add the debian JNI module directory to the JNI search path if it's not
# already there.
if ($JNIPath !~ /(^|:)$debianJNIDir($|:)/) {
  if ($JNIPath) {
    $JNIPath = $JNIPath . ':' . $debianJNIDir;
  } else {
    $JNIPath = $debianJNIDir;
  }
}

# Use environment variable $LTDL_LIBRARY_PATH to store the JNI path,
# since gij uses libltdl to dlopen JNI modules.
if ($ENV{LTDL_LIBRARY_PATH}) {
    $ENV{LTDL_LIBRARY_PATH} = $ENV{LTDL_LIBRARY_PATH} . ':' . $JNIPath;
} else {
    $ENV{LTDL_LIBRARY_PATH} = $JNIPath;
}

# Call the real Java runtime.
my @fullCommandLine = ( $javaRuntime );
push @fullCommandLine, @commandLine;
exec @fullCommandLine or exit(1);