File: c.py

package info (click to toggle)
felix 1.1.1-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,992 kB
  • ctags: 1,178
  • sloc: python: 7,260; makefile: 408; sh: 58
file content (83 lines) | stat: -rw-r--r-- 2,366 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
#line 123 "interscript/src/compilers.ipk"
import os
import sys
import string
import interscript.compilers.cconfig

class python_module:
  def __init__(self,**kwds):
    self.config = interscript.compilers.cconfig.config()
    self.config.append_dict(kwds)

  def configure(self,**kwds):
    self.config.append_dict(kwds)

  def compile(self,filename, **kwds):
    config = self.config.copy()
    config.append_dict(kwds)

    base = string.join(string.split(filename,'.')[:-1],'.')
    obj = base+'.o'
    cc = 'gcc -g -O2 -fpic -fPIC -pedantic '
    inc = '-I' + sys.prefix + '/include/python1.5 '
    if sys.prefix != sys.exec_prefix:
      inc = inc + '-I' + sys.exec_prefix + '/include/python1.5 '
    cstr = str(config)+' '
    arg = cc + cstr +  inc + '-c '+filename + ' -o '+ obj
    print 'system',repr(arg)
    os.system(arg)
    return obj

  def link(self,modname, filenames, **kwds):
    config = self.config.copy()
    config.append_dict(kwds)

    dll = modname +'.so'
    cc ='gcc -shared -Xlinker -export-dynamic '
    cstr = str(config) + ' '
    lib = '-L' + sys.exec_prefix + '/lib/python1.5 '
    files = string.join(filenames) + ' '
    arg = cc + cstr + lib + files + '-o ' + dll

    print 'system',repr(arg)
    os.system(arg)
    return dll

class application:
  def __init__(self,**kwds):
    self.config = interscript.compilers.cconfig.config()
    self.config.append_dict(kwds)

  def configure(self,**kwds):
    self.config.append_dict(kwds)

  def compile(self,filename, **kwds):
    config = self.config.copy()
    config.append_dict(kwds)

    base = string.join(string.split(filename,'.')[:-1],'.')
    obj = base+'.o'
    cc ='gcc -g -O2 -fpic -fPIC -pedantic '
    inc = '-I' + sys.prefix + '/include/python1.5 '
    if sys.prefix != sys.exec_prefix:
      inc = inc + '-I' + sys.exec_prefix + '/include/python1.5 '
    cstr = str(config)+' '
    arg = cc + cstr +  inc + '-c '+filename + ' -o '+ obj
    print 'system',repr(arg)
    os.system(arg)
    return obj

  def link(self,appname, filenames, **kwds):
    config = self.config.copy()
    config.append_dict(kwds)

    cc ='gcc '
    cstr = str(config) + ' '
    lib = '-L' + sys.exec_prefix + '/lib/python1.5 '
    files = string.join(filenames) + ' '
    arg = cc + cstr + lib + files + '-o ' + appname

    print 'system',repr(arg)
    os.system(arg)
    return appname