# Copyright (c) 1997-2006
# Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
# http://www.math.tu-berlin.de/polymake, mailto:polymake@math.tu-berlin.de
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version: http://www.gnu.org/licenses/gpl.txt.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#-----------------------------------------------------------------------------
# $Project: polymake $$Id: configure_java.pl 7556 2007-01-12 17:36:36Z gawrilow $
use strict 'vars', 'subs';
package Configure::Java;
use vars qw( @noexport @unconfigured @jars );
BEGIN {
@noexport=qw( PackageBase JAVAC JAVA JAR JavaBuildDir AutoconfFile );
}
use vars map { "\$$_" } @noexport;
my @rules=grep { -f "modules/common/rules/$_" } qw( utilities javaview_configure jreality_configure );
my $mod_common;
sub query_javaview {
while (print("Where is JavaView installed? ") &&
main::answer_path($JavaView::Viewer::install_top) &&
defined($JavaView::Viewer::install_top)) {
# for those who don't read the prompt carefully;
$JavaView::Viewer::install_top =~ s{/bin(?:/javaview)?$}{};
$JavaView::Viewer::install_top =~ s{/$}{};
if (-d $JavaView::Viewer::install_top and
-e "$JavaView::Viewer::install_top/bin/javaview") {
# remove 'config' flag
$mod_common->custom->set('$JavaView::Viewer::install_top');
$mod_common->repeat_configure('javaview_configure')
and return 1;
print <<'.';
The configuration script has failed: $@.
If this was caused by the wrong installation path, please specify a correct one.
Otherwise, type "none" to skip the JavaView configuration.
.
} else {
print "\"$JavaView::Viewer::install_top\" does not look like JavaView installation directory\n";
}
}
}
sub find_javaview {
do {
if (!$mod_common->rulefiles->{javaview_configure}) {
print <<'.';
JavaView, the preferred visualization tool, could not be found along your PATH.
If it is installed somewhere else on your site, please give the top directory
at the next prompt.
If not, but you are going to download it from www.javaview.de right now, rerun
this configuration after you have installed it.
If you are not going to use JavaView, type "none" at the next prompt.
Should you revise your decision later, remember to run
'polymake --reconfigure' or 'polymake --reconfigure-rules javaview'
after JavaView installation.
.
} elsif (eval("v$JavaView::Viewer::version") ge v3.0.3) {
return 1;
} else {
print <<"."
JavaView installed under $JavaView::Viewer::install_top is of an old version $JavaView::Viewer::version,
while the interactive visualization requires at least the version 3.03.
If a new version is installed somewhere else on your site, please give the top directory
at the next prompt.
If not, but you are going to download it from www.javaview.de right now, rerun
this configuration after you have installed it.
If the static visualization is good enough for you, type "none" at the next prompt.
Should you revise your decision later, remember to run
'polymake --reconfigure' or 'polymake --reconfigure-rules javaview'
after JavaView upgrade.
.
}
}
while (query_javaview);
}
sub query_jogl {
print "Do you want to use Java OpenGL with jReality? ";
$JReality::Viewer::jogl = main::yes_not($JReality::Viewer::jogl);
while ($JReality::Viewer::jogl) {
print("Which directory jogl.jar resides in? ");
main::answer_path($JReality::Viewer::jogl_path);
if (!defined($JReality::Viewer::jogl_path)) {
$JReality::Viewer::jogl=0;
last;
}
if (-d $JReality::Viewer::jogl_path) {
# maybe the native libraries are in the same folder as the jar
$JReality::Viewer::jogl_native_path ||= $JReality::Viewer::jogl_path;
print "Which directory the native jogl libraries reside in? ";
main::answer_path($JReality::Viewer::jogl_native_path);
if (-d $JReality::Viewer::jogl_native_path) {
# remove 'config' flags
$mod_common->custom->set('$JReality::Viewer::jogl');
$mod_common->custom->set('$JReality::Viewer::jogl_path');
$mod_common->custom->set('$JReality::Viewer::jogl_native_path');
last;
}
}
print <<'.';
The directory you have entered does not exist.
Please specify a correct directory path or type "none"
to skip the jReality-jogl configuration.
.
}
}
sub query_jreality {
while (print("\nPlease specify the directory where the JAR files\nreside or \"none\" if JReality is not installed: ") &&
main::answer_path($JReality::Viewer::jar_path) &&
defined($JReality::Viewer::jar_path)) {
$JReality::Viewer::jar_path =~ s{/$}{};
if (-d $JReality::Viewer::jar_path) {
# jogl could be occasionally installed in the same directory
if (-f "$JReality::Viewer::jar_path/jogl.jar") {
$JReality::Viewer::jogl_path ||= $JReality::Viewer::jar_path;
if (-f "$JReality::Viewer::jogl_path/libjogl.$Config::Config{dlext}") {
$JReality::Viewer::jogl_native_path ||= $JReality::Viewer::jogl_path;
$JReality::Viewer::jogl=1;
}
}
query_jogl;
# remove 'config' flags
$mod_common->custom->set('$JReality::Viewer::jar_path');
$mod_common->repeat_configure('jreality_configure') and return 1;
print "The configuration script has failed again: $@.\n";
} else {
print <<'.';
The directory you have entered does not exist.
Please specify a correct path or type "none" to skip the jReality configuration.
.
}
}
}
sub find_jreality {
if ($mod_common->rulefiles->{jreality_configure}) {
if (!$JReality::Viewer::jogl) {
print("\njReality was found on your system but without openGL support.\n");
query_jogl;
}
return 1;
}
print "\njReality components could not be found.\n";
while (query_jreality) {
if ($mod_common->rulefiles->{jreality_configure}) {
return 1;
}
}
}
sub java_options {
if (!$main::DeveloperMode) {
print "\nAre you going to develop new Java modules for interactive visualization,\n".
"or do you need to recompile the shipped jar archives",
($main::multi && " on this platform"), "? ";
return 0 unless main::yes_not(0);
}
$JAVAC or ($JAVAC=$JAVA)=~s/java$/javac/;
$JAR or ($JAR=$JAVA)=~s/java$/jar/;
print "\nWhich Java compiler should be used? ";
main::answer($JAVAC);
print "\nWhich Java archiver should be used? ";
main::answer($JAR);
defined($JAVAC) && defined($JAR);
}
sub make_java_dir {
my $src="java/src/$PackageBase";
main::make_dir_path $src;
(my $back=$src) =~ s|[^/]+|..|g;
foreach my $dir (@_) {
my $rel_dir="$JavaBuildDir/$PackageBase/$dir";
main::make_dir $rel_dir;
if (-d "apps/$dir/java") {#FIXME correct paths
symlink "$back/apps/$dir/java", "$src/$dir";
} else {
symlink "$back/modules/$dir/java", "$src/$dir";
}
open M, ">$rel_dir/Makefile";
$rel_dir =~ s:[^/]+:..:g;
print M <<".";
ProjectTop := $rel_dir
include \$(ProjectTop)/support/java.make
.
close M;
}
}
#######################################################################################
#
# prepare for the pre-configuration the java-dependent rules
#
use lib "perl", "$main::BuildDir/perlx";
use Poly::Module;
BEGIN {
$Switches::reconfigure=1;
$AutoconfFile="configured.pl";
}
package Poly::Module;
use Poly::Customize $Configure::Java::AutoconfFile;
@lookup=(".");
$reconfigure_hint="";
#######################################################################################
package Configure::Java;
$mod_common=eval { new Poly::Module("common", @rules) };
if ($@) {
print "WARNING: error loading module common: $@",
"autoconfiguration of java components will be skipped\n";
return;
}
$JAVA=$Modules::common::java;
$main::changed=0;
if ($JAVA eq "java") {
$JAVA=main::find_via_path("java");
}
for (;;) {
if ($JAVA) {
my ($java_version)= `$JAVA -version 2>&1` =~ /version "([\d.]+)/s;
last if eval("v$java_version") ge v1.5;
undef $JAVA;
print <<"."
Java interpreter $JAVA found along your PATH tells its version is $java_version.
You need at least Java 5 (version 1.5.0) in order to use the polymake interface
to JavaView and jReality visualization software.
.
} else {
print <<".";
Java interpreter could not be found along your PATH.
.
}
print <<".";
If you have Java 5 runtime environment or newer installed somewhere on your site,
please specify the corresponding path now.
Alternatively you can type "none" here, then the JavaView and jReality interfaces
will be disabled until you repeat this configuration step.
.
print "Path to the java interpreter: ";
main::answer_path($JAVA);
if (!$JAVA) {
$main::changed=1;
last;
}
}
if ($main::changed) {
$Modules::common::java=$JAVA;
$mod_common->custom->set('$Modules::common::java');
}
return if !$JAVA;
my $javaview=find_javaview;
my $jreality=find_jreality;
if ($javaview) {
push @jars, "$JavaView::Viewer::install_top/jars/javaview.jar";
} else {
push @unconfigured, "if_JavaView";
}
if ($jreality) {
push @jars, map { "$JReality::Viewer::jar_path/$_" } @JReality::Viewer::jars;
} else {
push @unconfigured, "if_JReality";
}
if (($javaview || $jreality) && java_options) {
$JavaBuildDir="java_build";
$PackageBase="de/tuberlin/polymake";
main::make_dir_path "$JavaBuildDir/$PackageBase";
open M, ">$JavaBuildDir/Makefile";
print M <<'.';
# make all jar archives
.PHONY: all clean install
all clean install: ; @$(MAKE) -C .. --no-print-directory $@-java
.
close M;
my $last_limb=qr{^[^/]+/(.*)};
my @java_src_dirs=grep { -d "$_/java" } @main::apps, @main::modules;
make_java_dir map { /$last_limb/ } @java_src_dirs;
if ($javaview) {
my @javaview_src_dirs = grep { -d "$_/java/javaview" } @java_src_dirs;
make_java_dir map { /$last_limb/; "$1/javaview" } @javaview_src_dirs;
}
if ($jreality) {
my @jreality_src_dirs = grep { -d "$_/java/jreality" } @java_src_dirs;
make_java_dir map { /$last_limb/; "$1/jreality" } @jreality_src_dirs;
}
foreach my $var (@noexport) {
print main::CONF "$var=$$var\n" if defined($$var);
}
print main::CONF <<".";
JavaUnconfigured := @unconfigured
AddJars := @jars
.
}
syntax highlighted by Code2HTML, v. 0.9.1