1cflags{
2 '-D NDEBUG',
3 '-I $dir',
4 '-I $srcdir/Include',
5 '-I $srcdir/Include/internal',
6 '-isystem $builddir/pkg/linux-headers/include',
7}
8
9pkg.deps = {'pkg/linux-headers/headers'}
10local libs = {}
11local modules = load 'modules.lua'
12
13if modules._ctypes then
14 cflags{'-isystem $builddir/pkg/libffi/include'}
15 table.insert(pkg.deps, 'pkg/libffi/headers')
16 table.insert(libs, 'libffi/libffi.a')
17end
18if modules._hashlib then
19 cflags{'-isystem $builddir/pkg/bearssl/include'}
20 table.insert(pkg.deps, 'pkg/bearssl/headers')
21 table.insert(libs, 'bearssl/libbearssl.a')
22end
23if modules._ssl then
24 cflags{'-isystem $builddir/pkg/libressl/include'}
25 table.insert(pkg.deps, 'pkg/libressl/headers')
26 table.insert(libs, {
27 'libressl/libssl.a',
28 'libressl/libcrypto.a',
29 })
30end
31if modules.pyexpat then
32 cflags{'-isystem $builddir/pkg/expat/include'}
33 table.insert(pkg.deps, 'pkg/expat/headers')
34 table.insert(libs, 'expat/libexpat.a.d')
35end
36if modules.zlib then
37 cflags{'-isystem $builddir/pkg/zlib/include'}
38 table.insert(pkg.deps, 'pkg/zlib/headers')
39 table.insert(libs, 'zlib/libz.a')
40end
41
42local srcs = {}
43sub('modules.ninja', function()
44 cflags{'-D Py_BUILD_CORE_BUILTIN'}
45
46 for _, mod in pairs(modules) do
47 for _, src in ipairs(mod) do
48 local obj = src..'.o'
49 if not srcs[obj] then
50 cc('Modules/'..src)
51 srcs[obj] = true
52 end
53 end
54 end
55end)
56srcs = table.keys(srcs)
57
58cflags{'-D Py_BUILD_CORE'}
59
60rule('makesetup', 'lua $dir/makesetup.lua $dir/modules.lua <$in >$out')
61build('makesetup', '$outdir/config.c', {'$srcdir/Modules/config.c.in', '|', '$dir/makesetup.lua', '$dir/modules.lua'})
62
63cc('Modules/getbuildinfo.c', nil, {
64 cflags=[[$cflags -D 'DATE="Oct 4 2021"' -D 'TIME="18:40:47"']]
65})
66cc('Modules/getpath.c', nil, {
67 cflags={
68 '$cflags',
69 [[-D 'PYTHONPATH=":plat-linux"']],
70 [[-D 'PREFIX="/"']],
71 [[-D 'EXEC_PREFIX="/"']],
72 [[-D 'VERSION="3.10"']],
73 [[-D 'VPATH=""']],
74 },
75})
76
77local platform = 'linux'
78local abiflags = ''
79for line in iterlines('pyconfig.h', 1) do
80 if line == '#define WITH_PYMALLOC 1' then
81 abiflags = abiflags..'m'
82 elseif line == '#define Py_DEBUG 1' then
83 abiflags = abiflags..'d'
84 end
85end
86
87cc('Python/getplatform.c', nil, {
88 cflags=string.format([[$cflags -D 'PLATFORM="%s"']], platform),
89})
90cc('Python/initconfig.c', nil, {
91 cflags=[[$cflags -D 'PLATLIBDIR="lib"']],
92})
93cc('Python/sysmodule.c', nil, {
94 cflags=string.format([[$cflags -D 'ABIFLAGS="%s"']], abiflags),
95})
96
97lib('libpython.a', {expand{'Modules/', srcs}, paths[[
98 Modules/(
99 getbuildinfo.c.o
100 getpath.c.o
101 main.c
102 gcmodule.c
103 )
104 Objects/(
105 abstract.c
106 accu.c
107 boolobject.c
108 bytes_methods.c
109 bytearrayobject.c
110 bytesobject.c
111 call.c
112 capsule.c
113 cellobject.c
114 classobject.c
115 codeobject.c
116 complexobject.c
117 descrobject.c
118 enumobject.c
119 exceptions.c
120 genericaliasobject.c
121 genobject.c
122 fileobject.c
123 floatobject.c
124 frameobject.c
125 funcobject.c
126 interpreteridobject.c
127 iterobject.c
128 listobject.c
129 longobject.c
130 dictobject.c
131 odictobject.c
132 memoryobject.c
133 methodobject.c
134 moduleobject.c
135 namespaceobject.c
136 object.c
137 obmalloc.c
138 picklebufobject.c
139 rangeobject.c
140 setobject.c
141 sliceobject.c
142 structseq.c
143 tupleobject.c
144 typeobject.c
145 unicodeobject.c
146 unicodectype.c
147 unionobject.c
148 weakrefobject.c
149 )
150 Parser/(
151 token.c
152 pegen.c
153 parser.c
154 string_parser.c
155 peg_api.c
156 myreadline.c
157 tokenizer.c
158 )
159 Python/(
160 _warnings.c
161 Python-ast.c
162 asdl.c
163 ast.c
164 ast_opt.c
165 ast_unparse.c
166 bltinmodule.c
167 ceval.c
168 codecs.c
169 compile.c
170 context.c
171 errors.c
172 frozenmain.c
173 future.c
174 getargs.c
175 getcompiler.c
176 getcopyright.c
177 getplatform.c.o
178 getversion.c
179 hamt.c
180 hashtable.c
181 import.c
182 importdl.c
183 initconfig.c.o
184 marshal.c
185 modsupport.c
186 mysnprintf.c
187 mystrtoul.c
188 pathconfig.c
189 preconfig.c
190 pyarena.c
191 pyctype.c
192 pyfpe.c
193 pyhash.c
194 pylifecycle.c
195 pymath.c
196 pystate.c
197 pythonrun.c
198 pytime.c
199 bootstrap_hash.c
200 structmember.c
201 symtable.c
202 sysmodule.c.o
203 thread.c
204 traceback.c
205 getopt.c
206 pystrcmp.c
207 pystrtod.c
208 pystrhex.c
209 dtoa.c
210 formatter_unicode.c
211 fileutils.c
212 suggestions.c
213 dynload_stub.c
214 frozen.c
215 )
216 $outdir/config.c
217]]})
218
219exe('python', {'Programs/python.c', 'libpython.a', expand{'$builddir/pkg/', libs}})
220file('bin/python3', '755', '$outdir/python')
221sym('bin/python', 'python3')
222
223build('copy', '$outdir/python3.1', '$srcdir/Misc/python.man')
224man{'$outdir/python3.1'}
225sym('share/man/man1/python.1.gz', 'python3.1.gz')
226
227for f in iterlines('pylibs.txt') do
228 file('lib/python3.10/'..f, '644', '$srcdir/Lib/'..f)
229end
230file('lib/python3.10/_sysconfigdata_'..abiflags..'_'..platform..'_.py', '644', '$dir/lib/_sysconfigdata.py')
231file('lib/python3.10/Makefile', '644', '$dir/lib/Makefile')
232dir('lib/python3.10/lib-dynload', '755')
233
234fetch 'curl'