96
# Windows specific issue:
97
# Having _DEBUG will cause Python.h to try to use python26_d.lib which is not included
98
# in Python installer and thus the build fails. See e.g.
99
# http://old.nabble.com/please-include-python26_d.lib-in-the-installer-td22737890.html
100
# http://old.nabble.com/MUD-Game-Programmming---Python-Modules-in-C%2B%2B-td25880983.html#a25882369
101
# for discussion on the topic. For some reason there is no issue about it in the
102
# Python bug tracker.
104
# From MSDN docs: "The compiler defines _DEBUG when you specify the /MTd or /MDd option."
105
# Thus, to be able to perform a debug test build, we need to either:
106
# * modify %PYTHON_HOME%\Include\pyconfig.h so python26.lib will be used instead of python26_d.lib
107
# * compile ourselves a debug version of Python
108
# * surround the #include <Python.h> in our source with #ifdef _DEBUG #undef _DEBUG #include <Python.h> style construct (see impl below)
109
# Of these options, the last one is the least intrusive and requires least hassle.
111
# cfile needs to be opened and have write permissions. This func will not close it.
112
def surroundPythonHIncludeWithGuards( cfile ) :
114
lines = cfile.readlines()
115
linenrOfPythonH = None
117
linenrOfPythonH = lines.index( '#include <Python.h>\n' )
118
except ValueError : return
120
if ( lines[ linenrOfPythonH - 2 ] == "# undef _DEBUG\n" ) : return
123
"#if defined( _DEBUG_WAS_DEFINED )\n",
128
for line in post : lines.insert( linenrOfPythonH + 1, line )
131
"#if defined( _DEBUG )\n",
132
"# define _DEBUG_WAS_DEFINED\n",
136
for line in pre : lines.insert( linenrOfPythonH, line )
140
cfile.writelines( lines )
96
142
if __name__ == '__main__' :
97
143
print 'Run tests using command "scons test".'