From 4661319bc7048f9d0c05921ddb139f8fab86add1 Mon Sep 17 00:00:00 2001
From: Lars Immisch <lars@ibp.de>
Date: Wed, 11 Apr 2012 23:48:06 +0200
Subject: [PATCH 2/2] Fixed python build for OS X.

Installation/building of the python module _pysimulavr.{so|dll} was broken
on OS X: manual installation was replaced by a hopefully more portable
mechanism.

_pysimulavr.{so|dll} had to be linked statically against the sources of
libsim, otherwise, libsim.dylib had an unresolved exteral to libbfd.

Signed-off-by: Lars Immisch <lars@ibp.de>
---
 configure.ac    |   19 +++++-------
 src/Makefile.am |   86 +++++++++++++++++++++++++------------------------------
 src/setup.py.in |    5 ++--
 3 files changed, 49 insertions(+), 61 deletions(-)

diff --git a/configure.ac b/configure.ac
index fa269d7..01ed760 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,16 +12,6 @@ AC_CONFIG_MACRO_DIR([m4])
 AM_MAINTAINER_MODE
 
 ####
-# check for OS and build system: MSYS/MingW
-####
-AC_SYS_CHECK_MINGW
-if test "$ac_sys_check_uname_o" = "Msys"; then
-  AC_SUBST([PYTHON_MODULE_EXTENSION],[.pyd])
-else
-  AC_SUBST([PYTHON_MODULE_EXTENSION],[.so])
-fi
-
-####
 # support of libtool, g++, swig (for tcl module and python module used)
 ####
 LT_INIT
@@ -48,9 +38,14 @@ AX_TCL_ENVIRONMENT
 ####
 AZ_PYTHON_DEFAULT
 AZ_PYTHON_ENABLE
-AZ_PYTHON_VERSION_ENSURE([2.4.0])
+AM_PATH_PYTHON([2.4])
+AC_PYTHON_DEVEL([2.4])
 SWIG_PYTHON
-AM_PATH_PYTHON
+# These two lines force installalation of _pysimulavr.{so|dll} and pysimulavr.py
+# into PYTHON_SITE_PKG (which is in the PYTHONPATH of the detected python 
+# executable)
+AC_SUBST([pkgpythondir], [$PYTHON_SITE_PKG])
+AC_SUBST([pkgpyexecdir], [$PYTHON_SITE_PKG])
 
 ###
 # Regression test suite support programs
diff --git a/src/Makefile.am b/src/Makefile.am
index 6709f22..6717dc5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,46 +15,9 @@ CXXFLAGS=-g -O2 -Icmd -Iui -Ihwtimer
 bin_PROGRAMS    = simulavr
 @MAINT@ noinst_PROGRAMS = kbdgentables
 
-lib_LTLIBRARIES = 
+lib_LTLIBRARIES =
 noinst_LTLIBRARIES =
 
-if USE_SWIG
-
-if USE_TCL
-TCL_WRAP_SRC = simulavr_wrap.cxx
-TCL_LIB      = @AVR_TCL_LIB@
-TCL_INCLUDE  = @AVR_TCL_INCLUDE@
-lib_LTLIBRARIES += libsimulavr.la
-endif
-
-if PYTHON_USE
-PYTHON_MODUL_LIB=_pysimulavr@PYTHON_MODULE_EXTENSION@
-PYTHON_XTRA_INC=-Ipython
-PYTHON_MODUL_INTERFACE=$(srcdir)/python/pysimulavr.i
-noinst_LTLIBRARIES += lib_pysimulavr.la
-nodist_lib_pysimulavr_la_SOURCES=pysimulavr_wrap.cpp
-lib_pysimulavr_la_CPPFLAGS=$(PYTHON_CPPFLAGS) $(PYTHON_XTRA_INC)
-lib_pysimulavr_la_LDFLAGS = -version-info 0:0:0 -rpath ${prefix}/lib
-lib_pysimulavr_la_LIBADD= libsim.la \
-  -L$(AVR_LIBBFD_LIBPATH) -lbfd -L$(AVR_LIBIBERTY_LIBPATH) -liberty $(EXTRA_LIBS)
-
-pysimulavr_wrap.cpp: $(PYTHON_MODUL_INTERFACE)
-	$(SWIG) $(SWIG_PYTHON_OPT) $(PYTHON_XTRA_INC) -o $@ $?
-
-$(PYTHON_MODUL_LIB): lib_pysimulavr.la
-if SYS_MINGW
-	$(CXX) -shared -o $(PYTHON_MODUL_LIB) \
-		$(addprefix .libs/,$(lib_pysimulavr_la_OBJECTS:.lo=.o)) .libs/libsim.a \
-		-lstdc++ -L$(AVR_LIBBFD_LIBPATH) -lbfd -L$(AVR_LIBIBERTY_LIBPATH) -liberty \
-		$(EXTRA_LIBS) $(PYTHON_LDFLAGS)
-else
-	cp .libs/lib_pysimulavr.so $(PYTHON_MODUL_LIB)
-endif
-
-endif
-
-endif
-
 if USE_VERILOG
 noinst_LTLIBRARIES += libavrvpi.la
 endif
@@ -67,19 +30,19 @@ FAB_HEADER=avr_ATtiny2313.h avr_ATtiny15.h avr_ATmega8.h
 endif
 
 libsim_la_SOURCES = \
