diff --git a/README.Java b/README.Java index 3e971f019..a0d466cfc 100644 --- a/README.Java +++ b/README.Java @@ -37,22 +37,9 @@ The Mercury compiler currently supports the grade `java' to target Java bytecode. The java grade is enabled by using any of the options `--grade java', `--target java', or just `--java'. -Support for building and installation of this grade -is still somewhat rudimentary. - To run a Mercury program using the java grade, you need to build the Mercury library and runtime in the java grade, using the Mercury source distribution. -You will also need to set the environment variable CLASSPATH to include the -mercury standard and runtime libraries for java, as well as the current -directory. You should use a command of the form: - - CLASSPATH=/mer_std.jar:/mer_std.runtime.jar:. - export CLASSPATH - -where is the location of the installed jar files, which will probably -be /usr/local/mercury/lib/mercury/lib/java or something similar. - You can now build programs such as hello.m or calculator.m in the samples directory. diff --git a/compiler/modules.m b/compiler/modules.m index 6a8bc0099..980a973f5 100644 --- a/compiler/modules.m +++ b/compiler/modules.m @@ -7196,12 +7196,8 @@ create_java_shell_script(MainModuleName, Succeeded) --> % XXX PathSeparator should be ";" on Windows { PathSeparator = ":" }, - % XXX The correct classpath needs to be set somewhere. - % It should take the form: - % DirName:/mer_std.jar:/mer_std.runtime.jar:. - % Currently this variable is empty, which causes problems, so - % we prepend the .class files' directory and the current CLASSPATH. globals__io_lookup_accumulating_option(java_classpath, Java_Incl_Dirs0), + % We prepend the .class files' directory and the current CLASSPATH. { Java_Incl_Dirs = [DirName, "$CLASSPATH" | Java_Incl_Dirs0] }, { ClassPath = string.join_list(PathSeparator, Java_Incl_Dirs) }, diff --git a/library/Mmakefile b/library/Mmakefile index dc89bf5ee..86d7bd40a 100644 --- a/library/Mmakefile +++ b/library/Mmakefile @@ -246,7 +246,7 @@ java_symlinks: # ensure that the path names are correct within the jar files. # We also compile NATIVE_SO here and copy it into the library directory. -JARS = $(STD_LIB_NAME).jar $(STD_LIB_NAME).runtime.jar +JARS = $(STD_LIB_NAME).jar $(RT_LIB_NAME).jar # We ignore the exit status of the last two commands because NATIVE_SO is not # an essential part of the Mercury standard library for the Java @@ -255,8 +255,7 @@ JARS = $(STD_LIB_NAME).jar $(STD_LIB_NAME).runtime.jar .PHONY: jars jars: classes $(JAR) $(JAR_CREATE_FLAGS) $(STD_LIB_NAME).jar mercury/*.class - $(JAR) $(JAR_CREATE_FLAGS) $(STD_LIB_NAME).runtime.jar \ - mercury/runtime/*.class + $(JAR) $(JAR_CREATE_FLAGS) $(RT_LIB_NAME).jar mercury/runtime/*.class -+cd mercury/runtime && mmake $(NATIVE_SO) -cp mercury/runtime/$(NATIVE_SO) . diff --git a/scripts/Mercury.config.bootstrap.in b/scripts/Mercury.config.bootstrap.in index fb41b0518..3cc2178a6 100644 --- a/scripts/Mercury.config.bootstrap.in +++ b/scripts/Mercury.config.bootstrap.in @@ -30,6 +30,14 @@ MERCURY_JAVA_INTERPRETER=@JAVA_INTERPRETER@ # be used by the substitution for SHARED_LIBS. MATH_LIB=$(MERCURY_MATH_LIB) +# This needed for Java classpath. +INSTALL_JAVA_LIBRARY_DIR=$(MERCURY_STDLIB_DIR)/lib/java + +# If you change these, you will also need to change the files indicated in +# scripts/c2init.in. +RT_LIB_NAME=mer_rt +STD_LIB_NAME=mer_std + DEFAULT_MERCURY_LINKAGE=@DEFAULT_LINKAGE@ # The default optimization level should be after @@ -52,6 +60,8 @@ DEFAULT_MCFLAGS=\ --cflags-for-gotos "@CFLAGS_FOR_GOTOS@" \ --cflags-for-pic "@CFLAGS_FOR_PIC@" \ --c-flag-to-name-object-file "@OBJFILE_OPT@" \ + --java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(RT_LIB_NAME).jar" \ + --java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(STD_LIB_NAME).jar" \ --object-file-extension ".@OBJ_SUFFIX@" \ --pic-object-file-extension ".@EXT_FOR_PIC_OBJECTS@" \ --link-with-pic-object-file-extension ".@EXT_FOR_LINK_WITH_PIC_OBJECTS@" \ diff --git a/scripts/Mercury.config.in b/scripts/Mercury.config.in index e62844442..219279775 100644 --- a/scripts/Mercury.config.in +++ b/scripts/Mercury.config.in @@ -29,6 +29,14 @@ MERCURY_JAVA_INTERPRETER=@JAVA_INTERPRETER@ # be used by the substitution for SHARED_LIBS. MATH_LIB=$(MERCURY_MATH_LIB) +# This needed for Java classpath. +INSTALL_JAVA_LIBRARY_DIR=$(MERCURY_STDLIB_DIR)/lib/java + +# If you change these, you will also need to change the files indicated in +# scripts/c2init.in. +RT_LIB_NAME=mer_rt +STD_LIB_NAME=mer_std + DEFAULT_MERCURY_LINKAGE=@DEFAULT_LINKAGE@ # The default optimization level should be after @@ -49,6 +57,8 @@ DEFAULT_MCFLAGS=\ --cflags-for-gotos "@CFLAGS_FOR_GOTOS@" \ --cflags-for-pic "@CFLAGS_FOR_PIC@" \ --c-flag-to-name-object-file "@OBJFILE_OPT@" \ + --java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(RT_LIB_NAME).jar" \ + --java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(STD_LIB_NAME).jar" \ --object-file-extension ".@OBJ_SUFFIX@" \ --pic-object-file-extension ".@EXT_FOR_PIC_OBJECTS@" \ --link-with-pic-object-file-extension ".@EXT_FOR_LINK_WITH_PIC_OBJECTS@" \ diff --git a/scripts/c2init.in b/scripts/c2init.in index 56bb0c764..f436b9ede 100755 --- a/scripts/c2init.in +++ b/scripts/c2init.in @@ -1,7 +1,7 @@ #! /bin/sh # @configure_input@ #---------------------------------------------------------------------------# -# Copyright (C) 1995-2003 The University of Melbourne. +# Copyright (C) 1995-2004 The University of Melbourne. # This file may only be copied under the terms of the GNU General # Public License - see the file COPYING in the Mercury distribution. #---------------------------------------------------------------------------# @@ -39,6 +39,8 @@ DEFAULT_GRADE=${MERCURY_DEFAULT_GRADE=@DEFAULT_GRADE@} # compiler/compile_target_code.m # scripts/c2init.in # scripts/ml.in +# scripts/Mercury.config.in +# scripts/Mercury.config.bootstrap.in # tools/bootcheck, # tools/binary # tools/binary_step