Index: Singular/mod_lib.h
===================================================================
--- Singular/mod_lib.h	(revision 1684c331ce908bffa043d3afe97c0a2c4b181d99)
+++ Singular/mod_lib.h	(revision bbeddf73180e5a0b82609d4054f2cf3d3de40a27)
@@ -9,6 +9,14 @@
 lib_types type_of_LIB(const char *newlib, char *fullname);
 
+
+#if HAVE_GFANLIB 
+#define SI_BUILTIN_GFANLIB(add) add(gfanlib)
+#else
+#define SI_BUILTIN_GFANLIB(add) 
+#endif
+
+
 #ifdef EMBED_PYTHON
-#define SI_BUILTIN_PYOBJECT(add) add(pyobject) add(syzextra)
+#define SI_BUILTIN_PYOBJECT(add) add(pyobject)  add(syzextra)      SI_BUILTIN_GFANLIB(add)
 //TODO: the line above means that syzextra should be staticly embedded IFF pyobjects do so :(
 #else
Index: dyn_modules/callgfanlib/Makefile.am
===================================================================
--- dyn_modules/callgfanlib/Makefile.am	(revision 1684c331ce908bffa043d3afe97c0a2c4b181d99)
+++ dyn_modules/callgfanlib/Makefile.am	(revision bbeddf73180e5a0b82609d4054f2cf3d3de40a27)
@@ -1,25 +1,5 @@
 ACLOCAL_AMFLAGS = -I ../../m4
 
-moduledir = $(libexecdir)/singular/MOD
-
-if HAVE_GFANLIB
-if ENABLE_P_PROCS_DYNAMIC
-  module_LTLIBRARIES=gfanlib.la
-endif
-endif
-
-
-CXXTEMPLFLAGS	=
-## -fno-implicit-templates
-## --no-exceptions
-
-# DEBUGCXXFLAGS = -g -Wextra -Wall -pedantic -Wno-long-long ${CXXTEMPLFLAGS}
-#
-# NODEBUGCFLAGS   = -O3 -w -fomit-frame-pointer ${PIPE}
-# NODEBUGCXXFLAGS = -O3 -w -fomit-frame-pointer ${CXXTEMPLFLAGS}
-# ##  --no-rtti ?
-# NODEBUGDEFS = -DNDEBUG -DOM_NDEBUG
-
-# -DHAVE_CONFIG_H??
+SOURCES = bbcone.cc bbcone.h bbfan.cc bbfan.h bbpolytope.cc bbpolytope.h gfan.h gitfan.cc gitfan.h gfanlib.cc
 
 MYINCLUDES =  -I${top_srcdir} -I${top_builddir} -I${srcdir} \
@@ -28,40 +8,24 @@
 $(FACTORY_CFLAGS) $(NTL_CFLAGS) $(GMP_CFLAGS)
 
-#### AM_LDFLAGS	= -release ${PACKAGE_VERSION}
-#  -L${abs_top_builddir}/gfanlib/
-# -L${top_builddir}/Singular -L${top_builddir}/numeric -L${top_builddir}/kernel \
-# -L${top_builddir}/libpolys/polys $(USE_FACTORY) -L${top_builddir}/omalloc -L${top_builddir}/resources
-
-
-
-SOURCES = bbcone.cc bbcone.h bbfan.cc bbfan.h bbpolytope.cc bbpolytope.h gfan.h gitfan.cc gitfan.h gfanlib.cc
-gfanlib_la_SOURCES   = $(SOURCES)
-# gfanlib_g_la_SOURCES = $(SOURCES)
-
-P_PROCS_CPPFLAGS_COMMON = -DDYNAMIC_VERSION
-
-gfanlib_la_CPPFLAGS   = ${MYINCLUDES} ${P_PROCS_CPPFLAGS_COMMON}
-# ${NODEBUGDEFS}
-# gfanlib_g_la_CPPFLAGS = ${MYINCLUDES} ${P_PROCS_CPPFLAGS_COMMON}
-
-# gfanlib_la_CXXFLAGS   = ${NODEBUGCXXFLAGS}
-# gfanlib_g_la_CXXFLAGS = ${DEBUGCXXFLAGS}
-
-
-gfanlib_la_LIBADD = ${abs_top_builddir}/gfanlib/libgfan.la ${CDDGMPLDFLAGS}
-# gfanlib_g_la_LIBADD = ${gfanlib_la_LIBADD}
+if HAVE_GFANLIB
+  module_LTLIBRARIES=gfanlib.la
+endif
 
 if ENABLE_P_PROCS_DYNAMIC
