-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.py
48 lines (35 loc) · 955 Bytes
/
build.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
import sys, os, glob
makefile = open("Makefile", "w")
makefile.write("""
PYVERSION=%(major_version)s.%(minor_version)s
PYPREFIX=%(prefix)s
INCLUDES=-I$(PYPREFIX)/include/python$(PYVERSION)
""" % {
'prefix': sys.prefix,
'major_version': sys.version_info[0],
'minor_version': sys.version_info[1],
})
all = []
for pyx in glob.glob("*.pyx"):
exe = os.path.splitext(pyx)[0]
all.append(exe)
if exe == 'pidigits_cython':
extra_flags = "-lgmp -I%(prefix)s/include -L%(prefix)s/lib" % {'prefix': sys.prefix}
else:
extra_flags = ""
makefile.write("""
%(exe)s.c: %(exe)s.pyx
\t@python -m cython -a --embed %(exe)s.pyx
%(exe)s: %(exe)s.c
\tgcc -O3 -o $@ $^ $(INCLUDES) -lpython$(PYVERSION) -lm %(extra_flags)s
""" % {
'exe': exe,
'extra_flags': extra_flags,
})
makefile.write("""
all: %(all)s
clean:
\t@rm -f *~ *.o *.so core core.* *.c %(all)s
""" % {'all': ' '.join(all)})
makefile.close()
os.system('make all')