From fcb945ca2e56ab2090f704dfc439747f18afb7bd Mon Sep 17 00:00:00 2001 From: sewardj Date: Thu, 25 Nov 1999 10:19:17 +0000 Subject: [PATCH] [project @ 1999-11-25 10:19:15 by sewardj] Don't guess where the installation directory is. Instead, read it from the STGHUGSDIR env var at startup. --- ghc/interpreter/connect.h | 7 ++++-- ghc/interpreter/dynamic.c | 17 ++++++++----- ghc/interpreter/hugs.c | 24 +++++++++++------- ghc/interpreter/machdep.c | 60 +++++++++++++++++++++++++-------------------- ghc/interpreter/runnofib | 8 +++--- ghc/interpreter/version.h | 2 +- 6 files changed, 70 insertions(+), 48 deletions(-) diff --git a/ghc/interpreter/connect.h b/ghc/interpreter/connect.h index cf99336..f956c6d 100644 --- a/ghc/interpreter/connect.h +++ b/ghc/interpreter/connect.h @@ -8,8 +8,8 @@ * included in the distribution. * * $RCSfile: connect.h,v $ - * $Revision: 1.17 $ - * $Date: 1999/11/23 15:12:10 $ + * $Revision: 1.18 $ + * $Date: 1999/11/25 10:19:15 $ * ------------------------------------------------------------------------*/ /* -------------------------------------------------------------------------- @@ -378,6 +378,9 @@ Int readRegInt Args((String var, Int def)); Bool writeRegInt Args((String var, Int val)); #endif +#define N_INSTALLDIR 200 +extern char installDir[N_INSTALLDIR]; + /*--------------------------------------------------------------------------- * File operations: *-------------------------------------------------------------------------*/ diff --git a/ghc/interpreter/dynamic.c b/ghc/interpreter/dynamic.c index 46ad6e4..1b416ec 100644 --- a/ghc/interpreter/dynamic.c +++ b/ghc/interpreter/dynamic.c @@ -9,14 +9,15 @@ * included in the distribution. * * $RCSfile: dynamic.c,v $ - * $Revision: 1.12 $ - * $Date: 1999/10/29 13:41:23 $ + * $Revision: 1.13 $ + * $Date: 1999/11/25 10:19:15 $ * ------------------------------------------------------------------------*/ #include "prelude.h" #include "storage.h" #include "errors.h" #include "dynamic.h" +#include "connect.h" #if HAVE_WINDOWS_H && !defined(__MSDOS__) @@ -31,11 +32,13 @@ String symbol0; { char symbol[100]; ObjectFile instance; - if (strlen(dll0) > 996) { + if (strlen(dll0) > 996-strlen(installDir)) { ERRMSG(line) "Excessively long library name:\n%s\n",dll0 EEND; } - strcpy(dll,dll0); + dll[0] = 0; + if (strcmp("nHandle",dll0)==0) strcat(dll,installDir); + strcat(dll,dll0); strcat(dll, ".dll"); if (strlen(symbol0) > 96) { @@ -79,11 +82,13 @@ String symbol; { void* sym; char dll[1000]; ObjectFile instance; - if (strlen(dll0) > 996) { + if (strlen(dll0) > 996-strlen(installDir)) { ERRMSG(line) "Excessively long library name:\n%s\n",dll0 EEND; } - strcpy(dll,dll0); + dll[0] = 0; + if (strcmp("nHandle",dll0)==0) strcat(dll,installDir); + strcat(dll,dll0); strcat(dll, ".so"); #ifdef RTLD_NOW instance = dlopen(dll,RTLD_NOW); diff --git a/ghc/interpreter/hugs.c b/ghc/interpreter/hugs.c index 85844cc..f1272c6 100644 --- a/ghc/interpreter/hugs.c +++ b/ghc/interpreter/hugs.c @@ -9,8 +9,8 @@ * included in the distribution. * * $RCSfile: hugs.c,v $ - * $Revision: 1.23 $ - * $Date: 1999/11/23 15:12:09 $ + * $Revision: 1.24 $ + * $Date: 1999/11/25 10:19:16 $ * ------------------------------------------------------------------------*/ #include @@ -224,12 +224,6 @@ char *argv[]; { CStackBase = &argc; /* Save stack base for use in gc */ - /* Try and figure out an absolute path to the executable, so - we can make a reasonable guess about where the default - libraries (Prelude etc) are. - */ - setDefaultLibDir ( argv[0] ); - /* If first arg is +Q or -Q, be entirely silent, and automatically run main after loading scripts. Useful for running the nofib suite. */ if (argc > 1 && (strcmp(argv[1],"+Q") == 0 || strcmp(argv[1],"-Q")==0)) { @@ -246,6 +240,13 @@ char *argv[]; { Printf("|| || Report bugs to: hugs-bugs@haskell.org\n"); Printf("|| || Version: %s _________________________________________\n\n",HUGS_VERSION); + /* Get the absolute path to the directory containing the hugs + executable, so that we know where the Prelude and nHandle.so/.dll are. + We do this by reading env var STGHUGSDIR. This needs to succeed, so + setInstallDir won't return unless it succeeds. + */ + setInstallDir ( argv[0] ); + #if SYMANTEC_C Printf(" Ported to Macintosh by Hans Aberg, compiled " __DATE__ ".\n\n"); #endif @@ -319,7 +320,12 @@ String argv[]; { } #if DEBUG - DEBUG_LoadSymbols(argv_0_orig); + { + char exe_name[N_INSTALLDIR + 6]; + strcpy(exe_name, installDir); + strcat(exe_name, "hugs"); + DEBUG_LoadSymbols(exe_name); + } #endif diff --git a/ghc/interpreter/machdep.c b/ghc/interpreter/machdep.c index f1fa49f..be3eab2 100644 --- a/ghc/interpreter/machdep.c +++ b/ghc/interpreter/machdep.c @@ -13,8 +13,8 @@ * included in the distribution. * * $RCSfile: machdep.c,v $ - * $Revision: 1.13 $ - * $Date: 1999/11/24 17:32:41 $ + * $Revision: 1.14 $ + * $Date: 1999/11/25 10:19:16 $ * ------------------------------------------------------------------------*/ #ifdef HAVE_SIGNAL_H @@ -604,33 +604,40 @@ String path; { * New path handling stuff for the Combined System (tm) * ------------------------------------------------------------------------*/ -#define N_DEFAULT_LIBDIR 1000 -char defaultLibDir[N_DEFAULT_LIBDIR]; +char installDir[N_INSTALLDIR]; -/* Assumes that getcwd()++argv[0] is the absolute path to the - executable. Basically wrong. +/* Sets installDir to $STGHUGSDIR, and ensures there is a trailing + slash at the end. */ -void setDefaultLibDir ( String argv_0 ) +void setInstallDir ( String argv_0 ) { - int i; - if (argv_0[0] != SLASH) { - if (!getcwd(defaultLibDir,N_DEFAULT_LIBDIR-strlen(argv_0)-10)) { - ERRMSG(0) "Can't get current working directory" - EEND; - } - i = strlen(defaultLibDir); - if (defaultLibDir[i-1] != SLASH) defaultLibDir[i++] = SLASH; - } else { - i = 0; + int i; + char* r = getenv("STGHUGSDIR"); + if (!r) { + fprintf(stderr, + "%s: installation error: environment variable STGHUGSDIR is not set.\n", + argv_0 ); + fprintf(stderr, + "%s: pls set it to be the directory where STGHugs98 is installed.\n\n", + argv_0 ); + exit(2); + } - strcpy(&defaultLibDir[i],argv_0); - i += strlen(argv_0); - while (defaultLibDir[i] != SLASH) i--; - i++; - strcpy(&defaultLibDir[i], "lib"); - /* fprintf ( stderr, "default lib dir = %s\n", defaultLibDir ); */ + + if (strlen(r) > N_INSTALLDIR-30 ) { + fprintf(stderr, + "%s: environment variable STGHUGSDIR is suspiciously long; pls remedy\n\n", + argv_0 ); + exit(2); + } + + strcpy ( installDir, r ); + i = strlen(installDir); + if (installDir[i-1] != SLASH) installDir[i++] = SLASH; + installDir[i] = 0; } + Bool findFilesForModule ( String modName, String* path, @@ -653,13 +660,13 @@ Bool findFilesForModule ( Int nPath; Bool literate; String peStart, peEnd; - String augdPath; /* .:hugsPath:defaultLibDir */ + String augdPath; /* .:hugsPath:installDir/lib */ *path = *sExt = NULL; *sAvail = *iAvail = *oAvail = FALSE; *sSize = *iSize = *oSize = 0; - augdPath = malloc(4+strlen(defaultLibDir)+strlen(hugsPath)); + augdPath = malloc(4+3+strlen(installDir)+strlen(hugsPath)); if (!augdPath) internal("moduleNameToFileNames: malloc failed(2)"); augdPath[0] = '.'; @@ -668,7 +675,8 @@ Bool findFilesForModule ( strcat ( augdPath, hugsPath ); augdPath[2+strlen(hugsPath)] = PATHSEP; augdPath[3+strlen(hugsPath)] = 0; - strcat(augdPath,defaultLibDir); + strcat(augdPath,installDir); + strcat(augdPath,"lib"); peEnd = augdPath-1; while (1) { diff --git a/ghc/interpreter/runnofib b/ghc/interpreter/runnofib index 98d2b21..d30e43c 100644 --- a/ghc/interpreter/runnofib +++ b/ghc/interpreter/runnofib @@ -19,20 +19,20 @@ fi if [ -f $NROOT/$1/$2/$2.stdin ] then -echo "$HUGZ/hugs +Q -P$NROOT/$1/$2 Main -- $3 $4 $5 $6 $7 $8 $9" +echo "$HUGZ/hugs -Q -P$NROOT/$1/$2 Main -- $3 $4 $5 $6 $7 $8 $9" echo " < $NROOT/$1/$2/$2.stdin 2> /dev/null" echo " > $TMPFILE" else -echo "$HUGZ/hugs +Q -P$NROOT/$1/$2 Main -- $3 $4 $5 $6 $7 $8 $9" +echo "$HUGZ/hugs -Q -P$NROOT/$1/$2 Main -- $3 $4 $5 $6 $7 $8 $9" echo " < /dev/null 2> /dev/null" echo " > $TMPFILE" fi if [ -f $NROOT/$1/$2/$2.stdin ] then -$HUGZ/hugs +Q -P$NROOT/$1/$2 Main -- $3 $4 $5 $6 $7 $8 $9 < $NROOT/$1/$2/$2.stdin 2> /dev/null > $TMPFILE +$HUGZ/hugs -Q -P$NROOT/$1/$2 Main -- $3 $4 $5 $6 $7 $8 $9 < $NROOT/$1/$2/$2.stdin 2> /dev/null > $TMPFILE else -$HUGZ/hugs +Q -P$NROOT/$1/$2 Main -- $3 $4 $5 $6 $7 $8 $9 < /dev/null 2> /dev/null > $TMPFILE +$HUGZ/hugs -Q -P$NROOT/$1/$2 Main -- $3 $4 $5 $6 $7 $8 $9 < /dev/null 2> /dev/null > $TMPFILE fi if [ $? -ne 0 ]; then diff --git a/ghc/interpreter/version.h b/ghc/interpreter/version.h index a1aadfc..368ee82 100644 --- a/ghc/interpreter/version.h +++ b/ghc/interpreter/version.h @@ -13,6 +13,6 @@ #if MAJOR_RELEASE #define HUGS_VERSION "November 1999 " #else -#define HUGS_VERSION "STGHugs-991123" +#define HUGS_VERSION "STGHugs-991124" #endif -- 1.7.10.4