From b309c87d9f6887de9b67d824a5333fded90fe4af Mon Sep 17 00:00:00 2001 From: Julien Fischer Date: Fri, 4 Sep 2015 13:55:09 +1000 Subject: [PATCH] Make it possible to run the installed Java version of the compiler. Make it possible to run the installed Java version of the compiler by installing versions of the wrapper scripts for 'mercury_compile' and 'mfilterjavac' that have the CLASSPATH set to point to the installed versions of the standard library Java archives. The wrapper script generated in the compiler directory is not suitable for this because as generated it sets the CLASSPATH relative to the compiler directory, not the installation directory. Modifying that file is not a good idea since that will mean that then the compiler cannot be executed in situ. Instead we provide a handwritten version of the wrapper script in the scripts directory that is installed in place of the generated one. Ditto for mfilterjavac. While this does create a small maintenance problem, I think that any other approach, for example, modifying the generation of wrapper scripts to account for this, is going to be a larger maintenance problem. TODO: - handle batch file launchers for Windows. - handle other executables in the Mercury system (although most of these are not so important in this context). compiler/Mmakefile: mfilterjavac/Mmakefile: Do not install generated wrapper scripts from these directories in the Java grade. scripts/mercury_compile.sh-java: scripts/mfilterjavac.sh-java: Java wrappers scripts for the installed versions of the compiler and mfilterjavac. scripts/Mmakefile: In the Java grade install the wrapper scripts for the compiler and mfilterjavac from this directory. --- compiler/Mmakefile | 19 +++++++++++++++---- mfilterjavac/Mmakefile | 16 ++++++++++------ scripts/Mmakefile | 9 +++++++++ scripts/mercury_compile.sh-java | 16 ++++++++++++++++ scripts/mfilterjavac.sh-java | 16 ++++++++++++++++ 5 files changed, 66 insertions(+), 10 deletions(-) create mode 100755 scripts/mercury_compile.sh-java create mode 100755 scripts/mfilterjavac.sh-java diff --git a/compiler/Mmakefile b/compiler/Mmakefile index 9b00027fd..842f294bd 100644 --- a/compiler/Mmakefile +++ b/compiler/Mmakefile @@ -261,11 +261,22 @@ install_mercury: install_compiler install_dirs: -[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR) -.PHONY: install_compiler -install_compiler: mercury_compile install_dirs - cp `vpath_find mercury_compile$(EXT_FOR_EXE)` $(INSTALL_MERC_BIN_DIR) +# If the compiler is built in the Java grade then we need to install Java +# archive containing its class files (currently called top_level.jar), but +# *not* the generated wrapper script 'mercury_compile' from this directory. +# The latter will set the CLASSPATH variable relative to this directory and +# won't work when moved to the installation directory. Instead we use the +# version of the wrapper script from the scripts directory and leave the +# one here alone. +# ifeq ($(findstring java,$(GRADE)),java) - cp `vpath_find top_level.jar` $(INSTALL_MERC_BIN_DIR) +INSTALL_PROGRAM=top_level.jar +else +INSTALL_PROGRAM=mercury_compile$(EXT_FOR_EXE) endif +.PHONY: install_compiler +install_compiler: mercury_compile install_dirs + cp `vpath_find $(INSTALL_PROGRAM)` $(INSTALL_MERC_BIN_DIR) + #-----------------------------------------------------------------------------# diff --git a/mfilterjavac/Mmakefile b/mfilterjavac/Mmakefile index 01122afac..fc1d2554f 100644 --- a/mfilterjavac/Mmakefile +++ b/mfilterjavac/Mmakefile @@ -135,13 +135,17 @@ realclean_local: # Installation target -.PHONY: install -install: mfilterjavac - -[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR) - cp `vpath_find mfilterjavac$(EXT_FOR_EXE)` \ - $(INSTALL_MERC_BIN_DIR)/mfilterjavac$(EXT_FOR_EXE) +# See the comment above the 'install_compiler' target in compiler/Mmakefile +# for the reasons why we handle the java grade specially here. +# ifeq ($(findstring java,$(GRADE)),java) - cp `vpath_find mfilterjavac.jar` $(INSTALL_MERC_BIN_DIR) +INSTALL_PROGRAM=mfilterjavac.jar +else +INSTALL_PROGRAM=mfilterjavac$(EXT_FOR_EXE) endif +install: mfilterjavac + -[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR) + cp `vpath_find $(INSTALL_PROGRAM)` $(INSTALL_MERC_BIN_DIR)/$(INSTALL_PROGRAM) + #-----------------------------------------------------------------------------# diff --git a/scripts/Mmakefile b/scripts/Mmakefile index bbf2813c3..fa60cf9d4 100644 --- a/scripts/Mmakefile +++ b/scripts/Mmakefile @@ -58,6 +58,10 @@ DEBUGGER_SCRIPTS = $(CONF_DEBUG_SCRIPTS) \ EMACS_SCRIPTS = gud.el +JAVA_WRAPPER_SCRIPTS = \ + mercury_compile \ + mfilterjavac + #-----------------------------------------------------------------------------# # .SUFFIXES: .in @@ -137,6 +141,11 @@ install_scripts: $(SCRIPTS) install_dirs done cp *.in *.sh-subr $(SCRIPTS) $(INSTALL_RECONF_DIR)/scripts -rm -f $(INSTALL_BINDIR)/mmake.old +ifeq ($(findstring java,$(GRADE)),java) + for file in $(JAVA_WRAPPER_SCRIPTS); do \ + cp $$file.sh-java $(INSTALL_MERC_BIN_DIR)/$$file ;\ + done +endif .PHONY: install_config install_config: Mercury.config install_dirs diff --git a/scripts/mercury_compile.sh-java b/scripts/mercury_compile.sh-java new file mode 100755 index 000000000..d5e27fca1 --- /dev/null +++ b/scripts/mercury_compile.sh-java @@ -0,0 +1,16 @@ +#!/bin/sh + +# This script invokes the _installed_ version of the Mercury compiler when it +# is built in the Java grade. + +DIR=${0%/*} +DIR=$( cd "${DIR}" && pwd -P ) +case $WINDIR in + '') SEP=':' ;; + *) SEP=';' ;; +esac +JARDIR="$DIR/../lib/mercury/lib/java" +CLASSPATH="$DIR/top_level.jar"${SEP}$CLASSPATH${SEP}$JARDIR/mer_rt.jar${SEP}$JARDIR/mer_std.jar${SEP}$JARDIR/mer_browser.jar${SEP}$JARDIR/mer_mdbcomp.jar +export CLASSPATH +JAVA=${JAVA:-java} +exec "$JAVA" jmercury.top_level "$@" diff --git a/scripts/mfilterjavac.sh-java b/scripts/mfilterjavac.sh-java new file mode 100755 index 000000000..cead4ffa7 --- /dev/null +++ b/scripts/mfilterjavac.sh-java @@ -0,0 +1,16 @@ +#!/bin/sh + +# This script invokes the _installed_ version of the mfilterjavac when it +# is built in the Java grade. + +DIR=${0%/*} +DIR=$( cd "${DIR}" && pwd -P ) +case $WINDIR in + '') SEP=':' ;; + *) SEP=';' ;; +esac +JARDIR="$DIR/../lib/mercury/lib/java" +CLASSPATH="$DIR/mfilterjavac.jar"${SEP}$CLASSPATH${SEP}$JARDIR/mer_rt.jar${SEP}$JARDIR/mer_std.jar${SEP}$JARDIR/mer_browser.jar${SEP}$JARDIR/mer_mdbcomp.jar +export CLASSPATH +JAVA=${JAVA:-java} +exec "$JAVA" jmercury.mfilterjavac "$@"