-  P_PROCS_MODULE_LDFLAGS = ${AM_LDFLAGS} -module -export-dynamic -avoid-version -flat_namespace -weak_reference_mismatches weak -undefined dynamic_lookup
+  moduledir = $(libexecdir)/singular/MOD
+  P_PROCS_CPPFLAGS_COMMON = -DDYNAMIC_VERSION 
+# Add under Mac OS X: -flat_namespace -weak_reference_mismatches weak -undefined dynamic_lookup
 else
-  P_PROCS_MODULE_LDFLAGS = ${AM_LDFLAGS}
+  moduledir = $(libdir)/singular
+  P_PROCS_CPPFLAGS_COMMON = -DSTATIC_VERSION 
 endif
 
-# Add under Mac OS X: -flat_namespace -weak_reference_mismatches weak -undefined dynamic_lookup
+P_PROCS_MODULE_LDFLAGS =  -module -export-dynamic -avoid-version -flat_namespace -weak_reference_mismatches weak -undefined dynamic_lookup
 
-gfanlib_la_LDFLAGS = ${P_PROCS_MODULE_LDFLAGS}
-# gfanlib_g_la_LDFLAGS = ${P_PROCS_MODULE_LDFLAGSG}
+gfanlib_la_SOURCES  = $(SOURCES)
+gfanlib_la_CPPFLAGS = ${MYINCLUDES} ${P_PROCS_CPPFLAGS_COMMON}
+gfanlib_la_LDFLAGS  = ${AM_LDFLAGS} ${P_PROCS_MODULE_LDFLAGS}
 
-
+gfanlib_la_LIBADD   = ${abs_top_builddir}/gfanlib/libgfan.la ${CDDGMPLDFLAGS}
 
 
Index: dyn_modules/callgfanlib/gfanlib.cc
===================================================================
--- dyn_modules/callgfanlib/gfanlib.cc	(revision 1684c331ce908bffa043d3afe97c0a2c4b181d99)
+++ dyn_modules/callgfanlib/gfanlib.cc	(revision bbeddf73180e5a0b82609d4054f2cf3d3de40a27)
@@ -9,5 +9,7 @@
 #include <bbpolytope.h>
 #include <gitfan.h>
-#include "Singular/ipid.h"
+
+#include <Singular/ipid.h>
+#include <Singular/mod_lib.h>
 
 template class gfan::Vector<gfan::Integer>;
@@ -16,5 +18,5 @@
 template class gfan::Matrix<gfan::Rational>;
 
-extern "C" int mod_init(SModulFunctions* p)
+int SI_MOD_INIT(gfanlib)(SModulFunctions* p)
 {
   bbcone_setup(p);
@@ -22,3 +24,14 @@
   bbpolytope_setup(p);
   gitfan_setup(p);
+  return 0;
 }
+
+#ifndef EMBED_PYTHON
+extern "C"
+{ 
+int mod_init(SModulFunctions* psModulFunctions)
+{ 
+  return SI_MOD_INIT(gfanlib)(psModulFunctions); 
+}
+}
+#endif
Index: gfanlib/Makefile.am
===================================================================
--- gfanlib/Makefile.am	(revision 1684c331ce908bffa043d3afe97c0a2c4b181d99)
+++ gfanlib/Makefile.am	(revision bbeddf73180e5a0b82609d4054f2cf3d3de40a27)
@@ -3,29 +3,12 @@
 if HAVE_GFANLIB
   libgfan_LTLIBRARIES=libgfan.la
-# if WANT_DEBUG
-#   libgfan_LTLIBRARIES+=libgfan_g.la
-# endif
 endif
 
 libgfandir = $(libdir)/
 
-#CXXTEMPLFLAGS =-ftrapv
-### -fno-implicit-templates
-
-#libgfan_la_CFLAGS   = -O3 -fpermissive -fomit-frame-pointer ${PIPE}
-#libgfan_g_la_CFLAGS = ${PIPE}
-
-# libgfan_la_CXXFLAGS   = -O3 -fpermissive -fomit-frame-pointer ${PIPE} ${CXXTEMPLFLAGS} -fno-exceptions -fno-rtti
-# libgfan_g_la_CXXFLAGS = -g -Wextra -Wall -pedantic -Wno-long-long ${PIPE} ${CXXTEMPLFLAGS}
-# -fdiagnostics-show-option
-
 AM_CPPFLAGS = -I${top_srcdir} -I${top_builddir} -DGMPRATIONAL -DHAVE_CONFIG_H
