Browse Source

Add code in ivars.c to look for a SPICE_ROOT environment variable

that gives the location of the ngspice installation.  That allows
binaries to be installed in a different directory to the one
compiled in.  The spinit startup file is made location-independent
by passing a variable giving the location of loadable modules,
so this fixes Bug #615 -
"spinit contains arch dependent paths, but is installed as noarch DATA".
pre-master-46
Giles Atkinson 3 years ago
committed by Holger Vogt
parent
commit
6b0ab44f1e
  1. 10
      src/frontend/cpitf.c
  2. 1
      src/include/ngspice/ngspice.h
  3. 37
      src/misc/ivars.c
  4. 30
      src/spinit.in

10
src/frontend/cpitf.c

@ -293,10 +293,20 @@ ft_cpinit(void)
if ((fp = fopen(buf, "r")) != NULL) { 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; cp_interactive = FALSE;
inp_spsource(fp, TRUE, buf, FALSE); inp_spsource(fp, TRUE, buf, FALSE);
cp_interactive = TRUE; cp_interactive = TRUE;
found = TRUE; found = TRUE;
cp_remvar(VARNAME);
break; break;
#if defined(HAS_WINGUI) || defined(__MINGW32__) || defined(_MSC_VER) #if defined(HAS_WINGUI) || defined(__MINGW32__) || defined(_MSC_VER)

1
src/include/ngspice/ngspice.h

@ -277,6 +277,7 @@ extern char *News_File;
extern char *Spice_Path; extern char *Spice_Path;
extern char *Help_Path; extern char *Help_Path;
extern char *Lib_Path; extern char *Lib_Path;
extern char *Module_Path;
extern char *Inp_Path; extern char *Inp_Path;
extern char *Infile_Path; extern char *Infile_Path;
extern char *Spice_Exec_Path; extern char *Spice_Exec_Path;

37
src/misc/ivars.c

@ -10,6 +10,7 @@ char *Spice_Path;
char *News_File; char *News_File;
char *Help_Path; char *Help_Path;
char *Lib_Path; char *Lib_Path;
char *Module_Path;
char *Inp_Path; char *Inp_Path;
char *Spice_Exec_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 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. an entry to ngspice\visualc\src\include\ngspice\config.h.
For Windows GUI and Console the path is set relative to the executable.*/ For Windows GUI and Console the path is set relative to the executable.*/
void void
ivars(char *argv0) ivars(char *argv0)
{ {
char *temp=NULL;
char *root, *temp=NULL;
#if defined (HAS_WINGUI) || defined (__MINGW32__) || defined (_MSC_VER) #if defined (HAS_WINGUI) || defined (__MINGW32__) || defined (_MSC_VER)
char *ngpath; char *ngpath;
#endif #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 #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 #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 #endif
}
tfree(temp);
/* for printing a news file */ /* for printing a news file */
mkvar(&News_File, Spice_Lib_Dir, "news", "SPICE_NEWS"); 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"); mkvar(&Lib_Path, Spice_Lib_Dir, "scripts", "SPICE_SCRIPTS");
/* used to call ngspice with aspice command, not used in Windows mode */ /* used to call ngspice with aspice command, not used in Windows mode */
mkvar(&Spice_Path, Spice_Exec_Dir, "ngspice", "SPICE_PATH"); mkvar(&Spice_Path, Spice_Exec_Dir, "ngspice", "SPICE_PATH");
tfree(temp);
/* may be used to store input files (*.lib, *.include, ...) */ /* may be used to store input files (*.lib, *.include, ...) */
/* get directory where ngspice resides */ /* get directory where ngspice resides */
#if defined (HAS_WINGUI) || defined (__MINGW32__) || defined (_MSC_VER) #if defined (HAS_WINGUI) || defined (__MINGW32__) || defined (_MSC_VER)
{ {
ngpath = ngdirname(argv0); ngpath = ngdirname(argv0);
/* set path either to <ngspice-bin-directory>/input or, /* set path either to <ngspice-bin-directory>/input or,
if set, to environment variable NGSPICE_INPUT_DIR */ if set, to environment variable NGSPICE_INPUT_DIR */
mkvar(&Inp_Path, ngpath, "input", "NGSPICE_INPUT_DIR"); mkvar(&Inp_Path, ngpath, "input", "NGSPICE_INPUT_DIR");
tfree(ngpath); tfree(ngpath);
} }
@ -90,6 +109,7 @@ ivars(char *argv0)
NG_IGNORE(argv0); NG_IGNORE(argv0);
/* set path either to environment variable NGSPICE_INPUT_DIR /* set path either to environment variable NGSPICE_INPUT_DIR
(if given) or to NULL */ (if given) or to NULL */
env_overr(&Inp_Path, "NGSPICE_INPUT_DIR"); env_overr(&Inp_Path, "NGSPICE_INPUT_DIR");
Inp_Path = copy(Inp_Path); /* allow tfree */ Inp_Path = copy(Inp_Path); /* allow tfree */
#endif #endif
@ -100,6 +120,7 @@ ivars(char *argv0)
/* Set raw file mode, 0 by default (binary) set in conf.c, /* Set raw file mode, 0 by default (binary) set in conf.c,
may be overridden by environmental may be overridden by environmental
variable, not sure if acknowledged everywhere in ngspice */ variable, not sure if acknowledged everywhere in ngspice */
env_overr(&temp, "SPICE_ASCIIRAWFILE"); env_overr(&temp, "SPICE_ASCIIRAWFILE");
if(temp) if(temp)
AsciiRawFile = atoi(temp); AsciiRawFile = atoi(temp);

30
src/spinit.in

@ -16,29 +16,31 @@ set x11lineararcs
* comment out if central osdi management is set up * comment out if central osdi management is set up
unset osdi_enabled unset osdi_enabled
* XSPICE and OSDI are loaded from a path provided in a variable.
* Load the codemodels * Load the codemodels
if $?xspice_enabled 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 end
* Load the OpenVAF/OSDI models * Load the OpenVAF/OSDI models
if $?osdi_enabled 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 end
Loading…
Cancel
Save