989b412000-03-06Marcus Comstedt 
fc40392008-08-15Martin Stjernholm protected int check_jre_dir(string dir)
989b412000-03-06Marcus Comstedt { if(!dir || dir=="" || dir[0]!='/') return 0; if(!file_stat(dir+"/lib/rt.jar")) return 0; if(!file_stat(dir+"/lib/flavormap.properties")) return 0;
edfe852001-01-24Marcus Comstedt  string v = Process.popen(dir+"/bin/java -version 2>&1"); if(2 <= sscanf(v, "java version \"%d.%d.%d", int maj, int min, int bld)) { if(maj < 1) return 0; if(maj > 1 || min > 2) return 1; if(min < 2) return 0; return bld >= 2; } else return 1;
989b412000-03-06Marcus Comstedt }
fc40392008-08-15Martin Stjernholm protected string findjre()
989b412000-03-06Marcus Comstedt {
edfe852001-01-24Marcus Comstedt  string dir = combine_path(combine_path(getcwd(), __FILE__), "../../../java/jre"); if(check_jre_dir(dir)) return dir; dir =
185d652000-04-05Henrik Grubbström (Grubba)  (Process.popen("java -verbose 2>&1 | sed -n -e 's/^[^/]*//' -e "
be558a2001-04-10Henrik Grubbström (Grubba)  "'s:/lib/rt\\.jar.*$::' -e p -e q")||"")-"\n";
ab4f2c2003-12-16Jonas Wallden  // Mac OS X uses a non-standard directory if (has_value(dir, "JavaVM.framework")) return "/System/Library/Frameworks/JavaVM.framework/Versions/" "CurrentJDK/Home/";
989b412000-03-06Marcus Comstedt  if(check_jre_dir(dir)) return dir;
df12f42001-01-17Marcus Comstedt  foreach(`+(@Array.map(({"/usr/local", "/usr", "/usr/java"}),
989b412000-03-06Marcus Comstedt  lambda(string s) { return Array.map(Array.map(({"jre*","jdk*","java*"}), glob,
e8f6ba2000-11-13Marcus Comstedt  reverse(sort(get_dir(s)|| ({""}))))* ({}),
989b412000-03-06Marcus Comstedt  lambda(string sb) { return s+"/"+sb; }); })), string d) { if(d && d!="") if(check_jre_dir(d+"/jre")) return d+"/jre"; else if(check_jre_dir(d)) return d; } return 0; } void run(object env) { string jrehome, arch, threads_type="native_threads";
9d7abc2000-08-31Fredrik Noring  write(" Checking for Java 2 (TM)...");
989b412000-03-06Marcus Comstedt  if(!(jrehome=getenv("JREHOME"))) jrehome=findjre(); if(!jrehome) jrehome = env->get("JREHOME"); if(!jrehome) {
f47af02000-03-30Leif Stensson  write(" not found\n");
989b412000-03-06Marcus Comstedt  return; }
b973a02000-08-31Fredrik Noring  write(" JREHOME="+jrehome+"\n");
989b412000-03-06Marcus Comstedt  env->set("JREHOME", jrehome);
0571ae2002-10-31Marcus Wellhardh  array archs = ({ (Process.popen("(/usr/bin/uname -p||uname -p) 2>/dev/null | sed -e 's/^i[4-9]86/i386/'")||"")-"\n", (Process.popen("(/usr/bin/uname -m||uname -m) 2>/dev/null | sed -e 's/^i[4-9]86/i386/'")||"")-"\n" }); foreach(Array.uniq(archs), string arch) { if(arch == "") arch = "_";
d98b272005-10-25Anders Johansson  else if(arch == "x86_64") arch = "amd64";
0571ae2002-10-31Marcus Wellhardh 
d98b272005-10-25Anders Johansson  foreach(({arch+"/"+threads_type, arch+"/classic", arch+"/server", arch}), string dir) {
0571ae2002-10-31Marcus Wellhardh  mixed s = file_stat(jrehome+"/lib/"+dir); if(s && s[1]==-2) env->append("LD_LIBRARY_PATH", jrehome+"/lib/"+dir); }
989b412000-03-06Marcus Comstedt  }
0571ae2002-10-31Marcus Wellhardh 
e8f6ba2000-11-13Marcus Comstedt  /* AIX */ if(file_stat(jrehome+"/bin/libjava.a")) env->append("LIBPATH", jrehome+"/bin/:"+jrehome+"/bin/classic/" );
051fe72002-05-06Jonas Wallden  // Only add _JAVA_OPTIONS if user hasn't got it already if (!env->get("_JAVA_OPTIONS"))
397f572003-02-05Jonas Wallden  env->set("_JAVA_OPTIONS", "\"-Xmx256m -Xrs\"");
989b412000-03-06Marcus Comstedt }