-
-# libgfan_la_CPPFLAGS   = ${AM_CPPFLAGS} -DHAVE_CONFIG_H -DNDEBUG -DOM_NDEBUG
-# libgfan_g_la_CPPFLAGS = ${AM_CPPFLAGS} -DHAVE_CONFIG_H
 
 SOURCES  = gfanlib_zcone.cpp gfanlib_symmetry.cpp gfanlib_symmetriccomplex.cpp gfanlib_polyhedralfan.cpp gfanlib_zfan.cpp gfanlib_polymakefile.cpp
 libgfan_la_SOURCES   = $(SOURCES)
-# libgfan_g_la_SOURCES = $(SOURCES)
 
 libgfan_includedir  =$(includedir)/gfanlib/
Index: gfanlib/configure.ac
===================================================================
--- gfanlib/configure.ac	(revision 1684c331ce908bffa043d3afe97c0a2c4b181d99)
+++ gfanlib/configure.ac	(revision bbeddf73180e5a0b82609d4054f2cf3d3de40a27)
@@ -24,5 +24,4 @@
 
 # Checks for libraries.
-
 LT_INIT
 
@@ -30,31 +29,10 @@
 AC_HEADER_STDC
 
-LB_CHECK_GMP(4.0,,AC_MSG_ERROR([Unable to find GMP on your machine: please use --with-gmp=PATH_TO_DIR_CONTAINING_LIB_AND_INCLUDE (see also ./configure --help if you do not understand what we are talking about)]))
-SING_CHECK_GFANLIB
-
-# AC_CHECK_HEADERS([gmp.h])
-# if test "$ac_cv_header_gmp_h" == no
-# then
-#	AC_MSG_WARN([Error, gmp.h is missing!])
-#	exit 1
-# fi
-AC_CHECK_HEADERS([cdd/setoper.h setoper.h cddlib/setoper.h])
-# if test "$ac_cv_header_setoper_h" == no -a "$ac_cv_header_cdd_setoper_h" == no -a "$ac_cv_header_cddlib_setoper_h" == no
-#then
-#	AC_MSG_WARN([Error, setoper.h is missing!])
-#fi
-
-# if setoper.h is there, assume that also cdd.h is there
-
-#if test "x$ENABLE_GFANLIB" = xyes; then
-#if test "$ac_cv_header_setoper_h" == no -a "$ac_cv_header_cdd_setoper_h" == no -a "$ac_cv_header_cddlib_setoper_h" == no
-#then
-###	exit 0
-#fi
-#fi
-
 # Checks for typedefs, structures, and compiler characteristics.
 AC_C_INLINE
 
+LB_CHECK_GMP(4.0,,AC_MSG_ERROR([Unable to find GMP on your machine: please use --with-gmp=PATH_TO_DIR_CONTAINING_LIB_AND_INCLUDE (see also ./configure --help if you do not understand what we are talking about)]))
+
+SING_CHECK_GFANLIB
 
 #AC_MSG_RESULT($ac_cv_singuname)
Index: m4/gfanlib-check.m4
===================================================================
--- m4/gfanlib-check.m4	(revision 1684c331ce908bffa043d3afe97c0a2c4b181d99)
+++ m4/gfanlib-check.m4	(revision bbeddf73180e5a0b82609d4054f2cf3d3de40a27)
@@ -9,55 +9,59 @@
 [ENABLE_GFANLIB="no"])
 
-BACKUP_LIBS=$LIBS
+AC_MSG_CHECKING(whether to build with gfanlib)
 
-AC_MSG_CHECKING(whether to build with gfanlib)
 if test "x$ENABLE_GFANLIB" = xyes; then
  AC_MSG_RESULT(yes)
