1cflags{
2 '-std=c11', -- otherwise Modules/mathmodule.c tries to use C23 issubnormal
3 '-D NDEBUG',
4 '-I $outdir',
5 '-I $srcdir',
6 '-I $srcdir/Include',
7 '-I $srcdir/Include/internal',
8 '-I $srcdir/Modules/_hacl',
9 '-I $srcdir/Modules/_hacl/include',
10 '-I $srcdir/Modules/expat',
11 '-isystem $builddir/pkg/linux-headers/include',
12}
13
14build('cat', '$outdir/pyconfig.h', {
15 '$builddir/probe/HAVE_PREADV2',
16 '$builddir/probe/HAVE_PWRITEV2',
17 '$builddir/probe/HAVE_STATX',
18 '$dir/pyconfig.h',
19})
20
21pkg.deps = {
22 '$outdir/pyconfig.h',
23 'pkg/linux-headers/headers'
24}
25local libs = {}
26local modules = load 'modules.lua'
27
28if modules._ctypes then
29 cflags{'-isystem $builddir/pkg/libffi/include'}
30 table.insert(pkg.deps, 'pkg/libffi/headers')
31 table.insert(libs, 'libffi/libffi.a')
32end
33if modules._hashlib then
34 cflags{'-isystem $builddir/pkg/bearssl/include'}
35 table.insert(pkg.deps, 'pkg/bearssl/headers')
36 table.insert(libs, '$builddir/pkg/bearssl/libbearssl.a')
37end
38if modules._ssl then
39 cflags{'-isystem $builddir/pkg/libressl/include'}
40 table.insert(pkg.deps, 'pkg/libressl/headers')
41 table.insert(libs, {
42 '$builddir/pkg/libressl/libssl.a',
43 '$builddir/pkg/libressl/libcrypto.a',
44 })
45end
46if modules.pyexpat then
47 cflags{'-isystem $builddir/pkg/expat/include'}
48 table.insert(pkg.deps, 'pkg/expat/headers')
49 table.insert(libs, '$builddir/pkg/expat/libexpat.a.d')
50end
51if modules.zlib then
52 cflags{'-isystem $builddir/pkg/zlib/include'}
53 table.insert(pkg.deps, 'pkg/zlib/headers')
54 table.insert(libs, '$builddir/pkg/zlib/libz.a')
55end
56if modules._blake2 or modules._sha3 then
57 table.insert(libs, 'libhacl.a')
58end
59
60local srcs = {}
61sub('modules.ninja', function()
62 cflags{'-D Py_BUILD_CORE_BUILTIN'}
63
64 for _, mod in pairs(modules) do
65 for _, src in ipairs(mod) do
66 local obj = src..'.o'
67 if not srcs[obj] then
68 cc('Modules/'..src)
69 srcs[obj] = true
70 end
71 end
72 end
73end)
74srcs = table.keys(srcs)
75
76cflags{'-D Py_BUILD_CORE'}
77
78rule('makesetup', 'lua $dir/makesetup.lua $dir/modules.lua <$in >$out')
79build('makesetup', '$outdir/config.c', {'$srcdir/Modules/config.c.in', '|', '$dir/makesetup.lua', '$dir/modules.lua'})
80
81cc('Modules/getbuildinfo.c', nil, {
82 cflags=[[$cflags -D 'DATE="Oct 21 2026"' -D 'TIME="08:54:43"']]
83})
84cc('Modules/getpath.c', nil, {
85 cflags={
86 '$cflags',
87 [[-D 'PYTHONPATH=":plat-linux"']],
88 [[-D 'PREFIX="/"']],
89 [[-D 'EXEC_PREFIX="/"']],
90 [[-D 'VERSION="3.15"']],
91 [[-D 'VPATH=""']],
92 [[-D 'PLATLIBDIR="lib"']],
93 },
94})
95
96local platform = 'linux'
97local abiflags = ''
98for line in iterlines('pyconfig.h', 1) do
99 if line == '#define WITH_PYMALLOC 1' then
100 abiflags = abiflags..'m'
101 elseif line == '#define Py_DEBUG 1' then
102 abiflags = abiflags..'d'
103 end
104end
105
106cc('Python/getplatform.c', nil, {
107 cflags=string.format([[$cflags -D 'PLATFORM="%s"']], platform),
108})
109cc('Python/initconfig.c', nil, {
110 cflags=[[$cflags -D 'PLATLIBDIR="lib"']],
111})
112cc('Python/sysmodule.c', nil, {
113 cflags=string.format([[$cflags -D 'ABIFLAGS="%s"']], abiflags),
114})
115
116cc('Modules/_hacl/Lib_Memzero0.c', nil, {
117 cflags='$cflags -D _GNU_SOURCE',
118})
119lib('libhacl.a', [[
120 Modules/_hacl/(
121 Hacl_Hash_SHA3.c
122 Hacl_Hash_Blake2s.c
123 Hacl_Hash_Blake2b.c
124 Lib_Memzero0.c.o
125 )
126]])
127
128lib('libpython.a', {expand{'Modules/', srcs}, paths[[
129 Modules/(
130 getbuildinfo.c.o
131 getpath.c.o
132 main.c
133 gcmodule.c
134 )
135 Objects/(
136 abstract.c
137 boolobject.c
138 bytes_methods.c
139 bytearrayobject.c
140 bytesobject.c
141 call.c
142 capsule.c
143 cellobject.c
144 classobject.c
145 codeobject.c
146 complexobject.c
147 descrobject.c
148 enumobject.c
149 exceptions.c
150 genericaliasobject.c
151 genobject.c
152 fileobject.c
153 floatobject.c
154 frameobject.c
155 funcobject.c
156 interpolationobject.c
157 iterobject.c
158 lazyimportobject.c
159 listobject.c
160 longobject.c
161 dictobject.c
162 odictobject.c
163 memoryobject.c
164 methodobject.c
165 moduleobject.c
166 namespaceobject.c
167 object.c
168 obmalloc.c
169 picklebufobject.c
170 rangeobject.c
171 sentinelobject.c
172 setobject.c
173 sliceobject.c
174 structseq.c
175 templateobject.c
176 tupleobject.c
177 typeobject.c
178 typevarobject.c
179 unicode_format.c
180 unicode_formatter.c
181 unicode_writer.c
182 unicodectype.c
183 unicodeobject.c
184 unionobject.c
185 weakrefobject.c
186 )
187 Parser/(
188 token.c
189 pegen.c
190 pegen_errors.c
191 action_helpers.c
192 parser.c
193 string_parser.c
194 peg_api.c
195 lexer/(buffer.c lexer.c state.c)
196 tokenizer/(
197 file_tokenizer.c
198 readline_tokenizer.c
199 string_tokenizer.c
200 utf8_tokenizer.c
201 helpers.c
202 )
203 myreadline.c
204 )
205 Python/(
206 _contextvars.c
207 _warnings.c
208 Python-ast.c
209 Python-tokenize.c
210 asdl.c
211 assemble.c
212 ast.c
213 ast_preprocess.c
214 ast_unparse.c
215 bltinmodule.c
216 brc.c
217 ceval.c
218 codecs.c
219 codegen.c
220 compile.c
221 context.c
222 critical_section.c
223 crossinterp.c
224 dynamic_annotations.c
225 errors.c
226 flowgraph.c
227 frame.c
228 frozenmain.c
229 future.c
230 gc.c
231 gc_free_threading.c
232 gc_gil.c
233 getargs.c
234 getcompiler.c
235 getcopyright.c
236 getplatform.c.o
237 getversion.c
238 ceval_gil.c
239 hamt.c
240 hashtable.c
241 import.c
242 importdl.c
243 index_pool.c
244 initconfig.c.o
245 interpconfig.c
246 instrumentation.c
247 instruction_sequence.c
248 intrinsics.c
249 jit.c
250 jit_publish.c
251 legacy_tracing.c
252 lock.c
253 marshal.c
254 modsupport.c
255 mysnprintf.c
256 mystrtoul.c
257 object_stack.c
258 optimizer.c
259 optimizer_analysis.c
260 optimizer_symbols.c
261 parking_lot.c
262 pathconfig.c
263 preconfig.c
264 pyarena.c
265 pyctype.c
266 pyfpe.c
267 pyhash.c
268 pylifecycle.c
269 pymath.c
270 pystate.c
271 pystats.c
272 pythonrun.c
273 pytime.c
274 qsbr.c
275 bootstrap_hash.c
276 specialize.c
277 slots.c
278 slots_generated.c
279 stackrefs.c
280 structmember.c
281 symtable.c
282 sysmodule.c.o
283 thread.c
284 traceback.c
285 tracemalloc.c
286 uniqueid.c
287 getopt.c
288 pystrcmp.c
289 pystrtod.c
290 pystrhex.c
291 dtoa.c
292 fileutils.c
293 suggestions.c
294 perf_trampoline.c
295 perf_jit_trampoline.c
296 jit_unwind.c
297 remote_debugging.c
298 dynload_stub.c
299
300 frozen.c
301 )
302 $outdir/config.c
303]]})
304
305exe('python', {'Programs/python.c', 'libpython.a', libs})
306file('bin/python3', '755', '$outdir/python')
307sym('bin/python', 'python3')
308
309build('copy', '$outdir/python3.1', '$srcdir/Misc/python.man')
310man{'$outdir/python3.1'}
311sym('share/man/man1/python.1.gz', 'python3.1.gz')
312
313for f in iterlines('pylibs.txt') do
314 file('lib/python3.15/'..f, '644', '$srcdir/Lib/'..f)
315end
316file('lib/python3.15/_sysconfigdata_'..abiflags..'_'..platform..'_.py', '644', '$dir/lib/_sysconfigdata.py')
317file('lib/python3.15/Makefile', '644', '$dir/lib/Makefile')
318dir('lib/python3.15/lib-dynload', '755')
319
320fetch 'curl'