2 use ExtUtils::MakeMaker;
\r
5 $ARCHNAME = $Config{archname};
\r
8 getopts('e'); # embedding?
\r
10 $CCFLAGS .= $ENV{CCFLAGS} if defined $ENV{CCFLAGS};
\r
12 # $USE_KAFFE is a boolean that tells us whether or not we should use Kaffe.
\r
13 # Set by find_includes (it seemed as good a place as any).
\r
15 # Note that we don't check to see the version of Kaffe is one we support.
\r
16 # Currently, the only one we support is the one from CVS.
\r
20 #require "JNIConfig";
\r
22 if ($^O eq 'solaris') {
\r
23 $LIBPATH = " -R$Config{archlib}/CORE -L$Config{archlib}/CORE";
\r
24 } elsif ($^O eq 'MSWin32') {
\r
25 $LIBPATH = " -L$Config{archlib}\\CORE";
\r
26 # MSR - added MS VC++ default library path
\r
27 # bjepson - fixed to support path names w/spaces in them.
\r
28 push(@WINLIBS, (split"\;",$ENV{LIB}));
\r
29 grep s/\\$//, @WINLIBS; # eliminate trailing \
\r
30 grep s/\/$//, @WINLIBS; # eliminate trailing /
\r
31 $LIBPATH .= join(" ", "", map { qq["-L$_" ] } @WINLIBS);
\r
33 $LIBPATH = " -L$Config{archlib}/CORE";
\r
37 # Figure out where Java might live
\r
39 # MSR - added JDK 1.3
\r
42 my @JAVA_HOME_GUESSES = qw(/usr/local/java /usr/java /usr/local/jdk117_v3
\r
43 C:\\JDK1.1.8 C:\\JDK1.2.1 C:\\JDK1.2.2 C:\\JDK1.3 );
\r
45 my @KAFFE_PREFIX_GUESSES = qw(/usr/local /usr);
\r
47 if (! defined $ENV{JAVA_HOME}) {
\r
48 print "You didn't define JAVA_HOME, so I'm trying a few guesses.\n";
\r
49 print "If this fails, you might want to try setting JAVA_HOME and\n";
\r
50 print "running me again.\n";
\r
52 @JAVA_HOME_GUESSES = ( $ENV{JAVA_HOME} );
\r
55 if (! defined $ENV{KAFFE_PREFIX}) {
\r
56 print "\nYou didn't define KAFFE_PREFIX, so I'm trying a few guesses.",
\r
57 "\nIf this fails, and you are using Kaffe, you might want to try\n",
\r
58 "setting KAFFE_PREFIX and running me again.\n",
\r
59 "If you want to ignore any possible Kaffe installation, set the\n",
\r
60 "KAFFE_PREFIX to and empty string.\n\n";
\r
62 @KAFFE_PREFIX_GUESSES = ($ENV{KAFFE_PREFIX} eq "") ? () :
\r
63 ( $ENV{KAFFE_PREFIX} );
\r
66 my(@KAFFE_INCLUDE_GUESSES, @KAFFE_LIB_GUESSES);
\r
67 foreach my $kaffePrefix (@KAFFE_PREFIX_GUESSES) {
\r
68 push(@KAFFE_INCLUDE_GUESSES, "$kaffePrefix/include/kaffe");
\r
69 push(@KAFFE_LIB_GUESSES, "$kaffePrefix/lib");
\r
70 push(@KAFFE_LIB_GUESSES, "$kaffePrefix/lib/kaffe");
\r
72 $guess .= "/include/kaffe";
\r
74 # Let's find out where jni.h lives
\r
76 my @INCLUDE = find_includes();
\r
78 if ($^O eq 'MSWin32') {
\r
79 # MSR - added MS VC++ default include path
\r
80 push(@INCLUDE,(split"\;",$ENV{INCLUDE}));
\r
81 grep s/\\$//, @INCLUDE; # remove trailing \
\r
82 grep s/\/$//, @INCLUDE; # remove trailing \
\r
83 $INC = join("", map { qq["-I$_" ] } @INCLUDE);
\r
86 $INC = join(" -I", ("", @INCLUDE));
\r
89 # Let's find out the name of the Java shared library
\r
91 my @JAVALIBS = find_libs();
\r
93 # Find out some defines based on the library we are linking to
\r
95 foreach (@JAVALIBS) {
\r
96 if ( $^O eq 'MSWin32') { # We're on Win32
\r
100 $CCFLAGS .= " -DWIN32 -Z7 -D_DEBUG";
\r
101 $MYEXTLIB = "$libjava";
\r
105 $CCFLAGS .= " -DKAFFE" if ($USE_KAFFE);
\r
107 # Let's find out the path of the library we need to link against.
\r
109 foreach (@JAVALIBS) {
\r
110 if ($^O eq 'MSWin32') { # We're on Win32
\r
113 my ($libname, $libpath, $libsuffix) = fileparse($_, ("\.so", "\.lib"));
\r
114 $libname =~ s/^lib//;
\r
115 if ($^O eq 'solaris') {
\r
116 $LIBPATH .= " -R$libpath -L$libpath"
\r
118 $LIBPATH .= " -L$libpath"
\r
120 $LIBS .= " -l$libname";
\r
123 # Do we need -D_REENTRANT?
\r
124 if ($LIBPATH =~ /native/) {
\r
125 print "Looks like native threads...\n";
\r
126 $CCFLAGS .= " -D_REENTRANT";
\r
130 print "We're embedding Perl in Java via libPerlInterpreter.so.\n";
\r
131 eval `../setvars -perl`;
\r
132 $CCFLAGS .= " -DEMBEDDEDPERL";
\r
133 $LIBPATH .= " -R$ENV{JPL_HOME}/lib/$ARCHNAME -L$ENV{JPL_HOME}/lib/$ARCHNAME";
\r
134 $LIBS .= " -lPerlInterpreter";
\r
138 if ($^O eq 'solaris') {
\r
139 $LIBS = " -lthread -lc $LIBS"; #-lthread must be first!!!
\r
140 $CCFLAGS .= " -D_REENTRANT";
\r
143 # MSR - clean up LIBS
\r
147 # Next, build JNI/Config.pm. This is a superfluous thing for the SUN and
\r
148 # Microsoft JDKs, but absolutely necessary for Kaffe. I think at some
\r
149 # point, the Microsoft and SUN implementations should use JNI::Config, too.
\r
153 mkdir("JNI", 0755) || die "Unable to make JNI directory: $!";
\r
155 open(JNICONFIG, ">JNI/Config.pm") || die "Unable to open JNI/Config.pm: $!";
\r
157 print JNICONFIG "# DO NOT EDIT! Autogenerated by JNI/Makefile.PL\n\n",
\r
158 "package JNI::Config;\nuse strict;\nuse Carp;\n",
\r
159 "\nuse vars qw(\$KAFFE \$LIB_JAVA \$CLASS_HOME ",
\r
160 "\$LIB_HOME);\n\n",
\r
161 "\$KAFFE = $USE_KAFFE;\n\$LIB_JAVA = \"$JAVALIBS[0]\";\n";
\r
163 my $path = $JAVALIBS[0];
\r
164 $path =~ s%/(kaffe/)?libkaffevm.so$%%;
\r
166 print JNICONFIG "\$LIB_HOME = \"$path/kaffe\";\n";
\r
168 print JNICONFIG "\$CLASS_HOME = \"$path/share/kaffe\";\n";
\r
170 print JNICONFIG "\n\n1;\n";
\r
176 VERSION_FROM => 'JNI.pm',
\r
178 LINKTYPE => 'dynamic',
\r
180 CCFLAGS => "$Config{ccflags} $CCFLAGS",
\r
181 ($Config{archname} =~ /mswin32.*-object/i ? ('CAPI' => 'TRUE') : ()),
\r
183 clean => {FILES => "JNI/* JNI"}
\r
186 $Makefile{LIBS} = ["$LIBPATH $LIBS"];
\r
188 $Makefile{MYEXTLIB} = $MYEXTLIB;
\r
191 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
\r
192 # the contents of the Makefile that is written.
\r
194 WriteMakefile(%Makefile);
\r
197 my $path = $JAVALIBS[0];
\r
198 $path =~ s%/libkaffevm.so$%%;
\r
199 print "\n\n***NOTE: be sure to have:\n",
\r
200 " LD_LIBRARY_PATH=$path\n",
\r
201 " in your enviornment (or installed as a system dynamic\n",
\r
202 " library location) when you compile and run this.\n";
\r
205 # subroutine to find a library
\r
209 my ($candidates, $locations) = @_;
\r
212 foreach my $name (@$candidates) {
\r
213 if (/$name$/ and ! /green_threads/ and !/include-old/) {
\r
214 $lib = $File::Find::name;
\r
220 foreach my $guess (@$locations) {
\r
221 next unless -d $guess;
\r
222 find (\&$wanted, $guess);
\r
225 print "Could not find @$candidates\n";
\r
227 print "Found @$candidates as $lib\n\n";
\r
232 # Extra lib for Java 1.2
\r
234 # if we want KAFFE, check for it, otherwise search for Java
\r
237 my($libjava, $libawt, $libjvm);
\r
240 $libjava = find_stuff(['libkaffevm.so'], \@KAFFE_LIB_GUESSES);
\r
241 $libawt = find_stuff(['libawt.so'], \@KAFFE_LIB_GUESSES);
\r
243 $libjava = find_stuff(['libjava.so', 'javai.lib', 'jvm.lib'],
\r
244 \@JAVA_HOME_GUESSES);
\r
245 $libjvm = find_stuff(['libjvm.so'], \@JAVA_HOME_GUESSES);
\r
246 $libawt = find_stuff(['libawt.so'], \@JAVA_HOME_GUESSES);
\r
247 if (defined $libjvm) { # JDK 1.2
\r
248 my $libhpi = find_stuff(['libhpi.so'], \@JAVA_HOME_GUESSES);
\r
249 return($libjava, $libjvm, $libhpi, $libawt);
\r
252 return($libjava, $libawt);
\r
255 # We need to find jni.h and jni_md.h
\r
258 # Always do find_includes as the first operation, as it has the side effect
\r
259 # of deciding whether or not we are looking for Kaffe. --bkuhn
\r
261 sub find_includes {
\r
263 my @CANDIDATES = qw(jni.h jni_md.h);
\r
267 foreach my $name (@CANDIDATES) {
\r
269 my ($hname, $hpath, $hsuffix) =
\r
270 fileparse($File::Find::name, ("\.h", "\.H"));
\r
271 unless ($hpath =~ /include-old/) {
\r
272 print "Found $hname$hsuffix in $hpath\n";
\r
273 push @includes, $hpath;
\r
280 foreach my $guess (@KAFFE_INCLUDE_GUESSES) {
\r
281 next unless -d $guess;
\r
282 find (\&find_inc, $guess);
\r
284 # If we have found includes, then we are using Kaffe.
\r
285 if (@includes > 0) {
\r
288 foreach my $guess (@JAVA_HOME_GUESSES) {
\r
289 next unless -d $guess;
\r
290 find (\&find_inc, $guess);
\r
293 die "Could not find Java includes!" unless (@includes);
\r