Re: Autotools build system

David Fang <[email protected]>
Newsgroups gmane.comp.gnu.gnucap.devel
Message-ID <[email protected]>
> Alright, task is on me to make autogen.sh happy again.  :)

Al,
 	Try this updated patch against your 2009-06-11 snapshot.

PatchLog: (in addition to previous description)
autogen.sh:
 	regenerate in libltdl subdir for consistency
 	direct it to use config files in parent (root) dir
configure.ac:
 	libtool section, one for libtool-2.x, other for 1.5.x (commented out)
 	removed AM_MAINTAINER_MODE (recommended) to allow make to
 		auto-regen when autotool sources are updated.
Makefile.am:
 	ACLOCAL_AMFLAGS points to m4 macros in libltdl's subdir
src/Makefile.am:
 	split out MODELHDRS in case we want to install them in the future


Same procedure after patching:
autogen.sh
configure-from-somwehere
make
make distcheck

This 'version' of gnucap again has no model plug-ins pre-loaded, you 
should either "attach gnucapbasemodels.so" or "dlopen gnucapbasemodels" 
before gnucap becomes useful.

Let me know how this goes!


Fang

David Fang
http://www.csl.cornell.edu/~fang/
http://www.achronix.com/

_______________________________________________
Gnucap-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnucap-devel
gnucap-2009-06-11.patch (text/plain, 9.7 KB)
diff -u -r gnucap-2009-06-11/Makefile.am gnucap-2009-06-11-patched/Makefile.am
--- gnucap-2009-06-11/Makefile.am	2008-06-01 07:58:12.000000000 -0700
+++ gnucap-2009-06-11-patched/Makefile.am	2009-06-21 13:43:24.000000000 -0700
@@ -2,7 +2,9 @@
 ##
 ## Top level automake file for gnucap
 
-SUBDIRS=	doc examples modelgen src
+SUBDIRS = libltdl modelgen src doc examples
 
-EXTRA_DIST=	autogen.sh Makefile.template configure.old
+ACLOCAL_AMFLAGS = -I libltdl/m4
+
+EXTRA_DIST = autogen.sh Makefile.template configure.old
 
diff -u -r gnucap-2009-06-11/autogen.sh gnucap-2009-06-11-patched/autogen.sh
--- gnucap-2009-06-11/autogen.sh	2007-02-27 09:39:37.000000000 -0800
+++ gnucap-2009-06-11-patched/autogen.sh	2009-06-21 13:35:41.000000000 -0700
@@ -1,6 +1,6 @@
-#! /bin/sh
-#
-# $Id$
+#! /bin/sh -e
+#	-e exits script on first error (non-zero exit status)
+# $Id: $
 #
 # Run the various GNU autotools to bootstrap the build
 # system.  Should only need to be done once.
@@ -9,19 +9,45 @@
 CONFIG_SHELL=/bin/sh
 export CONFIG_SHELL
 
+regen()
+{
+printf "In: "
+pwd
 echo "Running aclocal..."
-aclocal $ACLOCAL_FLAGS || exit 1
+aclocal $ACLOCAL_FLAGS
 
 echo "Running autoheader..."
-autoheader || exit 1
+autoheader $ACLOCAL_FLAGS
 
 echo "Running automake..."
-automake -a -c --gnu || exit 1
+automake -a -c --gnu
 
 echo "Running autoconf..."
-autoconf || exit 1
+autoconf $ACLOCAL_FLAGS
+}
+
+echo "Running libtoolize..."
+rm -rf libltdl
+libtoolize --ltdl --force --copy
+
+# In the freshly installed libltdl directory:
+# we forcibly remove some autotool files to force them to be regenerated
+# using the local versions of the autotools, in case of version mismatch.
+# Also point the config dir to the top-level one to share common files.
+(cd libltdl && \
+        mkdir -p removed && \
+        mv -f configure.ac configure.ac.bkp && \
+        sed '/^AC_CONFIG_AUX_DIR/s|(.*)|([..])|' configure.ac.bkp \
+                > configure.ac && \
+        mv -f configure.ac.bkp removed && \
+        mv -f Makefile.in configure aclocal.m4 config-h.in removed ; \
+        mv -f config.* install-sh ltmain.sh missing removed || : ; \
+        regen )
+
+# back to top-dir
+regen
 
-echo "not Running configure..."
+echo "not Running configure."
 ##./configure $@ || exit 1
 
 
diff -u -r gnucap-2009-06-11/configure.ac gnucap-2009-06-11-patched/configure.ac
--- gnucap-2009-06-11/configure.ac	2009-06-10 21:30:52.000000000 -0700
+++ gnucap-2009-06-11-patched/configure.ac	2009-06-21 13:40:08.000000000 -0700
@@ -28,8 +28,37 @@
 
 AM_INIT_AUTOMAKE(gnucap, 2009-06-11)
 AM_CONFIG_HEADER([config.h])
