build_tkinter.py 2.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
"""Script to compile the dependencies of _tkinter

Copyright (c) 2007 by Christian Heimes <christian@cheimes.de>

Licensed to PSF under a Contributor Agreement.
"""

import os
import sys

here = os.path.abspath(os.path.dirname(__file__))
par = os.path.pardir

14 15 16
TCL = "tcl8.6.1"
TK = "tk8.6.1"
TIX = "tix-8.4.3.3"
17

18
ROOT = os.path.abspath(os.path.join(here, par, par))
19
NMAKE = ('nmake /nologo /f %s %s %s')
20 21

def nmake(makefile, command="", **kw):
22
    defines = ' '.join(k+'='+str(v) for k, v in kw.items())
23 24
    cmd = NMAKE % (makefile, defines, command)
    print("\n\n"+cmd+"\n")
25 26 27 28 29 30
    if os.system(cmd) != 0:
        raise RuntimeError(cmd)

def build(platform, clean):
    if platform == "Win32":
        dest = os.path.join(ROOT, "tcltk")
31
        machine = "IX86"
32
    elif platform == "AMD64":
33
        dest = os.path.join(ROOT, "tcltk64")
34
        machine = "AMD64"
35 36 37 38 39
    else:
        raise ValueError(platform)

    # TCL
    tcldir = os.path.join(ROOT, TCL)
40
    if 1:
41 42
        os.chdir(os.path.join(tcldir, "win"))
        if clean:
43
            nmake("makefile.vc", "clean")
44 45
        nmake("makefile.vc", MACHINE=machine)
        nmake("makefile.vc", "install", INSTALLDIR=dest, MACHINE=machine)
46 47

    # TK
48
    if 1:
49 50
        os.chdir(os.path.join(ROOT, TK, "win"))
        if clean:
51
            nmake("makefile.vc", "clean", DEBUG=0, TCLDIR=tcldir)
52 53
        nmake("makefile.vc", DEBUG=0, MACHINE=machine, TCLDIR=tcldir)
        nmake("makefile.vc", "install", DEBUG=0, INSTALLDIR=dest, MACHINE=machine, TCLDIR=tcldir)
54 55

    # TIX
56
    if 1:
57
        # python9.mak is available at http://svn.python.org
58 59
        os.chdir(os.path.join(ROOT, TIX, "win"))
        if clean:
60 61
            nmake("python.mak", "clean")
        nmake("python.mak", MACHINE=machine, INSTALL_DIR=dest)
62
        nmake("python.mak", "install", MACHINE=machine, INSTALL_DIR=dest)
63 64

def main():
65 66
    if len(sys.argv) < 2 or sys.argv[1] not in ("Win32", "AMD64"):
        print("%s Win32|AMD64" % sys.argv[0])
67 68 69 70 71 72 73 74 75 76 77 78
        sys.exit(1)

    if "-c" in sys.argv:
        clean = True
    else:
        clean = False

    build(sys.argv[1], clean)


if __name__ == '__main__':
    main()