File: togl_setup.py

package info (click to toggle)
python-opengl 1.5.7-5.3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,192 kB
  • ctags: 3,971
  • sloc: ansic: 18,030; python: 8,909; tcl: 328; cpp: 211; makefile: 115; sh: 24
file content (165 lines) | stat: -rw-r--r-- 6,069 bytes parent folder | download
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""togl_setup.py

Compiles and installs Togl.

"""

# created 2000/08/01, Rene Liebscher <R.Liebscher@gmx.de>

import sys,os,string
from distutils.command.build_ext import build_ext
from distutils.dep_util import newer_group

# this is also a simple test if we need to build Togl
# without Tkinter it is not neccessary
import Tkinter
tk = Tkinter.Tk()

Togl = "Togl-1.5"
#Togl = "Togl-1.6"


# build togl
def togl_build(build_ext): # a simple function, not a class !!!
    import config

    # maybe we should use build as base, but we need an initialized
    # compiler object from build_ext
    # so let us get a instance of 'build' now
    build = build_ext.get_finalized_command ('build')

    extra_compile_args = [] # ["-Wall","-O"]
    extra_link_args = [] # ["-s"]
    # Name for the shared lib: (distutils will change it to Togl.{so|dll})
    output_name = "Togl"
    # where to put the built shared object (only for build process)
    output_dir = Togl + "-tk" + tk.getvar('tk_version')
    export_symbols = ["Togl_Init"]
    sources = [os.path.join("src",Togl,"togl.c")]

    if sys.platform == "win32":
        # VC++ 6.0 needs this, why togl doesn't use _WIN32?
        extra_compile_args.append("-DWIN32=1")

        tcl_lib = "tcl" + string.replace(tk.getvar('tcl_version'),".","")
        tk_lib = "tk" + string.replace(tk.getvar('tk_version'),".","")
        # we need the directory above tk_library
        tk_dir = os.path.normpath(os.path.join(tk.getvar('tk_library'),".."))
        
        include_dirs = [os.path.join("src",Togl)] + config.togl_include_dirs + \
                       [os.path.join(tk_dir,"..","include")]
        libraries = config.togl_libs + [tcl_lib,tk_lib]
        library_dirs = config.togl_lib_dirs + [tk_dir]
        runtime_library_dirs = None
    else:
        tcl_include_dir = os.path.join( "/usr/include",
					"tcl" + tk.getvar('tcl_version') )
        tk_include_dir = os.path.join( "/usr/include",
					"tcl" + tk.getvar('tcl_version') )
        tcl_lib_dir = os.path.normpath(os.path.join(tk.getvar('tcl_library'),".."))
        tk_lib_dir = os.path.normpath(os.path.join(tk.getvar('tk_library'),".."))
        tcl_lib = "tcl" + tk.getvar('tcl_version')
        tk_lib = "tk" + tk.getvar('tk_version')

        # Where to find tcl.h, tk.h, OpenGL/Mesa headers, etc:
        include_dirs = [os.path.join("src",Togl),
                        tcl_include_dir, tk_include_dir] + \
                        config.togl_include_dirs
        # Libraries to link with:
        libraries = config.togl_libs + [tcl_lib,tk_lib]
        # Where to find libtcl.a, libtk.a, OpenGL/Mesa libraries:
        library_dirs = config.togl_lib_dirs + [tcl_lib_dir, tk_lib_dir]
        runtime_library_dirs = None

    # rest of this function was inspired by build_ext.py , build_extensions() 
    
    if build_ext.inplace:
        # ignore build-base -- put the compiled extension into
        # the source tree along with pure Python modules
        pass
    else:
        output_dir = os.path.join (build.build_base, output_dir)

    if os.environ.has_key('CFLAGS'):
        extra_compile_args.extend(string.split(os.environ['CFLAGS']))

    # what is the name of the resulting file
    output_filename = build_ext.compiler.shared_object_filename(
                    basename=output_name,
                    output_dir=output_dir)

    if not (build_ext.force or newer_group(sources, output_filename, 'newer')):
        build_ext.announce ("skipping '%s' (up-to-date)" % output_name)  
    else:
        build_ext.announce ("building '%s'" % output_name)

        # compile source files        
        objects = build_ext.compiler.compile (sources,
                            output_dir=build_ext.build_temp,
                            #macros=macros,
                            include_dirs=include_dirs,
                            debug=build_ext.debug,
                            extra_postargs=extra_compile_args)

        # link all together
        build_ext.compiler.link_shared_object (
                objects, 
                output_filename,
                '', # <= output_dir
                libraries=libraries,
                library_dirs=library_dirs,
                runtime_library_dirs=runtime_library_dirs,
                extra_postargs=extra_link_args,
                export_symbols=export_symbols, 
                debug=build_ext.debug,
                build_temp=build_ext.build_temp)

    # building togl shared library

# togl_build    


from distutils.util import change_root
# install togl
#
# It is possibly to do this all in the build step, but then
# it is not included in a RPM distribution.
#
def togl_install(install,dry_run=0): # a simple function, not a class !!!
        
    outfiles = [] # we have to return all files we have installed

    # get path to Tk directory
    togl_dir = os.path.normpath(os.path.join(install.install_lib,"OpenGL","Tk", \
                                sys.platform + "-tk" + tk.getvar('tk_version')))
    install.mkpath(togl_dir)       
    # how are the built files called, and 
    # which names should have the installed files
    if sys.platform == "win32":
        togl = "Togl.dll"
    else:
        togl = "Togl.so"
    togl_src = os.path.join(install.build_base,
                            Togl + "-tk" + tk.getvar('tk_version'), togl)
    togl_dst = os.path.join(togl_dir,togl)
    # copy togl in tk directory
    if not dry_run:
        from types import TupleType
        out = install.copy_file(togl_src, togl_dst)
        if type(out) is TupleType:
            out = out[0] 
    else:
        out = togl_dst
    outfiles.append(out)

    # make package index for tcl/tk
    if not dry_run: 
        # only if real install
        install.announce("running 'pkg_mkIndex %s %s'" % (togl_dir, togl))
        if install.verbose:
            tk.tk.call('pkg_mkIndex','-verbose',togl_dir, togl)
        else:
            tk.tk.call('pkg_mkIndex',togl_dir, togl)
    outfiles.append(os.path.join(togl_dir,'pkgIndex.tcl'))

    return outfiles