+AC_CANONICAL_HOST
+
+dnl AM_MAINTAINER_MODE
+
+dnl --------------------------- LIBTOOL SECTION -------------------------------
+dnl libtool-1.5.x setup
+dnl AC_LIBLTDL_CONVENIENCE
+dnl AC_SUBST(LTDLINCL)
+dnl AC_SUBST(LIBLTDL)
+dnl AC_LIB_LTDL
+dnl AC_LIBTOOL_DLOPEN
+dnl AC_DISABLE_STATIC
+dnl AC_PROG_LIBTOOL
+dnl AC_CONFIG_SUBDIRS(libltdl)
+
+dnl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+dnl libtool-2.x setup
+AC_CONFIG_MACRO_DIR([libltdl/m4])
+LT_INIT
+AC_DISABLE_STATIC
+LTDL_INIT
+AC_SUBST(LTDLINCL)
+AC_SUBST(LIBLTDL)
+dnl ------------------------- end LIBTOOL SECTION -----------------------------
+
+dnl need these variables to augment test environment
+LTDL_SHLIBPATH_VAR=$libltdl_cv_shlibpath_var
+AC_SUBST(LTDL_SHLIBPATH_VAR)
+LTDL_OBJDIR=$libltdl_cv_objdir
+AC_SUBST(LTDL_OBJDIR)
 