+
+ AC_CHECK_HEADERS([setoper.h cdd/setoper.h cddlib/setoper.h])
+
+ if test "$ac_cv_header_setoper_h" == no -a "$ac_cv_header_cdd_setoper_h" == no -a "$ac_cv_header_cddlib_setoper_h" == no
+ then
+	AC_MSG_WARN([Error, setoper.h is missing!]) 
+ fi
+
+ AC_MSG_CHECKING([whether libcddgmp is usable])
+
+ BACKUP_LIBS=$LIBS
+
+ LIBS="-lcddgmp $GMP_LIBS $LIBS"
+
  AC_LANG_PUSH(C++)
- SAVE_LIBS=$LIBS
- LIBS="-lcddgmp $GMP_LIBS $LIBS"
-AC_LINK_IFELSE(
-  [AC_LANG_PROGRAM([#include <cdd/setoper.h>
-  #include <cdd/cdd.h>],
-    [dd_set_global_constants()])],
-  [LIBS="-lcddgmp $SAVE_LIBS"] [CDDGMPLDFLAGS="-lcddgmp"] 
-  [PASSED_ALL_TESTS_FOR_GFANLIB="yes"],
-  [AC_MSG_WARN([libcddgmp is not installed.])] 
-  [PASSED_ALL_TESTS_FOR_GFANLIB="no"
-  ]
-)
-if test "$PASSED_ALL_TESTS_FOR_GFANLIB" != yes; then
-AC_LINK_IFELSE(
-  [AC_LANG_PROGRAM([#include <setoper.h>
-  #include "cdd.h"],
-    [dd_set_global_constants()])],
-  [LIBS="$SAVE_LIBS -lcddgmp"] [CDDGMPLDFLAGS="-lcddgmp"] 
-  [PASSED_ALL_TESTS_FOR_GFANLIB="yes"],
-  [AC_MSG_WARN([libcddgmp is not installed.])] 
-  [PASSED_ALL_TESTS_FOR_GFANLIB="no"
-  ]
-)
-fi
-if test "$PASSED_ALL_TESTS_FOR_GFANLIB" != yes; then
-AC_LINK_IFELSE(
-  [AC_LANG_PROGRAM([#include <cddlib/setoper.h>
-  #include "cddlib/cdd.h"],
-    [dd_set_global_constants()])],
-  [LIBS="$SAVE_LIBS -lcddgmp"] [CDDGMPLDFLAGS="-lcddgmp"] 
-  [PASSED_ALL_TESTS_FOR_GFANLIB="yes"],
-  [AC_MSG_WARN([libcddgmp is not installed.])] 
-  [PASSED_ALL_TESTS_FOR_GFANLIB="no"
-  ]
-)
-fi
-  AC_LANG_POP()
+ AC_LINK_IFELSE(
+  [
+   AC_LANG_PROGRAM(
+    [
+     #ifdef HAVE_SETOPER_H
+     # include <setoper.h>
+     # include <cdd.h>
+     #endif
+     #ifdef HAVE_CDD_SETOPER_H
+     # include <cdd/setoper.h>
+     # include <cdd/cdd.h>
+     #endif
+     #ifdef HAVE_CDDLIB_SETOPER_H
+     # include <cddlib/setoper.h>
+     # include <cddlib/cdd.h>
+     #endif
+    ], [dd_set_global_constants()]    )
+  ],
+  [PASSED_ALL_TESTS_FOR_GFANLIB="1"] [CDDGMPLDFLAGS="-lcddgmp"],
+  [PASSED_ALL_TESTS_FOR_GFANLIB="0"]
+ )
+ AC_LANG_POP()
+
+ LIBS=$BACKUP_LIBS
+
+ AC_MSG_RESULT(no)
+
+ AC_SUBST(CDDGMPLDFLAGS) 
 else
  AC_MSG_RESULT(no)
- PASSED_ALL_TESTS_FOR_GFANLIB="no";
+ PASSED_ALL_TESTS_FOR_GFANLIB="0"
 fi
 
-LIBS=$BACKUP_LIBS
 
-AM_CONDITIONAL(HAVE_GFANLIB, test "x$PASSED_ALL_TESTS_FOR_GFANLIB" = xyes)
+AM_CONDITIONAL(HAVE_GFANLIB, test "x$PASSED_ALL_TESTS_FOR_GFANLIB" = x1)
+AC_DEFINE_UNQUOTED(HAVE_GFANLIB, ${PASSED_ALL_TESTS_FOR_GFANLIB}, [whether gfanlib support is enabled])
 
 ])
