diff --git a/src/frontend/cpitf.c b/src/frontend/cpitf.c index 484b2ff49..b04900ced 100644 --- a/src/frontend/cpitf.c +++ b/src/frontend/cpitf.c @@ -293,10 +293,20 @@ ft_cpinit(void) if ((fp = fopen(buf, "r")) != NULL) { + /* Set a variable to identify the loadable module directory. + * The standard spinit uses it to load XSPICE and OSDI files. + */ + +#define VARNAME "_module_path_" + cp_vset(VARNAME, CP_STRING, Module_Path); + + /* Run spinit */ + cp_interactive = FALSE; inp_spsource(fp, TRUE, buf, FALSE); cp_interactive = TRUE; found = TRUE; + cp_remvar(VARNAME); break; #if defined(HAS_WINGUI) || defined(__MINGW32__) || defined(_MSC_VER) diff --git a/src/include/ngspice/ngspice.h b/src/include/ngspice/ngspice.h index 0937f597d..8d852e9ba 100644 --- a/src/include/ngspice/ngspice.h +++ b/src/include/ngspice/ngspice.h @@ -277,6 +277,7 @@ extern char *News_File; extern char *Spice_Path; extern char *Help_Path; extern char *Lib_Path; +extern char *Module_Path; extern char *Inp_Path; extern char *Infile_Path; extern char *Spice_Exec_Path; diff --git a/src/misc/ivars.c b/src/misc/ivars.c index ce5446982..b26c66d80 100644 --- a/src/misc/ivars.c +++ b/src/misc/ivars.c @@ -10,6 +10,7 @@ char *Spice_Path; char *News_File; char *Help_Path; char *Lib_Path; +char *Module_Path; char *Inp_Path; char *Spice_Exec_Path; @@ -49,23 +50,39 @@ mkvar(char **p, char *path_prefix, char *var_dir, char *env_var) is given, to ../lib, set by src/makefile.am. With Visual C, it is set manually by an entry to ngspice\visualc\src\include\ngspice\config.h. For Windows GUI and Console the path is set relative to the executable.*/ + void ivars(char *argv0) { - char *temp=NULL; + char *root, *temp=NULL; #if defined (HAS_WINGUI) || defined (__MINGW32__) || defined (_MSC_VER) char *ngpath; #endif + root = getenv("SPICE_ROOT"); + if (root) { + temp = tprintf("%s/share/ngspice", root); + mkvar(&Spice_Lib_Dir, root, "share/ngspice", "SPICE_LIB_DIR"); + mkvar(&Module_Path, root, "lib/ngspice", "SPICE_MODULE_DIR"); + } else { #ifdef HAS_RELPATH - Spice_Lib_Dir = temp = copy("../share/ngspice"); -#elif !defined SHARED_MODULE && (defined (HAS_WINGUI) || defined (__MINGW32__) || defined (_MSC_VER)) - ngpath = ngdirname(argv0); - mkvar(&Spice_Lib_Dir, ngpath, "../share/ngspice", "SPICE_LIB_DIR"); - tfree(ngpath); + Spice_Lib_Dir = temp = copy("../share/ngspice"); +#elif !defined SHARED_MODULE && \ + (defined (HAS_WINGUI) || defined (__MINGW32__) || defined (_MSC_VER)) + + ngpath = ngdirname(argv0); + mkvar(&Spice_Lib_Dir, ngpath, "../share/ngspice", "SPICE_LIB_DIR"); + mkvar(&Module_Path, ngpath, "../lib/ngspice", "SPICE_MODULE_DIR"); + tfree(ngpath); #else - env_overr(&Spice_Lib_Dir, "SPICE_LIB_DIR"); + /* Trim "/share/ngspice" from configured Spice_Lib_Dir. */ + + temp = tprintf("%.*s", strlen(Spice_Lib_Dir) - 14, Spice_Lib_Dir); + mkvar(&Module_Path, temp, "lib/ngspice", "SPICE_MODULE_DIR"); + env_overr(&Spice_Lib_Dir, "SPICE_LIB_DIR"); #endif + } + tfree(temp); /* for printing a news file */ mkvar(&News_File, Spice_Lib_Dir, "news", "SPICE_NEWS"); @@ -75,14 +92,16 @@ ivars(char *argv0) mkvar(&Lib_Path, Spice_Lib_Dir, "scripts", "SPICE_SCRIPTS"); /* used to call ngspice with aspice command, not used in Windows mode */ mkvar(&Spice_Path, Spice_Exec_Dir, "ngspice", "SPICE_PATH"); - tfree(temp); + /* may be used to store input files (*.lib, *.include, ...) */ /* get directory where ngspice resides */ #if defined (HAS_WINGUI) || defined (__MINGW32__) || defined (_MSC_VER) { ngpath = ngdirname(argv0); + /* set path either to /input or, if set, to environment variable NGSPICE_INPUT_DIR */ + mkvar(&Inp_Path, ngpath, "input", "NGSPICE_INPUT_DIR"); tfree(ngpath); } @@ -90,6 +109,7 @@ ivars(char *argv0) NG_IGNORE(argv0); /* set path either to environment variable NGSPICE_INPUT_DIR (if given) or to NULL */ + env_overr(&Inp_Path, "NGSPICE_INPUT_DIR"); Inp_Path = copy(Inp_Path); /* allow tfree */ #endif @@ -100,6 +120,7 @@ ivars(char *argv0) /* Set raw file mode, 0 by default (binary) set in conf.c, may be overridden by environmental variable, not sure if acknowledged everywhere in ngspice */ + env_overr(&temp, "SPICE_ASCIIRAWFILE"); if(temp) AsciiRawFile = atoi(temp); diff --git a/src/spinit.in b/src/spinit.in index f1ca1c285..ed1b4b78f 100644 --- a/src/spinit.in +++ b/src/spinit.in @@ -16,29 +16,31 @@ set x11lineararcs * comment out if central osdi management is set up unset osdi_enabled +* XSPICE and OSDI are loaded from a path provided in a variable. + * Load the codemodels if $?xspice_enabled -@XSPICEINIT@ codemodel @pkglibdir@/spice2poly.cm -@XSPICEINIT@ codemodel @pkglibdir@/analog.cm -@XSPICEINIT@ codemodel @pkglibdir@/digital.cm -@XSPICEINIT@ codemodel @pkglibdir@/xtradev.cm -@XSPICEINIT@ codemodel @pkglibdir@/xtraevt.cm -@XSPICEINIT@ codemodel @pkglibdir@/table.cm +@XSPICEINIT@ codemodel $_module_path_/spice2poly.cm +@XSPICEINIT@ codemodel $_module_path_/analog.cm +@XSPICEINIT@ codemodel $_module_path_/digital.cm +@XSPICEINIT@ codemodel $_module_path_/xtradev.cm +@XSPICEINIT@ codemodel $_module_path_/xtraevt.cm +@XSPICEINIT@ codemodel $_module_path_/table.cm end * Load the OpenVAF/OSDI models if $?osdi_enabled - osdi @pkglibdir@/asmhemt.osdi - osdi @pkglibdir@/bjt504t.osdi - osdi @pkglibdir@/BSIMBULK107.osdi - osdi @pkglibdir@/BSIMCMG.osdi - osdi @pkglibdir@/HICUMl0-2.0.osdi - osdi @pkglibdir@/psp103.osdi - osdi @pkglibdir@/r2_cmc.osdi - osdi @pkglibdir@/vbic_4T_et_cf.osdi + osdi $_module_path_/asmhemt.osdi + osdi $_module_path_/bjt504t.osdi + osdi $_module_path_/BSIMBULK107.osdi + osdi $_module_path_/BSIMCMG.osdi + osdi $_module_path_/HICUMl0-2.0.osdi + osdi $_module_path_/psp103.osdi + osdi $_module_path_/r2_cmc.osdi + osdi $_module_path_/vbic_4T_et_cf.osdi end