From eaed7b4233731c36f320d40d5171c9db4a05a423 Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Sat, 23 Dec 2006 00:12:13 +0000 Subject: [PATCH] Improved Java detetction in Makefile, including case where directory has a space, e.g. "Progam Files". git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@209 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/Makefile | 112 +++++++++++++++++------------------ prism/src/dv/Makefile | 3 +- prism/src/hybrid/Makefile | 3 +- prism/src/jdd/Makefile | 3 +- prism/src/mtbdd/Makefile | 3 +- prism/src/odd/Makefile | 3 +- prism/src/prism/Makefile | 3 +- prism/src/simulator/Makefile | 3 +- prism/src/sparse/Makefile | 3 +- 9 files changed, 72 insertions(+), 64 deletions(-) diff --git a/prism/Makefile b/prism/Makefile index 96732cb5..71c03843 100644 --- a/prism/Makefile +++ b/prism/Makefile @@ -60,13 +60,38 @@ endif # either set the variable yourself by uncommenting and/or modifying one of the lines below # or pass a value to make directly, e.g.: make JAVA_DIR=/usr/java -# Autodetection -JAVA_JAVAC = $(shell JAVA_JAVAC=`which javac`; JAVA_JAVAC_DIR=`dirname $$JAVA_JAVAC`; cd $$JAVA_JAVAC_DIR; while [ -h ./javac ]; do JAVA_JAVAC=`/bin/ls -l ./javac | sed 's/.* -> //'`; JAVA_JAVAC_DIR=`dirname $$JAVA_JAVAC`; cd $$JAVA_JAVAC_DIR; JAVA_JAVAC_DIR=`pwd`; done; echo $$JAVA_JAVAC_DIR/javac) -#JAVA_JAVAC = $(shell JAVA_JAVAC=`which javac`; while [ -h $$JAVA_JAVAC ]; do JAVA_JAVAC=`/bin/ls -l $$JAVA_JAVAC | sed 's/.* -> //'`; done; echo $$JAVA_JAVAC) -ifneq (darwin,$(OSTYPE)) - JAVA_DIR = $(shell dirname $(JAVA_JAVAC) | sed 's/\/bin//') +# The detection of javac below can handle cases: +# - where javac is a symbolic link +# - where there is actually a chain of symbolic links +# - where there are relative symbolic links +# - where there are directory names including spaces +# Note: The code would be simpler if we could rely on +# the existence of "readlink -f" but we can't. + +# Find javac +DETECT_JAVAC = $(shell \ + (DETECT_JAVAC=`which javac`; \ + if [ -f "$$DETECT_JAVAC" ]; then \ + DETECT_JAVAC_DIR=`dirname "$$DETECT_JAVAC"`; \ + cd "$$DETECT_JAVAC_DIR"; \ + while [ -h ./javac ]; do \ + DETECT_JAVAC=`readlink ./javac`; \ + DETECT_JAVAC_DIR=`dirname "$$DETECT_JAVAC"`; \ + cd "$$DETECT_JAVAC_DIR"; \ + DETECT_JAVAC_DIR=`pwd`; \ + done; \ + echo $$DETECT_JAVAC_DIR/javac; \ + fi) 2> /dev/null) + +# Find directory containing javac +ifeq ("$(DETECT_JAVAC)","") + JAVA_DIR = else - JAVA_DIR = $(shell dirname $(JAVA_JAVAC) | sed 's/\/Commands//') + ifneq (darwin,$(OSTYPE)) + JAVA_DIR = $(shell dirname "$(DETECT_JAVAC)" | sed 's/\/bin//') + else + JAVA_DIR = $(shell dirname "$(DETECT_JAVAC)" | sed 's/\/Commands//') + endif endif #JAVA_DIR = /usr/java @@ -99,6 +124,7 @@ OPTIMISE = -O3 # Flags to generate shared libraries # Executable/library naming conventions # Suffix for binary distribution directory +# Place to look for (JNI) headers # (requires GNU make for conditional evaluation) # Linux @@ -112,6 +138,7 @@ ifeq ($(OSTYPE),linux) LIBPREFIX = lib LIBSUFFIX = .so BINDISTSUFFIX = linux + OSTYPE_INCLUDE = include endif # Solaris ifeq ($(OSTYPE),solaris) @@ -123,6 +150,7 @@ ifeq ($(OSTYPE),solaris) LIBPREFIX = lib LIBSUFFIX = .so BINDISTSUFFIX = solaris + OSTYPE_INCLUDE = include endif # Cygwin ifeq ($(OSTYPE),cygwin) @@ -135,6 +163,7 @@ ifeq ($(OSTYPE),cygwin) LIBPREFIX = LIBSUFFIX = .dll BINDISTSUFFIX = win + OSTYPE_INCLUDE = include endif # Darwin ifeq ($(OSTYPE),darwin) @@ -146,6 +175,7 @@ ifeq ($(OSTYPE),darwin) LIBPREFIX = lib LIBSUFFIX = .dylib BINDISTSUFFIX = osx + OSTYPE_INCLUDE = Headers endif ############### @@ -164,27 +194,9 @@ LIB_DIR = lib INCLUDE_DIR = include # Now we locate the JNI header files jni.h and jni_md.h -# (this is the only reason we need JAVA_DIR). -# If this doesn't work for some reason, locate the two files -# and set the JAVA_INCLUDES directory manually - -# Choose name for include directories -ifneq (darwin,$(OSTYPE)) - OSTYPE_INCLUDE = include -else - OSTYPE_INCLUDE = Headers -endif -# Look in Java directory -JAVA_JNI_H = $(shell ls $(JAVA_DIR)/$(OSTYPE_INCLUDE)/jni.h 2>/dev/null) -JAVA_JNI_MD_H = $(shell ls $(JAVA_DIR)/$(OSTYPE_INCLUDE)/jni_md.h 2>/dev/null) -# Then try subdirectories (for OS-specific files) -ifeq (,$(JAVA_JNI_MD_H)) - JAVA_JNI_MD_H = $(shell ls $(JAVA_DIR)/$(OSTYPE_INCLUDE)/*/jni_md.h 2>/dev/null) -endif -# Now strip off filename to leave directories -JAVA_JNI_H_DIR = $(shell echo $(JAVA_JNI_H) | sed 's/\/jni.h//') -JAVA_JNI_MD_H_DIR = $(shell echo $(JAVA_JNI_MD_H) | sed 's/\/jni_md.h//') -# Store result in JAVA_INCLUDES variable +# (in fact this is the only reason we need JAVA_DIR) +JAVA_JNI_H_DIR = $(shell ls "$(JAVA_DIR)"/$(OSTYPE_INCLUDE)/jni.h | sed 's/\/jni.h//' 2>/dev/null) +JAVA_JNI_MD_H_DIR = $(shell ls "$(JAVA_DIR)"/$(OSTYPE_INCLUDE)/jni_md.h "$(JAVA_DIR)"/$(OSTYPE_INCLUDE)/*/jni_md.h | sed 's/\/jni_md.h//' 2>/dev/null) JAVA_INCLUDES = -I $(JAVA_JNI_H_DIR) -I $(JAVA_JNI_MD_H_DIR) ######################### @@ -261,6 +273,8 @@ make_dirs: LIB_DIR="$(LIB_DIR)" \ INCLUDE_DIR="$(INCLUDE_DIR)" \ JAVA_INCLUDES="$(JAVA_INCLUDES)" \ + JAVA_JNI_H_DIR="$(JAVA_JNI_H_DIR)" \ + JAVA_JNI_MD_H_DIR="$(JAVA_JNI_MD_H_DIR)" \ C="$(C)" \ CPP="$(CPP)" \ LD="$(LD)" \ @@ -374,7 +388,7 @@ clean: checks done; \ find $(CLASSES_DIR) -name '*.class' -exec rm {} \; ; \ rm -f lib/*jnilib; \ - rm $(BIN_PRISM) $(BIN_XPRISM) $(BIN_PRISM_BAT) $(BIN_XPRISM_BAT) ) + rm -f $(BIN_PRISM) $(BIN_XPRISM) $(BIN_PRISM_BAT) $(BIN_XPRISM_BAT) ) celan: clean @@ -428,44 +442,30 @@ checks: if [ "$(JAVA_DIR)" = "" ]; then \ echo "PRISM was unable to find the directory which contains"; \ echo "your Java distribution. Please specify this manually to"; \ - echo "make as in the following example:"; \ + echo "make, as in these examples:"; \ echo; \ echo " make JAVA_DIR=/usr/java/j2sdk1.4.2"; \ + echo " make JAVA_DIR=\"/cygdrive/c/Program Files/Java/jdk1.4.2\""; \ echo; \ - echo "If you do not know where your Java distribution is, try typing:"; \ - echo; \ - echo " which javac"; \ - echo; \ - echo "If the output is of the form 'javac: Command not found' or"; \ - echo "'which: no javac in...' then either you do not have Java"; \ - echo "installed or your path is not set up to include Java."; \ - echo "If the output is something like:"; \ - echo; \ - echo " /bham/java/packages/j2sdk1.4.2/bin/javac"; \ + echo "See the PRISM manual for further information."; \ echo; \ - echo "then the directory is /usr/java/j2sdk1.4.2"; \ - echo "(i.e. with the '/bin/javac' removed)."; \ - echo "One situation where this doesn't work is when javac"; \ - echo "has been set up as a symbolic link. In this case, type:"; \ - echo; \ - echo " ls -l `which javac`"; \ - echo; \ - echo "which will tell you where javac actually is (the part displayed"; \ - echo "after the -> arrow. You can then deduce what the directory is as above."; \ + echo "Alternatively, if you wish, you can set the environment"; \ + echo "variable yourself (using setenv or export) or you"; \ + echo "can edit the value of JAVA_DIR directly in the Makefile."; \ exit 1; \ fi; \ - if [ ! -d $(JAVA_DIR) ]; then \ - echo "Java directory $(JAVA_DIR) does not exist."; \ + if [ ! -d "$(JAVA_DIR)" ]; then \ + echo "Java directory \"$(JAVA_DIR)\" does not exist."; \ exit 1; \ fi; \ - if [ ! -f $(JAVA_JNI_H_DIR)/jni.h ]; then \ - echo "Failed to locate the JNI header jni.h."; \ - echo "Are you sure Java is installed?"; \ + if [ ! -f "$(JAVA_DIR)"/$(OSTYPE_INCLUDE)/jni.h ]; then \ + echo "Could not locate JNI header jni.h in \"$(JAVA_DIR)/$(OSTYPE_INCLUDE)\"."; \ + echo "You may need to set JAVA_DIR by hand. See the PRISM manual for details."; \ exit 1; \ fi; \ - if [ ! -f $(JAVA_JNI_MD_H_DIR)/jni_md.h ]; then \ - echo "Failed to locate the JNI header jni_md.h"; \ - echo "Are you sure Java is installed?"; \ + if [ ! -f "$(JAVA_DIR)"/$(OSTYPE_INCLUDE)/jni_md.h -a ! -f "$(JAVA_DIR)"/$(OSTYPE_INCLUDE)/*/jni_md.h ]; then \ + echo "Could not locate JNI header jni_md.h in \"$(JAVA_DIR)/$(OSTYPE_INCLUDE)\" or ...."; \ + echo "You may need to set JAVA_DIR by hand. See the PRISM manual for details."; \ exit 1; \ fi; \ echo "OSTYPE: $(OSTYPE)"; \ diff --git a/prism/src/dv/Makefile b/prism/src/dv/Makefile index 8f1785b3..781524e3 100644 --- a/prism/src/dv/Makefile +++ b/prism/src/dv/Makefile @@ -14,7 +14,8 @@ PRISM_DIR_REL = ../.. INCLUDES = \ -I$(PRISM_DIR_REL)/$(CUDD_DIR)/include \ -$(JAVA_INCLUDES) \ +-I"$(JAVA_JNI_H_DIR)" \ +-I"$(JAVA_JNI_MD_H_DIR)" \ -I$(PRISM_DIR_REL)/$(INCLUDE_DIR) LIBRARIES = \ diff --git a/prism/src/hybrid/Makefile b/prism/src/hybrid/Makefile index 8821c321..671acd40 100644 --- a/prism/src/hybrid/Makefile +++ b/prism/src/hybrid/Makefile @@ -14,7 +14,8 @@ PRISM_DIR_REL = ../.. INCLUDES = \ -I$(PRISM_DIR_REL)/$(CUDD_DIR)/include \ -$(JAVA_INCLUDES) \ +-I"$(JAVA_JNI_H_DIR)" \ +-I"$(JAVA_JNI_MD_H_DIR)" \ -I$(PRISM_DIR_REL)/$(INCLUDE_DIR) LIBRARIES = \ diff --git a/prism/src/jdd/Makefile b/prism/src/jdd/Makefile index ed28f969..ad1d474e 100644 --- a/prism/src/jdd/Makefile +++ b/prism/src/jdd/Makefile @@ -14,7 +14,8 @@ PRISM_DIR_REL = ../.. INCLUDES = \ -I$(PRISM_DIR_REL)/$(CUDD_DIR)/include \ -$(JAVA_INCLUDES) \ +-I"$(JAVA_JNI_H_DIR)" \ +-I"$(JAVA_JNI_MD_H_DIR)" \ -I$(PRISM_DIR_REL)/$(INCLUDE_DIR) LIBRARIES = \ diff --git a/prism/src/mtbdd/Makefile b/prism/src/mtbdd/Makefile index 10c4c34a..60c11f17 100644 --- a/prism/src/mtbdd/Makefile +++ b/prism/src/mtbdd/Makefile @@ -14,7 +14,8 @@ PRISM_DIR_REL = ../.. INCLUDES = \ -I$(PRISM_DIR_REL)/$(CUDD_DIR)/include \ -$(JAVA_INCLUDES) \ +-I"$(JAVA_JNI_H_DIR)" \ +-I"$(JAVA_JNI_MD_H_DIR)" \ -I$(PRISM_DIR_REL)/$(INCLUDE_DIR) LIBRARIES = \ diff --git a/prism/src/odd/Makefile b/prism/src/odd/Makefile index 278a726c..85ef17f2 100644 --- a/prism/src/odd/Makefile +++ b/prism/src/odd/Makefile @@ -14,7 +14,8 @@ PRISM_DIR_REL = ../.. INCLUDES = \ -I$(PRISM_DIR_REL)/$(CUDD_DIR)/include \ -$(JAVA_INCLUDES) \ +-I"$(JAVA_JNI_H_DIR)" \ +-I"$(JAVA_JNI_MD_H_DIR)" \ -I$(PRISM_DIR_REL)/$(INCLUDE_DIR) LIBRARIES = \ diff --git a/prism/src/prism/Makefile b/prism/src/prism/Makefile index 42a0faed..8bff30de 100644 --- a/prism/src/prism/Makefile +++ b/prism/src/prism/Makefile @@ -13,7 +13,8 @@ THIS_DIR = prism PRISM_DIR_REL = ../.. INCLUDES = \ -$(JAVA_INCLUDES) \ +-I"$(JAVA_JNI_H_DIR)" \ +-I"$(JAVA_JNI_MD_H_DIR)" \ -I$(PRISM_DIR_REL)/$(INCLUDE_DIR) LIBRARIES = \ diff --git a/prism/src/simulator/Makefile b/prism/src/simulator/Makefile index 39550373..c4f2eb7d 100644 --- a/prism/src/simulator/Makefile +++ b/prism/src/simulator/Makefile @@ -14,7 +14,8 @@ PRISM_DIR_REL = ../.. INCLUDES = \ -I$(PRISM_DIR_REL)/$(CUDD_DIR)/include \ -$(JAVA_INCLUDES) \ +-I"$(JAVA_JNI_H_DIR)" \ +-I"$(JAVA_JNI_MD_H_DIR)" \ -I$(PRISM_DIR_REL)/$(INCLUDE_DIR) LIBRARIES = \ diff --git a/prism/src/sparse/Makefile b/prism/src/sparse/Makefile index 37c4e208..c59551eb 100644 --- a/prism/src/sparse/Makefile +++ b/prism/src/sparse/Makefile @@ -14,7 +14,8 @@ PRISM_DIR_REL = ../.. INCLUDES = \ -I$(PRISM_DIR_REL)/$(CUDD_DIR)/include \ -$(JAVA_INCLUDES) \ +-I"$(JAVA_JNI_H_DIR)" \ +-I"$(JAVA_JNI_MD_H_DIR)" \ -I$(PRISM_DIR_REL)/$(INCLUDE_DIR) LIBRARIES = \