summaryrefslogtreecommitdiff
path: root/sim/src/makehelp.py
blob: 74b5c59c969c0ae2d6e3f31cfb3460da3896acb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright 2006 Nanorex, Inc.  See LICENSE file for details.
import sys
import time
import os.path

if sys.platform == "darwin":
    extra_compile_args = [ "-O" ]
else:
    extra_compile_args = [ ]

DISTUTILS_FLAGS = None

if sys.platform != "win32":
    from distutils.core import setup
    from distutils.extension import Extension
    import Pyrex.Distutils

    class local_build_ext(Pyrex.Distutils.build_ext):
        def __init__(self, dist):
            Pyrex.Distutils.build_ext.__init__(self, dist)
            self.distn = dist
        def run(self):
            # Pieces of the distutils.command.build_ext.run() method
            global DISTUTILS_FLAGS
            from distutils.ccompiler import new_compiler
            from distutils.sysconfig import customize_compiler
            compiler = new_compiler(compiler=None,
                                    verbose=self.verbose,
                                    dry_run=self.dry_run,
                                    force=self.force)
            customize_compiler(compiler)
            DISTUTILS_FLAGS = (compiler.compiler_so +
                               self.distn.ext_modules[0].extra_compile_args)

    sys_argv = sys.argv
    sys.argv = ["setup.py", "build_ext"]
    setup(name = 'Simulator',
          ext_modules=[Extension("sim", [ ],
                                 extra_compile_args = extra_compile_args)],
          cmdclass = {'build_ext': local_build_ext})
    sys.argv = sys_argv

def hString(name, s, prefix=""):
    import string
    retval = "#define " + name + " \\\n\"" + prefix
    # replace double-quote with escaped-double-quote
    s = string.replace(s, "\"", "\\\"")
    # replace line terminations with end-of-last-line plus start-of-next-line
    s = string.replace(s, "\n", ("\\n\"\\\n\"") + prefix)
    return retval + s + "\\n\"\n"

#def cString(name, s, prefix=""):
#    import string
#    retval = "char " + name + "[] = \"\\\n" + prefix
#    # replace double-quote with escaped-double-quote
#    s = string.replace(s, "\"", "\\\"")
#    # replace line terminations with end-of-last-line plus start-of-next-line
#    s = string.replace(s, "\n", ("\\n\\\n") + prefix)
#    return retval + s + "\\n\";\n"

######################################

print hString("TRACE_PREFIX",
              "uname -a: " + sys.argv[3] + "\n",
              "# ")

print hString("TRACE_PREFIX_NON_DISTUTILS",
              "CFLAGS: " + sys.argv[1] + "\n" +
              "LDFLAGS: " + sys.argv[2] + "\n",
              "# ")

if DISTUTILS_FLAGS != None:
    distutils = " ".join(DISTUTILS_FLAGS)
else:
    distutils = "None"

print hString("TRACE_PREFIX_DISTUTILS",
              "Python " + sys.version.replace("\n", " ") + "\n" +
              distutils + "\n",
              "# ")