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 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
use ExtUtils::MakeMaker ;
use strict ;
use File::Spec ;
use Cwd ;
use Config ;
require "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){
my $def_pl = File::Spec->catfile('Java', 'default_j2sdk.pl') ;
if (-e $def_pl){
require File::Spec->catfile('Java', 'default_j2sdk.pl') ;
$jdk_dir = Inline::Java::get_default_j2sdk() ;
}
else {
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') ;
foreach my $f ('javac', 'jar', 'java'){
if (! -f File::Spec->catfile($jdk_dir, $jdk_bin, $f . $ext)){
my $bf = File::Spec->catfile($jdk_bin, $f . $ext) ;
print "Can't locate file '$bf' anywhere under '$jdk_dir'\n" ;
}
}
# 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('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::Spec->catfile($jdk_dir, $jdk_bin, 'javac' . $ext) ;
my $jar = File::Spec->catfile($jdk_dir, $jdk_bin, 'jar' . $ext) ;
my $src_dir = File::Spec->catdir('Java', 'sources', 'org', 'perl', 'inline', 'java') ;
my $src = File::Spec->catfile($src_dir, '*.java') ;
my $obj_dir = File::Spec->catdir('Java', 'classes') ;
my $server_arch = File::Spec->catfile('Java', 'InlineJavaServer.jar') ;
my $user_arch = File::Spec->catfile('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': $!") ;
}
sub MY::top_targets {
my $this = shift ;
my $make = <<MAKE ;
# Added by Inline::Java installation
pure_all :: java
MAKE
return $make . $this->MM::top_targets() ;
}
my $INSTALLSITEARCH = '' ;
my $INST_ARCHLIB = '' ;
sub MY::postamble {
my $this = shift ;
my $java_src = join(' ', glob($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
"$jar" cf $server_arch -C $obj_dir org -C $obj_dir InlineJava.properties
"$jar" cf $user_arch -C $obj_dir InlineJavaUserClassLink.class
\@\$(TOUCH) java.ts
java :: java.ts
MAKE
# Used for PerlNatives
$INSTALLSITEARCH = expand_macros($this, 'INSTALLSITEARCH') ;
$INST_ARCHLIB = expand_macros($this, 'INST_ARCHLIB') ;
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 ;
}
# Write the Makefile
my $natives_test = File::Spec->catdir('Java', 'Natives', '_Inline_test') ;
my $perlinterp_test = File::Spec->catdir('Java', 'PerlInterpreter', '_Inline_test') ;
WriteMakefile(
NAME => 'Inline::Java',
VERSION_FROM => 'Java.pm',
MIN_PERL_VERSION => '5.008',
DIR => ['Java'],
PREREQ_PM => {
Inline => 0.68,
'Inline::C' => 0.62,
Test => 1.13,
'MIME::Base64' => 0,
},
PM => {
'Java.pm' => File::Spec->catfile('$(INST_LIBDIR)', 'Java.pm'),
'Java.pod'=> File::Spec->catfile('$(INST_LIBDIR)', 'Java.pod'),
$server_arch => File::Spec->catfile('$(INST_LIBDIR)', $server_arch),
$user_arch => File::Spec->catfile('$(INST_LIBDIR)', $user_arch),
},
clean => {FILES => "$def_jdk _Inline_test $natives_test $perlinterp_test $obj_dir $server_arch $user_arch java.ts"},
ABSTRACT_FROM => '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',
},
},
no_index => { directory => [qw(Java/*)], file => [qw(Java/*.pm)] },
},
) ;
# 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) ;
# Clean up the Makefile for Win95/98/Me
if (Inline::Java::Portable::portable('COMMAND_COM')){
print "\nFixing Makefile for Win95/98/Me...\n" ;
open(MAKEFILE, "<Makefile") or die "Can't open Makefile for reading" ;
my @lines = <MAKEFILE> ;
close(MAKEFILE) ;
open(MAKEFILE, ">Makefile") or die "Can't open Makefile for writing" ;
foreach my $line (@lines){
if ($line !~ /^\s*((\@\[)|(\]))\s*$/){
print MAKEFILE $line ;
}
}
close(MAKEFILE) ;
}
my $make = Inline::Java::Portable::portable('MAKE') ;
print "\nYou can continue the installation with the following commands:\n" ;
print " % $make\n" ;
print " % $make test\n" ;
print " % $make install\n" ;
|