/
setup.py
130 lines (112 loc) · 3.49 KB
/
setup.py
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
import sys
import os
import pdb
import shutil
import os.path
from distutils.command.clean import clean as _clean
from distutils.core import setup, Extension
from distutils import sysconfig
##################################################################
def customize_compiler2(compiler):
(cc, cxx, opt, cflags, ccshared, ldshared, so_ext) = \
sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
'CCSHARED', 'LDSHARED', 'SO')
if 0:
print "cc=", cc
print "cxx=", cxx
print "opt=", opt
print "cflags=", cflags
print "ccshared=", ccshared
cflags = cflags.replace("-DNDEBUG", "")
cflags = cflags.replace("-O2", "")
cpp = cc + " -E"
cc_cmd = cc + ' ' + cflags
compiler.set_executables(
preprocessor=cpp,
compiler=cc_cmd,
compiler_so=cc_cmd + ' ' + ccshared,
compiler_cxx=cxx,
linker_so=ldshared,
linker_exe=cc)
compiler.shared_lib_extension = so_ext
return
idx = None
for i, arg in enumerate(sys.argv):
if arg == "-debug":
idx = i
if idx:
sys.argv.pop(idx)
d = sysconfig.__dict__
d['customize_compiler'] = customize_compiler2
##################################################################
##
## the main module - escape
##
##################################################################
escape_module = Extension('escape',
sources = ['escapemodule.c'])
mlist = [escape_module]
##################################################################
##
## benchark support - most folks won't need this
##
##################################################################
idx = None
for i, arg in enumerate(sys.argv):
if arg == "-bmark":
idx = i
if idx:
sys.argv.pop(idx)
slist = ["bmarkmodule.c", "bmark_scan.c"]
obj = Extension("bmark", sources=slist)
mlist.append(obj)
# does distutils have a way to run flex?
cmd = "flex -f -s -B -L -obmark_scan.c -Pbmark bmark_scan.lex"
print "Running flex command"
print cmd
c = os.system(cmd)
if c != 0:
print "Flex return non-zero status. Stopping."
sys.exit(-1)
##################################################################
##
## custom clean func
##
##################################################################
class clean(_clean):
"""Custom clean routine to clean pyc files"""
def run(self):
_clean.run(self)
if os.path.exists("build"):
print "Removing build dir"
shutil.rmtree("build")
for f in os.listdir("."):
if f.endswith(".pyc") \
or f.endswith("~") \
or f.endswith(".s") \
or f.endswith(".o") \
or f in ("a.out", "pytoken.tar.gz"):
os.unlink(f)
for f in ["parser.out", "parsetab.py"]:
try:
os.unlink(f)
except OSError:
pass
return
pass
##################################################################
##
## toplevel
##
##################################################################
## how can I force setup to turn off -O ??
##
setup(name = 'pytoken',
version = '1.01',
description = 'Generates scanners for python.',
author = 'Ram Bhamidipaty',
author_email = 'rambham@gmail.com',
url = 'http://code.google.com/p/pytoken/',
ext_modules = mlist,
py_modules = ['pytoken', 'pytoken_ply_lex'],
cmdclass = {"clean" : clean} )