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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
use ExtUtils::MakeMaker ;
use strict ;
use File::Spec ;
use Cwd ;
use Config ;
use lib 'lib'; # perl 5.26+
require "Inline/Java/Portable.pm" ;
print "\nWelcome to the Inline::Java installation procedure.\n\n" ;
# Hide PerlNatives by default...
$main::build_perl_natives = 0 ;
# Grab the J2SDK argument
my $jdk_dir = '' ;
for (my $i = 0 ; $i < scalar(@ARGV) ; $i++){
my $remove = 0 ;
if ($ARGV[$i] =~ /^J2SDK=(.+)$/){
$jdk_dir = $1 ;
$remove = 1 ;
}
elsif ($ARGV[$i] =~ /^BUILD_JNI=(.+)$/){
$main::build_jni = $1 ;
$remove = 1 ;
}
elsif ($ARGV[$i] =~ /^BUILD_PERL_NATIVES=(.+)$/){
$main::build_perl_natives = $1 ;
$remove = 1 ;
}
elsif ($ARGV[$i] =~ /^BUILD_PERL_INTERPRETER=(.+)$/){
$main::build_perl_interpreter = $1 ;
$remove = 1 ;
}
elsif ($ARGV[$i] =~ /^JVM_LIB_TYPE=(.+)$/){
$main::jvm_lib_type = $1 ;
$remove = 1 ;
}
if ($remove){
splice(@ARGV, $i, 1) ;
$i-- ;
}
}
if (! $jdk_dir){
my $try = $ENV{PERL_INLINE_JAVA_J2SDK} || $ENV{JAVA_HOME}
|| Inline::Java::Portable::portable('DEFAULT_J2SDK_DIR') ;
print "Using $try as J2SDK directory.\n\n" if $try ;
$jdk_dir = $try ;
}
if (! $jdk_dir){
print <<NO_J2SDK;
A Java 2 SDK is required to install and use Inline::Java. Please
specify your Java 2 SDK installation directory using the J2SDK
option to Makefile.PL as such:
perl Makefile.PL J2SDK=/path/to/your/j2sdk/installation
You can set the JAVA_HOME environment variable to specify your
Java 2 SDK installation directory. For example, if you are using
the CPAN installer you can do:
JAVA_HOME=/path/to/your/j2sdk/installation cpan Inline::Java
NO_J2SDK
exit(1) ;
}
elsif (! -d $jdk_dir){
print <<BAD_J2SDK;
Java 2 SDK installation directory '$jdk_dir' does not exist.
BAD_J2SDK
exit(1) ;
}
my $perl_jdk_dir = $jdk_dir ;
$perl_jdk_dir =~ s/'/\'/g ;
# Check directory
my $jdk_bin = Inline::Java::Portable::portable("J2SDK_BIN") ;
my $ext = Inline::Java::Portable::portable('EXE_EXTENSION') ;
$ENV{PATH} .= $Config{path_sep} . File::Spec->catdir($jdk_dir, $jdk_bin);
require File::Which;
print "Can't locate file '$_' in PATH\n"
for grep !File::Which::which($_), 'javac', 'jar', 'java';
# Now we have the J2SDK directory and it exists.
# We will create the default_j2sdk.pl file that
# will contain that value for future use.
my $def_jdk = File::Spec->catfile(qw(lib Inline Java default_j2sdk.pl)) ;
open(J2SDK, ">$def_jdk") or
die("Can't open '$def_jdk' for writing: $!") ;
print J2SDK <<J2SDK_PL;
# This file is created by the Makefile.PL for Inline::Java
# You can modify it if you wish
use strict ;
# The default J2SDK to use for Inline::Java. You can change
# it if this value becomes invalid.
sub Inline::Java::get_default_j2sdk {
return '$perl_jdk_dir' ;
}
1 ;
J2SDK_PL
close(J2SDK) ;
print <<SAVE_J2SDK;
Default J2SDK for Inline::Java will be '$jdk_dir'.
See module documentation for information on how to use a different J2SDK
or change this default value.
SAVE_J2SDK
# We will now add the building of our Java files to the Makefile.
my $javac = File::Which::which('javac');
my $jar = File::Which::which('jar');
my $src_dir = File::Spec->catdir('Java', 'sources', 'org', 'perl', 'inline', 'java') ;
my @src = glob File::Spec->catfile($src_dir, '*.java') ;
my $obj_dir = File::Spec->catdir('Java', 'classes') ;
my $server_arch = File::Spec->catfile(qw(lib Inline Java InlineJavaServer.jar)) ;
my $user_arch = File::Spec->catfile(qw(lib Inline Java InlineJavaUser.jar)) ;
# Create the object diretory because later we need to put the properties
# file inside it.
if (! -e $obj_dir){
mkdir($obj_dir) or
die("Can't create object directory '$obj_dir': $!") ;
}
my $INSTALLSITEARCH = '' ;
my $INST_ARCHLIB = '' ;
sub MY::postamble {
my $this = shift ;
my $java_src = join(' ', @src, File::Spec->catfile($obj_dir, 'InlineJava.properties')) ;
my $make = <<MAKE ;
# Added by Inline::Java installation
JAVA_SRC=$java_src
java.ts: \$(JAVA_SRC)
\@\$(MKPATH) $obj_dir
"$javac" -deprecation -g -d $obj_dir @src
\@\$(TOUCH) java.ts
$server_arch : java.ts
"$jar" cf $server_arch -C $obj_dir org -C $obj_dir InlineJava.properties
$user_arch : java.ts
"$jar" cf $user_arch -C $obj_dir InlineJavaUserClassLink.class
MAKE
# Used for PerlNatives
$INSTALLSITEARCH = expand_macros($this, 'INSTALLVENDORARCH') ;
$INST_ARCHLIB = expand_macros($this, 'INSTALLVENDORARCH') ;
return $make ;
}
sub expand_macros {
my $mm = shift ;
my $var = shift ;
my $val = $mm->{$var} ;
while ($val =~ s/\$\((.*?)\)/$mm->{$1}/){}
$val =~ s/\\/\\\\/g ;
return $val ;
}
my @subfiles = glob File::Spec->catfile(qw(lib Inline Java *.*));
my $subprefix = File::Spec->catdir(qw(lib Inline));
# Write the Makefile
WriteMakefile(
NAME => 'Inline::Java',
VERSION_FROM => 'lib/Inline/Java.pm',
MIN_PERL_VERSION => '5.008',
LICENSE => 'artistic_2',
DIR => ['Java'],
BUILD_REQUIRES => {
'ExtUtils::MakeMaker' => '7.30',
},
XSMULTI => 1,
CONFIGURE_REQUIRES => {
'ExtUtils::MakeMaker' => '7.30',
'File::Which' => 0,
},
PREREQ_PM => {
Inline => 0.68,
Test => 1.13,
'MIME::Base64' => 0,
},
PM => {
'lib/Inline/Java.pm' => File::Spec->catfile('$(INST_LIBDIR)', 'Java.pm'),
'lib/Inline/Java.pod'=> File::Spec->catfile('$(INST_LIBDIR)', 'Java.pod'),
map { my $f = $_; $f =~ s#\Q$subprefix\E#\$(INST_LIBDIR)#; ($_ => $f) } @subfiles, $server_arch, $user_arch,
},
clean => {FILES => "$def_jdk _Inline $obj_dir $server_arch $user_arch java.ts"},
ABSTRACT_FROM => 'lib/Inline/Java.pod', # retrieve abstract from module
AUTHOR => 'Patrick LeBoutillier <patl@cpan.org>',
META_MERGE => {
"meta-spec" => { version => 2 },
resources => {
repository => {
type => 'git',
url => 'https://github.com/ingydotnet/Inline-Java',
web => 'https://github.com/ingydotnet/Inline-Java',
},
},
prereqs => {
develop => {
requires => {
'Test::CheckManifest' => '0.9',
},
},
},
},
);
# Add the so_dirs to the default_j2sdk.pl file.
open(J2SDK, ">>$def_jdk") or
die("Can't open '$def_jdk' for appending: $!") ;
print J2SDK <<J2SDK_PL;
sub Inline::Java::get_default_j2sdk_so_dirs {
return (
J2SDK_PL
foreach my $d (sort @main::SO_DIRS){
$d =~ s/'/\'/g ;
print J2SDK "\t\t'$d',\n" ;
}
print J2SDK <<J2SDK_PL;
) ;
}
1 ;
J2SDK_PL
close(J2SDK) ;
# Create the properties that will be included in the jar.
my @perlnatives_so_parts = ("auto", "Inline", "Java", "PerlNatives",
"PerlNatives." . Inline::Java::Portable::portable('SO_EXT')) ;
my $install_perlnatives_so = File::Spec->catfile($INSTALLSITEARCH, @perlnatives_so_parts) ;
$install_perlnatives_so = Inline::Java::Portable::portable("SUB_FIX_JAVA_PATH", $install_perlnatives_so) ;
$install_perlnatives_so =~ s/\\/\\\\/g ;
my $test_perlnatives_so = File::Spec->rel2abs(File::Spec->catfile($INST_ARCHLIB, @perlnatives_so_parts)) ;
$test_perlnatives_so = Inline::Java::Portable::portable("SUB_FIX_JAVA_PATH", $test_perlnatives_so) ;
$test_perlnatives_so =~ s/\\/\\\\/g ;
my @perlinterpreter_so_parts = ("auto", "Inline", "Java", "PerlInterpreter",
"PerlInterpreter." . Inline::Java::Portable::portable('SO_EXT')) ;
my $install_perlinterpreter_so = File::Spec->catfile($INSTALLSITEARCH, @perlinterpreter_so_parts) ;
$install_perlinterpreter_so = Inline::Java::Portable::portable("SUB_FIX_JAVA_PATH", $install_perlinterpreter_so) ;
$install_perlinterpreter_so =~ s/\\/\\\\/g ;
my $test_perlinterpreter_so = File::Spec->rel2abs(File::Spec->catfile($INST_ARCHLIB, @perlinterpreter_so_parts)) ;
$test_perlinterpreter_so = Inline::Java::Portable::portable("SUB_FIX_JAVA_PATH", $test_perlinterpreter_so) ;
$test_perlinterpreter_so =~ s/\\/\\\\/g ;
my $libperl = $Config{libperl} ;
my $dlext = $Config{dlext} ;
my $libperl_so = '' ;
if ($libperl =~ /\.$dlext$/){
$libperl_so = File::Spec->catfile($Config{installarchlib}, 'CORE', $libperl) ;
}
my $prop = File::Spec->catfile($obj_dir, 'InlineJava.properties') ;
open(PROP, ">$prop") or
die("Can't open '$prop' for writing: $!") ;
print PROP <<PROP;
# This file is created by the Makefile.PL for Inline::Java
inline_java_perlnatives_so_install = $install_perlnatives_so
inline_java_perlnatives_so_test = $test_perlnatives_so
inline_java_perlinterpreter_so_install = $install_perlinterpreter_so
inline_java_perlinterpreter_so_test = $test_perlinterpreter_so
inline_java_libperl_so = $libperl_so
PROP
close(PROP) ;
|