From 71dba047aff50b4c410df66a03e9b0db78330777 Mon Sep 17 00:00:00 2001 From: paltherr Date: Fri, 18 Jul 2003 06:48:57 +0000 Subject: - Removed .scala_wrapper - Added .scala_wrapper.tmpl - Modified Makefile to generate .scala_wrapper from .scala_wrapper.tmpl --- Makefile | 41 ++++- bin/.scala_wrapper | 152 ------------------ sources/bin/.scala_wrapper.tmpl | 338 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 376 insertions(+), 155 deletions(-) delete mode 100755 bin/.scala_wrapper create mode 100644 sources/bin/.scala_wrapper.tmpl diff --git a/Makefile b/Makefile index 85e770118b..38701140da 100644 --- a/Makefile +++ b/Makefile @@ -38,8 +38,9 @@ PROJECT_JAR_FILES += scalai # scala scripts wrapper SCRIPTS_PREFIX = $(PROJECT_ROOT)/bin -SCRIPTS_WRAPPER_NAME = .scala_wrapper +SCRIPTS_WRAPPER = $(SCRIPTS_PREFIX)/.scala_wrapper SCRIPTS_WRAPPER_LINKS += $(SCRIPTS_WRAPPER_ALIASES:%=$(SCRIPTS_PREFIX)/%) +SCRIPTS_WRAPPER_ALIASES += scala-info SCRIPTS_WRAPPER_ALIASES += socos SCRIPTS_WRAPPER_ALIASES += socos-debug SCRIPTS_WRAPPER_ALIASES += siris @@ -220,6 +221,7 @@ clean : fastclean distclean : clean $(RM) .latest-* $(RM) $(SCRIPTS_WRAPPER_LINKS) + $(RM) $(SCRIPTS_WRAPPER) $(RM) -r $(PROJECT_OUTPUTDIR) $(RM) $(PROJECT_JAR_ARCHIVE) $(RM) $(ROOT)/support/latex/*.class @@ -303,8 +305,41 @@ $(PROJECT_OUTPUTDIR) : $(LN) -s $(PROJECT_OUTPUTDIR_LINK) $(PROJECT_OUTPUTDIR),\ $(MKDIR) $(PROJECT_OUTPUTDIR)) -$(SCRIPTS_WRAPPER_LINKS): - $(LN) -s $(SCRIPTS_WRAPPER_NAME) $@; +$(SCRIPTS_WRAPPER) : MACRO_VERSION ?= "development version" +$(SCRIPTS_WRAPPER) : MACRO_RUNTIME_SOURCES ?= $(PROJECT_SOURCEDIR:$(PROJECT_ROOT)%=$$PREFIX%) +$(SCRIPTS_WRAPPER) : MACRO_RUNTIME_CLASSES ?= $(PROJECT_OUTPUTDIR:$(PROJECT_ROOT)%=$$PREFIX%) +$(SCRIPTS_WRAPPER) : MACRO_DTD2SCALA_CLASSES ?= $(PROJECT_OUTPUTDIR:$(PROJECT_ROOT)%=$$PREFIX%) +$(SCRIPTS_WRAPPER) : MACRO_BCEL_CLASSES ?= $(BCEL_JARFILE) +$(SCRIPTS_WRAPPER) : MACRO_FJBG_CLASSES ?= $(FJBG_JARFILE) +$(SCRIPTS_WRAPPER) : MACRO_MSIL_CLASSES ?= $(MSIL_JARFILE) +$(SCRIPTS_WRAPPER) : MACRO_XERCES_CLASSES ?= $(XERCES_JARFILE) +$(SCRIPTS_WRAPPER) : MACRO_JAVA_ARGS ?= -enableassertions +$(SCRIPTS_WRAPPER) : $(SCRIPTS_WRAPPER).tmpl $(PROJECT_ROOT)/Makefile + $(RM) $@ + @$(ECHO) "Generating file $@" + @$(SED) \ + -es@{#VERSION#}@'$(MACRO_VERSION)'@g \ + -es@{#RUNTIME_SOURCES#}@'$(MACRO_RUNTIME_SOURCES)'@g \ + -es@{#RUNTIME_CLASSES#}@'$(MACRO_RUNTIME_CLASSES)'@g \ + -es@{#DTD2SCALA_CLASSES#}@'$(MACRO_RUNTIME_CLASSES)'@g \ + -es@{#BCEL_CLASSES#}@'$(MACRO_BCEL_CLASSES)'@g \ + -es@{#FJBG_CLASSES#}@'$(MACRO_FJBG_CLASSES)'@g \ + -es@{#MSIL_CLASSES#}@'$(MACRO_MSIL_CLASSES)'@g \ + -es@{#XERCES_CLASSES#}@'$(MACRO_XERCES_CLASSES)'@g \ + -es@{#JAVA_ARGS#}@'$(MACRO_JAVA_ARGS)'@g \ + $@.tmpl > $@ + @macros=`$(SED) -n -es'@.*{#\(.*\)#}.*@\1@p' < $@`; \ + if [ -n "$$macros" ]; then \ + $(ECHO) "error: there are undefined macros: $$macros"; \ + $(RM) $@; \ + exit 1; \ + fi; + $(CHMOD) 755 $@ + +$(SCRIPTS_WRAPPER_LINKS): $(SCRIPTS_WRAPPER) + @if [ ! -h $@ ]; then \ + $(call RUN,$(LN) -s $(notdir $(SCRIPTS_WRAPPER)) $@); \ + fi $(FUNCTION_FILES) : .latest-meta $(FUNCTION_TEMPLATE) $(RM) .latest-generate diff --git a/bin/.scala_wrapper b/bin/.scala_wrapper deleted file mode 100755 index 6564f8ff98..0000000000 --- a/bin/.scala_wrapper +++ /dev/null @@ -1,152 +0,0 @@ -#!/bin/sh -############################################################################## -# ____ ____ ____ ____ ______ # -# / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala # -# __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL # -# /_____/\____/\___/\____/____/ # -# # -############################################################################## - -############################################################################## -# launch script for scala tools -# -# @author Philippe Altherr -# @version 1.0 -# -# $Id$ - -############################################################################## -# define prefix and script - -SOURCE="$0"; -while [ -h "$SOURCE" ]; do - SCRIPT="`basename $SOURCE`"; - LOOKUP="`ls -ld "$SOURCE"`"; - TARGET="`expr "$LOOKUP" : '.*-> \(.*\)$'`"; - if expr "${TARGET:-.}/" : '/.*/$' > /dev/null; then - SOURCE="${TARGET:-.}"; - else - SOURCE="`dirname "$SOURCE"`/${TARGET:-.}"; - fi; -done; -PREFIX="`dirname "$SOURCE"`/.."; -PREFIX="`cd "$PREFIX"; pwd`"; - -############################################################################## -# compute product & version - -CVSTREE="false"; -PRODUCT="$SCRIPT" - -if [ -f "$PREFIX/VERSION" ]; then - VERSION=`head -1 "$PREFIX/VERSION"`; -elif [ -d "$PREFIX/CVS" ]; then - CVSTREE="true"; - VERSION="development version"; -else - VERSION="unknown version"; -fi - -############################################################################## -# check script name - -if [ -z "$SCRIPT" ]; then - exit 0; -fi; - -case "$SCRIPT" in - socos* | siris* | surus* | dtd2scala* ) - true;; - *) - echo "unknown script \`$SCRIPT'" 1>&2; - exit 1;; -esac; - -############################################################################## -# setup paths - -if [ "$CVSTREE" = "true" ]; then - BCEL_PATH="${BCEL_PATH:-/home/linuxsoft/apps/BCEL-5/bcel.jar}"; - FJBG_PATH="${FJBG_PATH:-/home/linuxsoft/apps/fjbg/jars/fjbg.jar}"; - MSIL_PATH="${MSIL_PATH:-/home/linuxsoft/apps/java2net/msil.jar}"; - XERCES_PATH="${XERCES_PATH:-/home/linuxsoft/apps/xerces/xercesImpl.jar}"; - SCALA_CLASSES="$PREFIX/classes"; - SCALA_SOURCES="$PREFIX/sources"; -else - PROJECT_NAME="scala"; - LIBDIR="$PREFIX/lib"; - DATADIR="$PREFIX/share"; - BCEL_PATH="$LIBDIR/bcel.jar"; - FJBG_PATH="$LIBDIR/fjbg.jar"; - MSIL_PATH="$LIBDIR/msil.jar"; - XERCES_PATH="$LIBDIR/xercesImpl.jar"; - SCALA_CLASSES="$LIBDIR/$PROJECT_NAME.jar"; - SCALA_SOURCES="$DATADIR/$PROJECT_NAME/library"; -fi; - -JAVA_CLASSPATH="$SCALA_CLASSES"; -JAVA_CLASSPATH="$JAVA_CLASSPATH:$BCEL_PATH"; -JAVA_CLASSPATH="$JAVA_CLASSPATH:$FJBG_PATH"; -JAVA_CLASSPATH="$JAVA_CLASSPATH:$MSIL_PATH"; -JAVA_CLASSPATH="$JAVA_CLASSPATH:$XERCES_PATH"; - -SCALA_CLASSPATH="${CLASSPATH:-.}" - -SCALA_BOOTCLASSPATH="$JAVA_CLASSPATH"; -SCALA_BOOTCLASSPATH="$SCALA_BOOTCLASSPATH:$SCALA_SOURCES"; - -############################################################################## -# OS specific support - -case `uname` in - CYGWIN* ) - # For Cygwin, switch paths to Windows format before running java. - # We assume that CLASSPATH is already in Windows format, so there - # is nothing to do for SCALA_CLASSPATH. - JAVA_CLASSPATH=`cygpath -w -p "$JAVA_CLASSPATH"` - SCALA_BOOTCLASSPATH=`cygpath -w -p "$SCALA_BOOTCLASSPATH"` - ;; -esac - -############################################################################## -# select java arguments - -JAVA_ARGS="-Dscala.boot.class.path='$SCALA_BOOTCLASSPATH'"; -JAVA_ARGS="$JAVA_ARGS -Dscala.class.path='$SCALA_CLASSPATH'"; -JAVA_ARGS="$JAVA_ARGS -Dscala.product='$PRODUCT'"; -JAVA_ARGS="$JAVA_ARGS -Dscala.version='$VERSION'"; -JAVA_ARGS="$JAVA_ARGS -classpath '$JAVA_CLASSPATH'"; -JAVA_ARGS="$JAVA_ARGS -ms16m -enableassertions"; - -case "$SCRIPT" in - *-debug* ) - JAVA_ARGS="$JAVA_ARGS -Djava.compiler=NONE";; -esac; - -############################################################################## -# select main class & program arguments - -# select script-specific program arguments -case "$SCRIPT" in - socos* ) - JAVA_MAIN="scalac.Main"; - ;; - surus* ) - JAVA_MAIN="scalai.Main"; - ;; - siris* ) - SCALA_WRAPPER_EXEC=${SCALA_WRAPPER_EXEC:="exec ledit"}; - JAVA_MAIN="scalai.Main"; - MAIN_ARGS="$MAIN_ARGS -interactive"; - ;; - dtd2scala* ) - JAVA_MAIN="dtd2scala.Main"; - ;; -esac; - -############################################################################## -# invoke java - -eval ${SCALA_WRAPPER_EXEC:-exec} java $JAVA_ARGS $JAVA_MAIN $MAIN_ARGS '"$@"'; - -############################################################################## diff --git a/sources/bin/.scala_wrapper.tmpl b/sources/bin/.scala_wrapper.tmpl new file mode 100644 index 0000000000..6decaf2530 --- /dev/null +++ b/sources/bin/.scala_wrapper.tmpl @@ -0,0 +1,338 @@ +#!/bin/sh +############################################################################## +# ____ ____ ____ ____ ______ # +# / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala # +# __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL # +# /_____/\____/\___/\____/____/ # +# # +############################################################################## +# Launch script for Scala tools # +############################################################################## + +# $Id$ + +############################################################################## +# Configuration + +# The configure function contains all the configurable variables of +# this script. The content of these variables may be overridden by +# defining an environment variable with the same name prefixed by +# SCALA_. For example, to run socos with a big initial heap size, one +# may run the command "env SCALA_JAVA_ARGS=-Xms1024m socos". +# +# The following environment variables are also read by this script: +# - SCALA_BOOTCLASSPATH: if defined, it is used as the default +# bootclasspath by the Scala compiler. +# +# - SCALA_CLASSPATH: if defined, it is used as the default classpath +# by the scala compiler. +# +# - CLASSPATH: if defined and if SCALA_CLASSPATH is undefined, it is +# used as the default classpath by the Scala compiler. +# +# All paths and path lists must be in Unix form (i.e. use '/' as file +# separator and ':' as path separator). There is only one exception to +# this rule: CLASSPATH must be in Windows form (i.e. use '\' and ';') +# on Windows platforms. + +configure() { + + # Location of the Scala library sources. These sources are + # included in the Scala distribution. + # This variable must refer a directory. + RUNTIME_SOURCES={#RUNTIME_SOURCES#}; + + # Location of the compiled Scala library and Scala tools. This + # library and these tools are included in the Scala distribution. + # This variable must refer a directory or a zip or jar file. + RUNTIME_CLASSES={#RUNTIME_CLASSES#}; + + # Location of the compiled dtd2scala tool. This tool is included + # in the Scala distribution. + # This variable must refer a directory or a zip or jar file. + DTD2SCALA_CLASSES={#DTD2SCALA_CLASSES#}; + + # Location of the compiled fjbg library. This library is included + # in the Scala distribution. + # This variable must refer a directory or a zip or jar file. + FJBG_CLASSES={#FJBG_CLASSES#}; + + # Location of the compiled msil library. This library is included + # in the Scala distribution. + # This variable must refer a directory or a zip or jar file. + MSIL_CLASSES={#MSIL_CLASSES#}; + + # Location of the compiled bcel library. This library may be found + # at http://jakarta.apache.org/bcel/. + # This variable must refer a directory or a zip or jar file. + BCEL_CLASSES={#BCEL_CLASSES#}; + + # Location of the compiled xerces library. This library may be + # found at http://xml.apache.org/xerces2-j/. + # This variable must refer a directory or a zip or jar file. + XERCES_CLASSES={#XERCES_CLASSES#}; + + # Command to start the Java VM. + JAVA_EXEC="java"; + + # Additional arguments to pass to the Java VM. + JAVA_ARGS={#JAVA_ARGS#}; + + # Command to start subprocesses. This is mainly for debugging + # purposes. One may, for example, display the Java command that is + # started by "socos", by running "env SCALA_EXEC=echo socos". + EXEC="exec"; + +} + +############################################################################## +# Error functions + +# Prints a warning message on stderr. +warning() { + echo "$0: warning: " "$@" 1>&2; +} + +# Prints an error message on stderr. +error() { + echo "$0:" "$@" 1>&2; +} + +# Prints an error message on stderr and exits with a non-zero status. +abort() { + error "$@"; + exit 1; +} + +############################################################################## +# File name and path list conversion functions + +# Prints the OS specific form of the given Unix form file name. +get_os_filename() { + [ $# = 1 ] || abort "internal error"; + case "$UNAME" in + CYGWIN* ) cygpath --windows "$1";; + * ) echo "$@";; + esac; +} + +# Prints the OS specific form of the given Unix form path list. +get_unix_filename() { + [ $# = 1 ] || abort "internal error"; + case "$UNAME" in + CYGWIN* ) cygpath --unix "$1";; + * ) echo "$@";; + esac; +} + +# Prints the Unix form of the given OS specific form file name. +get_os_pathlist() { + [ $# = 1 ] || abort "internal error"; + case "$UNAME" in + CYGWIN* ) cygpath --window --path "$1";; + * ) echo "$@";; + esac; +} + +# Prints the Unix form of the given OS specific form path list. +get_unix_pathlist() { + [ $# = 1 ] || abort "internal error"; + case "$UNAME" in + CYGWIN* ) cygpath --unix --path "$1";; + * ) echo "$@";; + esac; +} + +############################################################################## +# Variable configuration functions + +# Configures the variable with the given name. If a variable named +# SCALA_$1 is defined, assigns its value to the variable named $1, +# otherwise does nothing. +configure_variable() { + [ $# = 1 ] || abort "internal error"; + name="$1"; shift 1; + + if set | grep "^SCALA_$name=" > /dev/null; then + eval $name=\$SCALA_$name; + fi; +} + +# Configures and tests the path variable with the given name. If a +# variable named SCALA_$1 is defined and refers an existing directory +# or file, assigns its value to the variable named $1. If, after that, +# the variable $1 refers a non-existing path, exits with an error. +configure_path_variable() { + [ $# = 1 ] || abort "internal error"; + name="$1"; shift 1; + + if set | grep "^SCALA_$name=" > /dev/null; then + path=`eval echo \\\$SCALA_\$name`; + if [ -f "$path" -o -d "$path" ]; then + eval $name=\$SCALA_$name; + else + warning "File refered by SCALA_$name ($path) does not exist."; + unset SCALA_$name; + fi; + fi; + + path=`eval echo \\\$\$name`; + if [ ! -f "$path" -a ! -d "$path" ]; then + abort "File referred by $name ($path) does not exist." \ + "Please, fix the definition of $name in file $SOURCE." \ + "Alternatively you may also define the environment" \ + "variable SCALA_$name."; + fi +} + +############################################################################## +# Path list construction functions + +# Appends a named path to a named path list. Configures the path +# variable $2 and updates the path list in variable $1 by appending +# the path from variable $2. +append_path() { + [ $# = 2 ] || abort "internal error"; + configure_path_variable "$2"; + + listname="$1"; shift 1; + pathname="$1"; shift 1; + list=`eval echo \\\$\$listname`; + + if [ -z "$list" ]; then + eval $listname=\$$pathname; + else + eval $listname=\$$listname:\$$pathname; + fi; +} + +############################################################################## +# Java invocation functions + +# Invokes Java with the given arguments (which must, at least, contain +# the name of the main class) and the following additional arguments: +# - arguments specified by variable JAVA_ARGS +# - script-suffix-specific arguments +# - definition of Java properties scala.product and scala.version +# - classpath set to $JAVA_CLASSPATH +exec_java() { + [ $# -gt 0 ] || abort "internal error"; + + # configure variables + configure_variable EXEC; + configure_variable JAVA_EXEC; + configure_variable JAVA_ARGS; + + # append script-suffix-specific arguments + case "$SCRIPT" in + *-debug* ) JAVA_ARGS="$JAVA_ARGS -Djava.compiler=NONE";; + esac; + + # invoke Java + $EXEC $JAVA_EXEC $JAVA_ARGS \ + -classpath "`get_os_pathlist "$JAVA_CLASSPATH"`" \ + -Dscala.product="$SCRIPT" \ + -Dscala.version="$VERSION" \ + "$@"; +} + +# Starts a Java program using the Scala compiler. The given arguments +# are passed to exec_java. They must, at least, contain the name of +# the main class. +exec_compile() { + [ $# -gt 0 ] || abort "internal error"; + + # compute Java classpath + append_path JAVA_CLASSPATH RUNTIME_CLASSES; + append_path JAVA_CLASSPATH BCEL_CLASSES; + append_path JAVA_CLASSPATH FJBG_CLASSES; + append_path JAVA_CLASSPATH MSIL_CLASSES; + + # compute Scala classpath + if [ -z "$SCALA_CLASSPATH" ]; then + if [ -n "$CLASSPATH" ]; then + SCALA_CLASSPATH=`get_unix_pathlist "$CLASSPATH"`; + else + SCALA_CLASSPATH="."; + fi; + fi; + + # compute Scala boot classpath + if [ -z "$SCALA_BOOTCLASSPATH" ]; then + append_path SCALA_BOOTCLASSPATH RUNTIME_SOURCES; + append_path SCALA_BOOTCLASSPATH RUNTIME_CLASSES; + fi; + + # invoke Java + exec_java \ + -Dscala.class.path=`get_os_pathlist "$SCALA_CLASSPATH"` \ + -Dscala.boot.class.path=`get_os_pathlist "$SCALA_BOOTCLASSPATH"` \ + "$@"; +} + +# Starts a program using dtd2scala. The given arguments are passed to +# exec_java. They must, at least, contain the name of the main class. +exec_dtd2scala() { + [ $# -gt 0 ] || abort "internal error"; + + # compute Java classpath + append_path JAVA_CLASSPATH DTD2SCALA_CLASSES; + append_path JAVA_CLASSPATH XERCES_PATH; + + # invoke Java + exec_java \ + "$@"; +} + +############################################################################## +# Implementation of scala-info + +scala_info() { + abort "!!! not yet implemented"; +} + +############################################################################## +# Definition of UNAME, SOURCE, SCRIPT, PREFIX and VERSION + +unset SCRIPT; +UNAME=`uname`; +SOURCE=$0; +while [ -h "$SOURCE" ]; do + SCRIPT=`basename "$SOURCE"`; + LOOKUP=`ls -ld "$SOURCE"`; + TARGET=`expr "$LOOKUP" : '.*-> \(.*\)$'`; + if expr "${TARGET:-.}/" : '/.*/$' > /dev/null; then + SOURCE=${TARGET:-.}; + else + SOURCE=`dirname "$SOURCE"`/${TARGET:-.}; + fi; +done; +PREFIX=`dirname "$SOURCE"`/..; +PREFIX=`cd "$PREFIX"; pwd`; + +VERSION={#VERSION#}; +VERSION=${VERSION:-"unknown version"}; + +############################################################################## +# Test of invocation method + +if [ -z "$SCRIPT" ]; then + abort "Illegal direct invocation; invoke me through a symbolic link."; +fi; + +############################################################################## +# Configuration and invocation of $SCRIPT + +unset JAVA_CLASSPATH; +configure; + +case "$SCRIPT" in + scala-info ) scala_info "$@";; + socos* ) exec_compile scalac.Main "$@";; + surus* ) exec_compile scalai.Main "$@";; + siris* ) exec_compile scalai.Main -interactive "$@";; + dtd2scala* ) exec_dtd2scala dtd2scala.Main "$@";; + * ) abort "Don't know what to do for $SCRIPT.";; +esac; + +############################################################################## -- cgit v1.2.3