-  adcpin.cpp application.cpp at4433.cpp at8515.cpp atmega668base.cpp atmega128.cpp \
-  at90canbase.cpp atmega8.cpp atmega1284abase.cpp \
+  adcpin.cpp application.cpp at4433.cpp at8515.cpp atmega668base.cpp \
+  atmega128.cpp at90canbase.cpp atmega8.cpp atmega1284abase.cpp \
   atmega16_32.cpp attiny2313.cpp externalirq.cpp \
   avrdevice.cpp avrerror.cpp avrfactory.cpp avrmalloc.cpp decoder.cpp \
-  decoder_trace.cpp flash.cpp flashprog.cpp hardware.cpp helper.cpp cmd/gdbserver.cpp \
-  hwacomp.cpp hwad.cpp hweeprom.cpp \
+  decoder_trace.cpp flash.cpp flashprog.cpp hardware.cpp helper.cpp \
+  cmd/gdbserver.cpp hwacomp.cpp hwad.cpp hweeprom.cpp \
   hwtimer/timerprescaler.cpp hwtimer/prescalermux.cpp \
   hwtimer/timerirq.cpp hwpinchange.cpp hwport.cpp hwspi.cpp hwsreg.cpp \
-  hwtimer/icapturesrc.cpp hwstack.cpp hwtimer/hwtimer.cpp hwuart.cpp hwwado.cpp \
-  ioregs.cpp irqsystem.cpp ui/keyboard.cpp ui/lcd.cpp memory.cpp \
+  hwtimer/icapturesrc.cpp hwstack.cpp hwtimer/hwtimer.cpp hwuart.cpp \
+  hwwado.cpp ioregs.cpp irqsystem.cpp ui/keyboard.cpp ui/lcd.cpp memory.cpp \
   ui/mysocket.cpp net.cpp pin.cpp ui/extpin.cpp pinatport.cpp pinmon.cpp \
-  rwmem.cpp ui/scope.cpp ui/serialrx.cpp ui/serialtx.cpp spisrc.cpp spisink.cpp \
-  specialmem.cpp string2.cpp systemclock.cpp traceval.cpp ui/ui.cpp 
+  rwmem.cpp ui/scope.cpp ui/serialrx.cpp ui/serialtx.cpp spisrc.cpp \
+  spisink.cpp specialmem.cpp string2.cpp systemclock.cpp traceval.cpp ui/ui.cpp 
 
 nodist_libsim_la_SOURCES =  $(FAB_CPP)
 
@@ -88,7 +51,36 @@ libsim_la_LDFLAGS = -version-info 0:0:0 -rpath ${prefix}/lib
 nodist_libsimulavr_la_SOURCES = $(TCL_WRAP_SRC)
 libsimulavr_la_LDFLAGS = -version-info 0:0:0 -rpath ${prefix}/lib
 libsimulavr_la_LIBADD = $(libsim_la_OBJECTS) -lz \
-  -L$(AVR_LIBBFD_LIBPATH) -lbfd -L$(AVR_LIBIBERTY_LIBPATH) -liberty $(EXTRA_LIBS)
+  -L$(AVR_LIBBFD_LIBPATH) -lbfd \
+  -L$(AVR_LIBIBERTY_LIBPATH) -liberty $(EXTRA_LIBS)
+
+if USE_SWIG
+
+if USE_TCL
+TCL_WRAP_SRC = simulavr_wrap.cxx
+TCL_LIB      = @AVR_TCL_LIB@
+TCL_INCLUDE  = @AVR_TCL_INCLUDE@
+lib_LTLIBRARIES += libsimulavr.la
+endif
+
+if PYTHON_USE
+BUILT_SOURCES=pysimulavr_wrap.cpp
+SWIG_SOURCES=$(srcdir)/python/pysimulavr.i
+pkgpython_PYTHON = pysimulavr.py
+pkgpyexec_LTLIBRARIES=_pysimulavr.la
+
+PYTHON_XTRA_INC=-Ipython
+_pysimulavr_la_SOURCES= $(BUILT_SOURCES) $(SWIG_SOURCES) $(libsim_la_SOURCES)
+_pysimulavr_la_CPPFLAGS=$(PYTHON_CPPFLAGS) $(PYTHON_XTRA_INC)
+_pysimulavr_la_LDFLAGS = -module -version-info 0:0:0
+_pysimulavr_la_LIBADD= -L$(AVR_LIBBFD_LIBPATH) -lbfd \
+  -L$(AVR_LIBIBERTY_LIBPATH) -liberty $(EXTRA_LIBS) 
+
+pysimulavr_wrap.cpp: $(SWIG_SOURCES)
+	$(SWIG) $(SWIG_PYTHON_OPT) $(PYTHON_INC) $(PYTHON_XTRA_INC) -o $@ $?
+
+endif
+endif
 
 pkginclude_HEADERS = \
   adcpin.h application.h at4433.h at8515.h atmega128.h atmega16_32.h attiny2313.h \
diff --git a/src/setup.py.in b/src/setup.py.in
index aa0f9f2..141208a 100644
--- a/src/setup.py.in
+++ b/src/setup.py.in
@@ -6,12 +6,13 @@ try:
 except:
   from distutils import setup
   
-from distutils.sysconfig import get_python_lib
+from distutils.sysconfig import get_python_lib, get_config_var
 
 setup(name = 'pysimulavr',
       version = "@PACKAGE_VERSION@",
       py_modules = ["pysimulavr"],
-      data_files = [(get_python_lib(), ["_pysimulavr@PYTHON_MODULE_EXTENSION@"])],
+      data_files = [(get_python_lib(),
+                       ["_pysimulavr" + get_config_var('SO')])],
       author="Klaus Rudolph & others",
       author_email="<simulavr-devel@nongnu.org>",
       license="GPL",
-- 
1.7.9.4

