Hi,

after trying to compile Python for .NET on ArchLinux x86_64 I have run
into several issues which the attached patches fix:

1. Enable Mono config file loading. Otherwise a Python build with UCS4
Unicode strings does not work as the Mono.Posix module cannot find
msvcrt (which is mapped to libc in Mono's config files).
2. Python.Runtime.dll.config is missing mappings for Python 2.7
3. The architecture detection code in the Makefile did not work
correctly (checking for the 86 substring is true for both x86 as well as
x86_64 targets).
4. I have renamed the clrmodule.il target in the Makefile to
clrmodule_make.il. Otherwise a fresh SVN checkout would not build as
clrmodule.il is already included.
5. Adapt the clrmod Makefile to support Mono 2.8 pkgconfig change.
Additionally, retrieve Glib 2 options from its pkgconfig and compile
the x86_64 build with -fPIC.
6. Support the standard DESTDIR parameter for the install target.
Additionally, install Python.Runtime.dll and Python.Runtime.dll.config
to the site-packages folder so it is found by the clr module.

If you have any comments or if there are any issues with these patches
please let me know.

Philip
>From eaf41a22667b58a68be4e983fb3de327b24c7b9f Mon Sep 17 00:00:00 2001
From: Philip Lorenz <loren...@gmail.com>
Date: Wed, 4 May 2011 11:35:44 +0200
Subject: [PATCH 1/6] Enable Mono config loading. This fixes an issue when
 Python is compiled with UCS4 Unicode strings and the
 Utf32Marshaler is used.

---
 src/monoclr/pynetinit.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/monoclr/pynetinit.c b/src/monoclr/pynetinit.c
index 51e44dc..70468d1 100644
--- a/src/monoclr/pynetinit.c
+++ b/src/monoclr/pynetinit.c
@@ -37,7 +37,7 @@ PyNet_Args* PyNet_Init(int ext) {
      * if you are planning on using the dllmaps defined on the
      * system configuration
      */
-    //mono_config_parse(NULL);
+    mono_config_parse(NULL);
 
     /* I can't use this call to run the main_thread_handler. The function
      * runs it in another thread but *this* thread holds the Python
-- 
1.7.5

>From 5bd4bddd71dfd6d4ddf16b5a5d6ea4686fc8269f Mon Sep 17 00:00:00 2001
From: Philip Lorenz <loren...@gmail.com>
Date: Wed, 4 May 2011 11:37:22 +0200
Subject: [PATCH 2/6] Add mappings for Python 2.7 to Mono config.

---
 Python.Runtime.dll.config |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/Python.Runtime.dll.config b/Python.Runtime.dll.config
index 9af241f..11b4fb0 100644
--- a/Python.Runtime.dll.config
+++ b/Python.Runtime.dll.config
@@ -13,9 +13,11 @@ For more information read:
        <dllmap dll="python24" target="libpython2.4.so" os="!windows" />
        <dllmap dll="python25" target="libpython2.5.so" os="!windows" />
        <dllmap dll="python26" target="libpython2.6.so" os="!windows" />
+       <dllmap dll="python27" target="libpython2.7.so" os="!windows" />
        <dllmap dll="python23.dll" target="libpython2.3.so" os="!windows" />
        <dllmap dll="python24.dll" target="libpython2.4.so" os="!windows" />
        <dllmap dll="python25.dll" target="libpython2.5.so" os="!windows" />
        <dllmap dll="python26.dll" target="libpython2.6.so" os="!windows" />
+       <dllmap dll="python27.dll" target="libpython2.7.so" os="!windows" />
 </configuration>
 
-- 
1.7.5

>From 55c200a1e8b47bcd867adf263d1bd1e6aba97096 Mon Sep 17 00:00:00 2001
From: Philip Lorenz <loren...@gmail.com>
Date: Wed, 4 May 2011 11:43:28 +0200
Subject: [PATCH 3/6] Fix architecture detection. The old code did not
 determine the architecture correctly (uname -m returns
 iX86 for 32 bit platforms and x86_64 for 64 bit
 platforms - both containing the string 86).

---
 Makefile |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 1f6f01d..7de3255 100644
--- a/Makefile
+++ b/Makefile
@@ -16,13 +16,11 @@ UCS ?= $(shell $(PYTHON) -c "import sys; \
 SITEPACKAGES = $(shell $(PYTHON) -c "from distutils.sysconfig import 
get_python_lib; \
     print get_python_lib(plat_specific=1, standard_lib=0)")
 INSTALL=/usr/bin/install -m644
-# Contributed by VIKAS DHIMAN -  - Thanks, Vikas!
-ARCH_FULL = $(shell uname -m)
-ifneq (, $(findstring 86, $(ARCH_FULL)))
-       ARCH = x86
-else
-       ARCH = x64
-endif 
+
+# Determine host architecture if it was not specified by the user.
+ARCH ?= $(shell getconf LONG_BIT)
+CFLAGS_CLR_64 = -Ix64
+CFLAGS_CLR_32 = -Ix86
 
 ifeq ($(origin WINDIR), undefined)
     RUNNER = mono
@@ -81,7 +79,7 @@ Python.Runtime.dll: $(RUNTIME_CS)
 src/runtime/clrmodule.il: src/runtime/clrmodule.pp.il
 ifeq ($(origin WINDIR), undefined)
        cd "$(BASEDIR)/src/runtime";\
-       $(CPP) -C -P -x c++ -I $(ARCH) clrmodule.pp.il -o clrmodule.il
+       $(CPP) -C -P -x c++ $(CFLAGS_CLR_$(ARCH)) clrmodule.pp.il -o 
clrmodule.il
 else
        cd "$(BASEDIR)/src/runtime";\
        cp oldmodule.il clrmodule.il
-- 
1.7.5

>From 46e563f1b27754664f2bac3457046158cb96a5c1 Mon Sep 17 00:00:00 2001
From: Philip Lorenz <loren...@gmail.com>
Date: Wed, 4 May 2011 11:46:57 +0200
Subject: [PATCH 4/6] Rename clrmodule.il in the Makefile build to
 clrmodule_make.il. clrmodule.il is used by the Visual
 Studio project and therefore in the source
 distribution. However, this means that the Makefile
 will not create the correct clrmodule.il if a realclean
 is not run beforehands.

---
 Makefile |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 7de3255..212e54a 100644
--- a/Makefile
+++ b/Makefile
@@ -76,18 +76,18 @@ Python.Runtime.dll: $(RUNTIME_CS)
            $(RUNTIME_REF) /out:../../Python.Runtime.dll /recurse:*.cs
 
 # Contributed by VIKAS DHIMAN -  - Thanks, Vikas!
-src/runtime/clrmodule.il: src/runtime/clrmodule.pp.il
+src/runtime/clrmodule_make.il: src/runtime/clrmodule.pp.il
 ifeq ($(origin WINDIR), undefined)
        cd "$(BASEDIR)/src/runtime";\
-       $(CPP) -C -P -x c++ $(CFLAGS_CLR_$(ARCH)) clrmodule.pp.il -o 
clrmodule.il
+       $(CPP) -C -P -x c++ $(CFLAGS_CLR_$(ARCH)) clrmodule.pp.il -o 
clrmodule_make.il
 else
        cd "$(BASEDIR)/src/runtime";\
-       cp oldmodule.il clrmodule.il
+       cp oldmodule.il clrmodule_make.il
 endif
 
-clr.pyd: Python.Runtime.dll src/runtime/clrmodule.il
+clr.pyd: Python.Runtime.dll src/runtime/clrmodule_make.il
        $(ILASM) /nologo /dll /quiet /output=clr.pyd \
-           src/runtime/clrmodule.il
+           src/runtime/clrmodule_make.il
 
 
 clr.so: Python.Runtime.dll src/monoclr/clrmod.c src/monoclr/pynetclr.h \
@@ -109,6 +109,7 @@ Python.EmbeddingTest.dll: Python.Runtime.dll $(EMBED_CS)
 
 .PHONY=clean
 clean:
+       -rm src/runtime/clrmodule_make.il
        rm -f *.exe *.dll *.so *.pyd
        make -C src/monoclr clean
 
-- 
1.7.5

>From 63e008b4766f0057fce8998e213f26c13ffc3c19 Mon Sep 17 00:00:00 2001
From: Philip Lorenz <loren...@gmail.com>
Date: Wed, 4 May 2011 12:15:08 +0200
Subject: [PATCH 5/6] Pass ARCH to monoclr Makefile and change monoclr
 Makefile to support Mono >= 2.8. Additionally, -fPIC is
 added for x86_64 compiles and the Glib 2 CFLAGS and
 libraries are retrieved via pkg-config.

---
 Makefile             |    2 +-
 src/monoclr/Makefile |   27 ++++++++++++++++++++-------
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 212e54a..62001e6 100644
--- a/Makefile
+++ b/Makefile
@@ -179,7 +179,7 @@ asm:
            Python.Runtime.il
 
 monoclr:
-       make -C $(BASEDIR)/src/monoclr PYTHON=$(PYTHON)
+       make -C $(BASEDIR)/src/monoclr PYTHON=$(PYTHON) ARCH=$(ARCH)
 
 run: python.exe
        $(RUNNER) python.exe
diff --git a/src/monoclr/Makefile b/src/monoclr/Makefile
index 11b8c90..9b7f5c0 100755
--- a/src/monoclr/Makefile
+++ b/src/monoclr/Makefile
@@ -1,13 +1,13 @@
 # Author: Christian Heimes
 
-PYTHON = python
+PYTHON ?= python
 BASENAME = $(shell $(PYTHON) -c "import sys; print 'python%i.%i' % 
sys.version_info[:2]")
 GCC = gcc
 
 ifeq ($(origin WINDIR), undefined)
-    DLL_OR_SO = "-shared"
+    DLL_OR_SO = -shared
 else
-    DLL_OR_SO = "-dynamiclib"
+    DLL_OR_SO = -dynamiclib
 endif
 
 
@@ -16,11 +16,24 @@ PY_LIBS = $(shell $(PYTHON) -c "from distutils.sysconfig 
import get_config_vars;
 PY_CFLAGS = -I$(shell $(PYTHON) -c "from distutils.sysconfig import 
get_config_vars; \
     print get_config_vars('CFLAGS')[0] + ' -I' + 
get_config_vars('CONFINCLUDEPY')[0]")
 
-MONO_LIBS = $(shell pkg-config --libs mono)            # Was --libs mono
-MONO_CFLAGS = $(shell pkg-config --cflags mono)        # Was --cflags mono
+ARCH ?= $(shell getconf LONG_BIT)
 
-LIBS = $(MONO_LIBS) $(PY_LIBS)
-CFLAGS = $(MONO_CFLAGS) $(PY_CFLAGS)
+CFLAGS_32 =
+CFLAGS_64 = -fPIC
+
+MONO_LIBS = $(shell pkg-config --libs mono-2)
+MONO_CFLAGS = $(shell pkg-config --cflags mono-2)
+# Check if Mono >= 2.8 was found - if not fallback to old version
+ifeq ($(strip $(MONO_LIBS)),)
+       MONO_LIBS = $(shell pkg-config --libs mono)
+       MONO_CFLAGS = $(shell pkg-config --cflags mono)
+endif
+
+GLIB_LIBS = $(shell pkg-config --libs glib-2.0)
+GLIB_CFLAGS = $(shell pkg-config --cflags glib-2.0)
+
+LIBS = $(MONO_LIBS) $(PY_LIBS) $(GLIB_LIBS)
+CFLAGS = $(MONO_CFLAGS) $(PY_CFLAGS) $(GLIB_CFLAGS) $(CFLAGS_$(ARCH))
 
 all: clr$(BASENAME) $(BASENAME) clr.so
 
-- 
1.7.5

>From 7eafa503ff84b00c7a7a81dbf8fb8541ce534c8b Mon Sep 17 00:00:00 2001
From: Philip Lorenz <loren...@gmail.com>
Date: Wed, 4 May 2011 12:33:32 +0200
Subject: [PATCH 6/6] Support DESTDIR parameter when installing and install
 Python.Runtime.dll and Python.Runtime.dll.config along
 with the clr extension into site-packages.

---
 Makefile |    3 ++-
 setup.py |    2 ++
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 62001e6..0a56582 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ UCS ?= $(shell $(PYTHON) -c "import sys; \
 SITEPACKAGES = $(shell $(PYTHON) -c "from distutils.sysconfig import 
get_python_lib; \
     print get_python_lib(plat_specific=1, standard_lib=0)")
 INSTALL=/usr/bin/install -m644
+DESTDIR ?= /
 
 # Determine host architecture if it was not specified by the user.
 ARCH ?= $(shell getconf LONG_BIT)
@@ -185,7 +186,7 @@ run: python.exe
        $(RUNNER) python.exe
 
 install: all
-       $(PYTHON) setup.py install
+       $(PYTHON) setup.py install --root=$(DESTDIR)
 
 mkkey:
        $(SN) -k $(KEYFILE)
diff --git a/setup.py b/setup.py
index 0941be8..15f8d85 100755
--- a/setup.py
+++ b/setup.py
@@ -57,4 +57,6 @@ if os.name == "posix":
 setup(name="clr",
     ext_modules = extensions,
     scripts = ["src/monoclr/clrpython%s" % VERSION],
+    packages = [""],
+    package_data = { '': ["Python.Runtime.dll", "Python.Runtime.dll.config"] }
     )
\ No newline at end of file
-- 
1.7.5

_________________________________________________
Python.NET mailing list - PythonDotNet@python.org
http://mail.python.org/mailman/listinfo/pythondotnet

Reply via email to