-AM_MAINTAINER_MODE
 
 AC_MSG_CHECKING([if debug code should be compiled in])
 AC_ARG_ENABLE([debug],
@@ -121,7 +150,8 @@
 fi
 
 # exports symbols to plugins
-LDFLAGS="$LDFLAGS -rdynamic"
+# LDFLAGS="$LDFLAGS -rdynamic"
+# use libtool flag -export-dynamic
 
 #AC_OUTPUT([
 #	Makefile
diff -u -r gnucap-2009-06-11/modelgen/Makefile.am gnucap-2009-06-11-patched/modelgen/Makefile.am
--- gnucap-2009-06-11/modelgen/Makefile.am	2009-06-10 21:19:47.000000000 -0700
+++ gnucap-2009-06-11-patched/modelgen/Makefile.am	2009-06-20 15:06:32.000000000 -0700
@@ -41,5 +41,5 @@
  configure.old Makefile.template
 
 
-INCLUDES=	-I$(top_srcdir)/src
+AM_CPPFLAGS = -I$(top_srcdir)/src
 
diff -u -r gnucap-2009-06-11/src/Makefile.am gnucap-2009-06-11-patched/src/Makefile.am
--- gnucap-2009-06-11/src/Makefile.am	2009-06-10 21:20:12.000000000 -0700
+++ gnucap-2009-06-11-patched/src/Makefile.am	2009-06-21 14:31:48.000000000 -0700
@@ -24,6 +24,9 @@
 ##  02110-1301, USA.
 
 bin_PROGRAMS= gnucap
+pkglib_LTLIBRARIES = libgnucap.la gnucapbasemodels.la
+
+AM_CPPFLAGS = $(LTDLINCL)
 
 #------------------------------------------------------------------------
 # These source files can be omitted, and supplied as plugins.
@@ -91,7 +94,8 @@
 e_elemnt.cc e_ccsrc.cc e_storag.cc e_cardlist.cc \
 bm_model.cc bm_value.cc bm_cond.cc bm.cc \
 c__cmd.cc c_attach.cc c_file.cc c_genrat.cc \
-findbr.cc plot.cc main.cc globals.cc
+findbr.cc plot.cc globals.cc
+# main.cc
 #------------------------------------------------------------------------
 RAW_HDRS = \
 md.h ap.h mode.h constant.h declare.h patchlev.h \
@@ -111,40 +115,54 @@
 c_comand.h globals.h
 #------------------------------------------------------------------------
 ## The modelgen generated files
-MODELSRCS= ${MODELS:.model=.cc} ${MODELS:.model=.h}
+MODELSRCS= ${MODELS:.model=.cc}
+MODELHDRS= ${MODELS:.model=.h}
 MODELOBJS= ${MODELS:.model=.${OBJEXT}}
+MODELLTOBJS= ${MODELS:.model=.lo}
 
-nodist_gnucap_SOURCES= ${SRCS1} ${MODELSRCS} ${SRCS2}
+nodist_gnucapbasemodels_la_SOURCES = ${MODELSRCS} ${MODELHDRS}
+gnucapbasemodels_la_LDFLAGS = -module
 
 SRCS1= 
 SRCS2= ${RAW_SRCS} ${RAW_HDRS}
 
+libgnucap_la_SOURCES= ${SRCS1} ${SRCS2}
+libgnucap_la_LIBADD= ${LIBLTDL}
+
+gnucap_SOURCES= main.cc
+gnucap_LDADD = libgnucap.la
+# if symbols from executable are needed for plug-in modules
+gnucap_LDFLAGS = -export-dynamic
+
 # make all of the model object files depend on all of the model sources
 # this is a bit overkill, but for example the bjt model makes use of the
 # diode model and we want to be sure and capture that dependency
-${MODELOBJS}: ${MODELSRCS}
+${MODELOBJS} ${MODELLTOBJS}: ${MODELSRCS} ${MODELHDRS}
 
 ## Include the .model files in the distfile as well as the rest of the
 ## non-generated sources
 
-EXTRA_DIST= ${MODELS} ${SRCS1} ${SRCS2} \
+EXTRA_DIST= ${MODELS} \
 configure.old Make1 test_readline.cc spice-wrapper.cc \
 Make3 Makefile.template \
 Make2.g++ Make2.Debug Make2.mingw32 \
 Makefile.am
 
 ### Clean out the modelgen generated files
-CLEANFILES= ${MODELSRCS}
+CLEANFILES= ${MODELSRCS} ${MODELHDRS}
 
 ## Suffix rules for modelgen.
 ##
 
-SUFFIXES= .model
+SUFFIXES= .model .cc .h
 MODELGEN= @MODELGEN@
+MODELGENEXE = ${MODELGEN}${EXEEXT}
+
+.model.cc:
+	${MODELGENEXE} -cc $<
 
-%.cc : %.model %.h ${MODELGEN}${EXEEXT}
-	${MODELGEN} -cc $<
+.model.h:
+	${MODELGENEXE} -h $<
 
-%.h : %.model ${MODELGEN}${EXEEXT}
-	${MODELGEN} -h $<
+${MODELSRCS} ${MODELHDRS}: ${MODELGENEXE}
 
diff -u -r gnucap-2009-06-11/src/c_attach.cc gnucap-2009-06-11-patched/src/c_attach.cc
--- gnucap-2009-06-11/src/c_attach.cc	2009-06-10 21:20:11.000000000 -0700
+++ gnucap-2009-06-11-patched/src/c_attach.cc	2009-06-21 14:37:42.000000000 -0700
@@ -23,6 +23,7 @@
 //testing=informal
 #include "c_comand.h"
 #include "globals.h"
+#include "ltdl.h"	/* for libtool's libltdl */
 /*--------------------------------------------------------------------------*/
 namespace {
 /*--------------------------------------------------------------------------*/
@@ -77,6 +78,24 @@
 } p1;
 DISPATCHER<CMD>::INSTALL d1(&command_dispatcher, "attach|load", &p1);
 /*--------------------------------------------------------------------------*/
+class CMD_DLOPEN : public CMD {
+public:
+  void do_it(CS& cmd, CARD_LIST*)
+  {itested();
+    if (cmd.more()) {itested();
+	// TODO: use something like a reference-counted pointer
+	// so that libraries are automatically dlclose()'d upon destruction
+	const lt_dlhandle mh = lt_dlopenext(cmd.tail().c_str());
+	if (!mh) {
+		throw Exception("Failed to load module\n"
+		    "You may need to adjust your dynamic library serach paths.");
+	}
+    }
+    // else do nothing
+  }
+} p4;
+DISPATCHER<CMD>::INSTALL d4(&command_dispatcher, "dlopen", &p4);
+/*--------------------------------------------------------------------------*/
 class CMD_DETACH : public CMD {
 public:
   void do_it(CS& cmd, CARD_LIST*)
diff -u -r gnucap-2009-06-11/src/main.cc gnucap-2009-06-11-patched/src/main.cc
--- gnucap-2009-06-11/src/main.cc	2009-06-10 21:20:11.000000000 -0700
+++ gnucap-2009-06-11-patched/src/main.cc	2009-06-21 14:33:10.000000000 -0700
@@ -28,6 +28,7 @@
 #include "patchlev.h"
 #include "c_comand.h"
 #include "declare.h"	/* plclose */
+#include "ltdl.h"	/* for libtool's libltdl */
 /*--------------------------------------------------------------------------*/
 struct JMP_BUF{
   sigjmp_buf p;
@@ -176,8 +177,31 @@
   }
 }
 /*--------------------------------------------------------------------------*/
+/**
+	Class whose sole responsibility is to balance dlinit with dlexit,
+	using constructor/destructor duality, thereby guaranteeing
+	exception safety and non-leaking.
+	Provided by Fang.
+ */
+class ltdl_token {
+public:
+	ltdl_token() { lt_dlinit(); }
+	~ltdl_token() { lt_dlexit(); }
+
+private:
+	ltdl_token(const ltdl_token&);
+
+	ltdl_token&
+	operator = (const ltdl_token&);
+
+	// also stack-allocate only...
+} /* __attribute__((unused)) */ ;
+
+
+/*--------------------------------------------------------------------------*/
 int main(int argc, const char *argv[])
 {
+  const ltdl_token __lt__;
   {
     SET_RUN_MODE xx(rBATCH);
     sign_on();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.