The latest JPL from the anoncvs.
[p5sagit/p5-mst-13.2.git] / jpl / JNI / Makefile.PL
CommitLineData
19956692 1#!/usr/bin/perl\r
2use ExtUtils::MakeMaker;\r
3use Getopt::Std;\r
4use Config;\r
5$ARCHNAME = $Config{archname};\r
6use File::Basename;\r
7\r
8getopts('e'); # embedding?\r
9\r
10$CCFLAGS .= $ENV{CCFLAGS} if defined $ENV{CCFLAGS};\r
11\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
14\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
17\r
18my $USE_KAFFE = 0;\r
19\r
20#require "JNIConfig";\r
21\r
22if ($^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
32} else {\r
33 $LIBPATH = " -L$Config{archlib}/CORE";\r
34}\r
35#$LIBS = " -lperl";\r
36\r
37# Figure out where Java might live\r
38#\r
39# MSR - added JDK 1.3\r
40#\r
41\r
42my @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
44\r
45my @KAFFE_PREFIX_GUESSES = qw(/usr/local /usr);\r
46\r
47if (! 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
51} else {\r
52 @JAVA_HOME_GUESSES = ( $ENV{JAVA_HOME} );\r
53}\r
54\r
55if (! 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
61} else {\r
62 @KAFFE_PREFIX_GUESSES = ($ENV{KAFFE_PREFIX} eq "") ? () :\r
63 ( $ENV{KAFFE_PREFIX} );\r
64}\r
65\r
66my(@KAFFE_INCLUDE_GUESSES, @KAFFE_LIB_GUESSES);\r
67foreach 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
71}\r
72 $guess .= "/include/kaffe";\r
73\r
74# Let's find out where jni.h lives\r
75#\r
76my @INCLUDE = find_includes();\r
77\r
78if ($^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
84\r
85} else {\r
86 $INC = join(" -I", ("", @INCLUDE));\r
87}\r
88\r
89# Let's find out the name of the Java shared library\r
90#\r
91my @JAVALIBS = find_libs();\r
92\r
93# Find out some defines based on the library we are linking to\r
94#\r
95foreach (@JAVALIBS) {\r
96 if ( $^O eq 'MSWin32') { # We're on Win32\r
97 $INC =~ s#/#\\#g;\r
98 $INC =~ s#\\$##;\r
99 print $INC, "\n";\r
100 $CCFLAGS .= " -DWIN32 -Z7 -D_DEBUG";\r
101 $MYEXTLIB = "$libjava";\r
102 }\r
103}\r
104\r
105$CCFLAGS .= " -DKAFFE" if ($USE_KAFFE);\r
106\r
107# Let's find out the path of the library we need to link against.\r
108#\r
109foreach (@JAVALIBS) {\r
110 if ($^O eq 'MSWin32') { # We're on Win32\r
111 $_ =~ s#/#\\\\#g;\r
112 }\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
117 } else {\r
118 $LIBPATH .= " -L$libpath"\r
119 }\r
120 $LIBS .= " -l$libname";\r
121}\r
122\r
123# Do we need -D_REENTRANT?\r
124if ($LIBPATH =~ /native/) {\r
125 print "Looks like native threads...\n";\r
126 $CCFLAGS .= " -D_REENTRANT";\r
127}\r
128\r
129if ($opt_e) {\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
135}\r
136\r
137# Needed for JNI.\r
138if ($^O eq 'solaris') {\r
139 $LIBS = " -lthread -lc $LIBS"; #-lthread must be first!!!\r
140 $CCFLAGS .= " -D_REENTRANT";\r
141}\r
142\r
143# MSR - clean up LIBS\r
144$LIBS =~ s/-l$//;\r
145\r
146#\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
150#\r
151\r
152if (! -d "JNI") {\r
153 mkdir("JNI", 0755) || die "Unable to make JNI directory: $!";\r
154}\r
155open(JNICONFIG, ">JNI/Config.pm") || die "Unable to open JNI/Config.pm: $!";\r
156\r
157print 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
162if ($USE_KAFFE) {\r
163 my $path = $JAVALIBS[0];\r
164 $path =~ s%/(kaffe/)?libkaffevm.so$%%;\r
165\r
166 print JNICONFIG "\$LIB_HOME = \"$path/kaffe\";\n";\r
167 $path =~ s%/lib%%;\r
168 print JNICONFIG "\$CLASS_HOME = \"$path/share/kaffe\";\n";\r
169}\r
170print JNICONFIG "\n\n1;\n";\r
171close JNICONFIG;\r
172\r
173\r
174my %Makefile = (\r
175 NAME => 'JNI',\r
176 VERSION_FROM => 'JNI.pm',\r
177 DEFINE => '',\r
178 LINKTYPE => 'dynamic',\r
179 INC => $INC,\r
180 CCFLAGS => "$Config{ccflags} $CCFLAGS", \r
181 ($Config{archname} =~ /mswin32.*-object/i ? ('CAPI' => 'TRUE') : ()),\r
182\r
183 clean => {FILES => "JNI/* JNI"}\r
184);\r
185\r
186$Makefile{LIBS} = ["$LIBPATH $LIBS"];\r
187if ($MYEXTLIB) {\r
188 $Makefile{MYEXTLIB} = $MYEXTLIB;\r
189}\r
190\r
191# See lib/ExtUtils/MakeMaker.pm for details of how to influence\r
192# the contents of the Makefile that is written.\r
193#\r
194WriteMakefile(%Makefile);\r
195\r
196if ($USE_KAFFE) {\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
203}\r
204\r
205# subroutine to find a library\r
206#\r
207sub find_stuff {\r
208\r
209 my ($candidates, $locations) = @_;\r
210 my $lib;\r
211 $wanted = sub {\r
212 foreach my $name (@$candidates) {\r
213 if (/$name$/ and ! /green_threads/ and !/include-old/) {\r
214 $lib = $File::Find::name;\r
215 }\r
216 }\r
217 };\r
218 \r
219 use File::Find;\r
220 foreach my $guess (@$locations) {\r
221 next unless -d $guess;\r
222 find (\&$wanted, $guess);\r
223 }\r
224 if (! $lib) {\r
225 print "Could not find @$candidates\n";\r
226 } else {\r
227 print "Found @$candidates as $lib\n\n";\r
228 }\r
229 return $lib;\r
230}\r
231\r
232# Extra lib for Java 1.2\r
233#\r
234# if we want KAFFE, check for it, otherwise search for Java\r
235\r
236sub find_libs {\r
237 my($libjava, $libawt, $libjvm);\r
238\r
239 if ($USE_KAFFE) {\r
240 $libjava = find_stuff(['libkaffevm.so'], \@KAFFE_LIB_GUESSES);\r
241 $libawt = find_stuff(['libawt.so'], \@KAFFE_LIB_GUESSES);\r
242 } else {\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
250 }\r
251 }\r
252 return($libjava, $libawt);\r
253}\r
254\r
255# We need to find jni.h and jni_md.h\r
256#\r
257\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
260\r
261sub find_includes {\r
262\r
263 my @CANDIDATES = qw(jni.h jni_md.h);\r
264 my @includes;\r
265\r
266 sub find_inc {\r
267 foreach my $name (@CANDIDATES) {\r
268 if (/$name$/) {\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
274 } \r
275 }\r
276 }\r
277 }\r
278 \r
279 use File::Find;\r
280 foreach my $guess (@KAFFE_INCLUDE_GUESSES) {\r
281 next unless -d $guess;\r
282 find (\&find_inc, $guess);\r
283 }\r
284 # If we have found includes, then we are using Kaffe.\r
285 if (@includes > 0) {\r
286 $USE_KAFFE = 1;\r
287 } else {\r
288 foreach my $guess (@JAVA_HOME_GUESSES) {\r
289 next unless -d $guess;\r
290 find (\&find_inc, $guess);\r
291 }\r
292 }\r
293 die "Could not find Java includes!" unless (@includes);\r
294\r
295 return @includes;\r
296}\r
297\r