From bb27f7d002416ff049534a4de4639a3c49848057 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 23 May 2003 16:48:46 +0000 Subject: [PATCH] Experimental script to assist in static linking wxWindows/wxPython to the python interpreter git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@20705 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/distrib/make_static_setup.py | 111 ++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 wxPython/distrib/make_static_setup.py diff --git a/wxPython/distrib/make_static_setup.py b/wxPython/distrib/make_static_setup.py new file mode 100644 index 0000000000..7ba0d9f7a9 --- /dev/null +++ b/wxPython/distrib/make_static_setup.py @@ -0,0 +1,111 @@ +#!/bin/env python +#--------------------------------------------------------------------------- +# This script generates a template that can be used in the Python +# build process (on posix systems) in order to staticly link the +# wxPython modules into the Python executable. The output of this +# script should be put into a file named Setup.local (or perhaps just +# concatenated to Setup) in the Modules dir of the Python source +# distribution, then just build Python like normal. +# +# You can use any of the command-line args that setup.py understands +# with this script too in order to control what modules are built and +# which compile options and such are used. +# +# This script must be run from the wxPython directory. +#--------------------------------------------------------------------------- + + +import sys, os, re + +# if you need to change some setup.py flags do it here before it is +# imported. Just append to sys.argv. +sys.argv.append("BUILD_GLCANVAS=0") +sys.argv.append("BUILD_OGL=0") +sys.argv.append("BUILD_DLLWIDGET=0") +#sys.argv.append("CORE_ONLY=1") + +import setup + + +def printitem(st): + if st: + print '\\\n\t', st, + + +def buildflags(items, flag, path=None): + st = '' + for item in items: + if path is not None and item[0] != '/': + item = os.path.join(path, item) + st += "%s%s " % (flag, item) + return st + + +def buildmacros(items): + st = '' + for item in items: + if len(item) == 1: + st += "-U%s " % item[0] + elif item[1] is None: + st += "-D%s " % item[0] + else: + st += "-D%s=%s " % item + return st + + +# Python's makesetup can't handle -D flags with = in them, so we need to workaround +def fixmacros(st): + defs = [] + pat = re.compile(r'-D([A-Za-z0-9_]*)=([A-Za-z0-9_]*)') + match = pat.search(st) + while match is not None: + name = match.group(1) + value = match.group(2) + defs.append("m_%s = -D%s=%s" % (name, name, value)) + st = st[:match.start()] + ("$(m_%s)" % name) + st[match.end():] + match = pat.search(st) + + return st, defs + + + +def main(): + cwd = os.getcwd() + + print """\ +# This file is autogenerated by %s and should be +# placed in the /Modules/Setup.local file before +# Python is built. + +*static* + +""" % sys.argv[0] + + for ext in setup.wxpExtensions: + eca = " ".join(ext.extra_compile_args) + macros = buildmacros(ext.define_macros) + + eca, defs = fixmacros(eca) + print "\n".join(defs) + macros, defs = fixmacros(macros) + print "\n".join(defs) + + print ext.name, + for s in ext.sources: + printitem(os.path.join(cwd, s)) + printitem(buildflags(ext.include_dirs, '-I', cwd)) + printitem(buildflags(ext.library_dirs, '-L')) + printitem(buildflags(ext.libraries, '-l')) + printitem(macros) + printitem(eca) + # filter out some options that makesetup can't handle, but it shouldn't hurt to remove these... + ela = filter(lambda x: x not in ['-pthread', '-rdynamic'], ext.extra_link_args) + printitem(" ".join(ela)) + + print; print; print + + + +if __name__ == "__main__": + main() +