From 07ea6466ad9b6bc6d09e104ce694f391cd4f69e9 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sat, 12 Aug 2017 17:37:19 +0200 Subject: [PATCH] configure option --enable-relpath add relative path ../lib to spinit for codemodels and search path in ivars.c, independently from install path which has to be an absolute path --- configure.ac | 11 +++++++++++ src/Makefile.am | 8 +++++++- src/misc/ivars.c | 25 ++++++++++++++++++++----- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 20a5cbe4c..5da4eb71c 100644 --- a/configure.ac +++ b/configure.ac @@ -171,6 +171,10 @@ AC_ARG_ENABLE([help], AC_ARG_ENABLE([xgraph], [AS_HELP_STRING([--enable-xgraph], [Enable xgraph compilation.])]) +# --enable-relpath: Relative path for binary and data. Default is "no". +# ngspice shared may want relative paths for spinit etc. +AC_ARG_ENABLE([relpath], + [AS_HELP_STRING([--enable-relpath], [Enable relative paths for spinit etc.])]) # --with-readline: Includes GNU readline support into CLI. Default is "no". AC_ARG_WITH([readline], [AS_HELP_STRING([--with-readline[=yes/no]], [Enable GNU readline support for CLI. Default=no.])]) @@ -774,8 +778,15 @@ if test "x$getopt_long" = xtrue; then AC_DEFINE([HAVE_GETOPT_LONG], [1], [Have fcn getopt_long()]) fi +AM_CONDITIONAL([RELPATH], [test "x$enable_relpath" = xyes]) +if test "x$enable_relpath" = xyes; then + AC_DEFINE_UNQUOTED([NGSPICEBINDIR], ["`echo ../bin`"], [Define the directory for executables]) + AC_DEFINE_UNQUOTED([NGSPICEDATADIR], ["`echo ../share/ngspice`"], [Define the directory for architecture independent data files]) + AC_DEFINE([HAS_RELPATH], [1], [rel. path of libraries and scripts]) +else AC_DEFINE_UNQUOTED([NGSPICEBINDIR], ["`echo $dprefix/bin`"], [Define the directory for executables]) AC_DEFINE_UNQUOTED([NGSPICEDATADIR], ["`echo $dprefix/share/ngspice`"], [Define the directory for architecture independent data files]) +fi AC_DEFINE_UNQUOTED([NGSPICEBUILDDATE], ["`date`"], [Define the build date]) if test "x$with_wingui" = xyes; then diff --git a/src/Makefile.am b/src/Makefile.am index eec46cd59..1bdafe5e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -293,13 +293,19 @@ ngspice.idx: ngmakeidx$(EXEEXT) $(srcdir)/ngspice.txt endif !SHWIN endif !WINGUI +if RELPATH +spinitpath=../lib/ngspice +endif RELPATH +if !RELPATH +spinitpath=$(pkglibdir) +endif !RELPATH ## create spinit at compile time, see ## (info "(autoconf) Installation Directory Variables") edit = sed \ -e 's|@XSPICEINIT[@]|$(XSPICEINIT)|g' \ - -e 's|@pkglibdir[@]|$(pkglibdir)|g' + -e 's|@pkglibdir[@]|$(spinitpath)|g' spinit tclspinit : Makefile rm -f $@ $@.tmp diff --git a/src/misc/ivars.c b/src/misc/ivars.c index 9a504bcf6..1abc822df 100644 --- a/src/misc/ivars.c +++ b/src/misc/ivars.c @@ -33,16 +33,30 @@ mkvar(char **p, char *path_prefix, char *var_dir, char *env_var) *p = tprintf("%s%s%s", path_prefix, DIR_PATHSEP, var_dir); } + /* $dprefix has been set to /usr/local or C:/Spice (Windows) in configure.ac, + or to given by prefix="" as parameter to ./configure command. + NGSPICEBINDIR has been set to $dprefix/bin in config.h. + NGSPICEDATADIR has been set to $dprefix/share/ngspice in config.h. + If --enable-relpath is selected as paramter to the ./configure command, then + NGSPICEBINDIR is set to ../bin in config.h. + NGSPICEDATADIR is set to ../share/ngspice in config.h. + Spice_Exec_Dir has been set to NGSPICEBINDIR in conf.c, + may be overridden here by environmental variable SPICE_EXEC_DIR. + Spice_Lib_Dir has been set to NGSPICEDATADIR in conf.c, + may be overridden here by environmental variable SPICE_LIB_DIR. + The search path for codemodels in spinit contains $dprefix, or, if --enable-relpath + 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.*/ void ivars(char *argv0) { char *temp=NULL; - /* $dprefix has been set to /usr/local or C:/Spice (Windows) in configure.ac, - NGSPICEBINDIR has been set to $dprefix/bin in configure.ac, - Spice_Exec_Dir has been set to NGSPICEBINDIR in conf.c, - may be overridden here by environmental variable SPICE_EXEC_DIR */ - env_overr(&Spice_Exec_Dir, "SPICE_EXEC_DIR"); + +#ifdef HAS_RELPATH + Spice_Lib_Dir = temp = copy("../share/ngspice"); +#else env_overr(&Spice_Lib_Dir, "SPICE_LIB_DIR"); +#endif /* for printing a news file */ mkvar(&News_File, Spice_Lib_Dir, "news", "SPICE_NEWS"); @@ -52,6 +66,7 @@ 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)