~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/translator/goal/win32/gc_patch_windows.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# patches for the Boehm GC for PyPy under Windows
 
2
 
 
3
"""
 
4
How to build a pypy compatible version of the Boehm collector
 
5
for Windows and Visual Studio .net 2003.
 
6
 
 
7
First of all, download the official Boehm collector suite
 
8
from http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc.tar.gz
 
9
At the time of writing (2005-10-06) this contains version gc6.5 .
 
10
 
 
11
Unpack this folder somewhere, for instance to "d:\tmp".
 
12
Change to this folder using
 
13
 
 
14
d:
 
15
cd \tmp\gc6.5
 
16
 
 
17
Then copy the file NT_THREADS_MAKEFILE to Makefile:
 
18
 
 
19
copy NT_THREADS_MAKEFILE Makefile
 
20
 
 
21
This file is the general-purpose gc dll makefile. For some internal
 
22
reasons, this file's defaults are bad for PyPy. The early initialisation
 
23
in DllMain() inhibits the changes necessary for PyPy. Use this script to
 
24
do a patch: (assuming that you have d:\pypy\dist\pypy\translator\goal)
 
25
 
 
26
python d:\pypy\dist\pypy\translator\goal\win32\gc_patch_windows.py
 
27
 
 
28
Now, your makefile is patched a little bit. In particular,
 
29
 
 
30
ALL_INTERIOR_POINTERS   is now undefined, which PyPy wants to have
 
31
NO_GETENV               is specified, since we don't want dependencies
 
32
 
 
33
and the name of the .lib and .dll files is changed to gc_pypy.???
 
34
 
 
35
Now you need to build your gc, either as a debug or as a release
 
36
build. First of all, make sure that you have your environment prepared.
 
37
Please note that you will need to use Microsoft's cmd, as cygwin bash
 
38
doesn't correctly handle the batch file in the next step.
 
39
 
 
40
With my setup, I have to do
 
41
 
 
42
"e:\Programme\Microsoft Visual Studio .NET 2003\Vc7\bin\vcvars32.bat"
 
43
 
 
44
After that, you can either build a release or a debug gc. 
 
45
 
 
46
After a successful build, you need to enable gc_pypy.dll for your compiler.
 
47
There are many ways to install this. The following recommendation just
 
48
works without changing your environment variables. I think this is the
 
49
easiest way possible, but this is a matter of taste. What I did is:
 
50
 
 
51
nmake CFG="gc - Win32 Release"
 
52
 
 
53
After the build, you will find a gc_pypy.dll file in the Release folder.
 
54
Copy this file to c:\windows\system32 or any other folder that is always
 
55
in your PATH variable.
 
56
 
 
57
Also, copy Release\gc_pypy.lib to (in my case)
 
58
"e:\Programme\Microsoft Visual Studio .NET 2003\Vc7\lib";
 
59
 
 
60
finally, copy d:\tmp\gc6.5\include to
 
61
"e:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include"
 
62
and rename this folder to "gc", so that "gc/gc.h" is valid.
 
63
 
 
64
That's all, folks!
 
65
 
 
66
In case of a debug build, replace "Release" by "Debug", and also copy
 
67
gc_pypy.pdb to your lib folder. This allows you to use source-level
 
68
debugging. Please note: If you want to both build the default gc.dll
 
69
and gc_pypy.dll, please delete the Debug resp. Release folders in
 
70
between. The generated .sbr files are in the way.
 
71
 
 
72
Please use the above recipe and report any bugs to me.
 
73
In case of trouble, I also can provide you with pre-built dlls.
 
74
Note: We also could have solved this by including the gc source
 
75
into the PyPy build. This may or may not become necessary if something
 
76
changes dramatically, again. As long as this is not needed, I prefer
 
77
this simple solution.
 
78
 
 
79
Summary transcript of the steps involved: (please adjust paths)
 
80
 
 
81
d:
 
82
cd \tmp\gc6.5
 
83
copy NT_THREADS_MAKEFILE Makefile
 
84
python d:\pypy\dist\pypy\translator\goal\win32\gc_patch_windows.py
 
85
"e:\Programme\Microsoft Visual Studio .NET 2003\Vc7\bin\vcvars32.bat"
 
86
nmake CFG="gc - Win32 Release"
 
87
copy Release\gc_pypy.dll c:\windows\system32
 
88
copy Release\gc_pypy.lib "e:\Programme\Microsoft Visual Studio .NET 2003\Vc7\lib"
 
89
mkdir "e:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\gc"
 
90
copy include "e:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\gc"
 
91
 
 
92
cheers - chris
 
93
"""
 
94
 
 
95
REPLACE = {
 
96
    '"ALL_INTERIOR_POINTERS"': '"NO_GETENV"',
 
97
    }
 
98
 
 
99
for ending in "lib exp map pdb bsc dll pch".split():
 
100
    REPLACE["gc.%s" % ending] = "gc_pypy.%s" % ending
 
101
 
 
102
def change_settings(src):
 
103
    for old, new in REPLACE.items():
 
104
        newsrc = src.replace(old, new)
 
105
        if newsrc == src:
 
106
            raise ValueError, "this makefile does not contain %s" % old
 
107
        src = newsrc
 
108
    return src
 
109
 
 
110
def find_file():
 
111
    import os
 
112
    for name in os.listdir("."):
 
113
        if name.lower() == 'makefile':
 
114
            return name
 
115
    else:
 
116
        raise ValueError, 'Makefile not found'
 
117
 
 
118
try:
 
119
    name = find_file()
 
120
    source = change_settings(file(name).read())
 
121
    file(name, "w").write(source)
 
122
    print "Updated your Makefile to fit PyPy's needs. Your lib will be named gc_pypy.dll"
 
123
    print "and gc_pypy.lib. Please put them into appropriate places, see __doc__."
 
124
except:
 
125
    print __doc__
 
126
    raise