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