6 set_values("python3", "python2")
7 set_description("Enable/Disable Python")
11 set_extensions(".pyx")
12 on_load(function(target
)
13 import("lib.detect.find_tool")
14 local python
= get_config("liba-python"):split("::")
15 local python
= assert(find_tool(python
[#python
]), "python not found!")
16 local cython
= assert(find_tool("cython3") or find_tool("cython"), "cython not found!")
17 local suffix
= os
.iorunv(python
.program
, {
19 'import sysconfig;print(sysconfig.get_config_var("EXT_SUFFIX") or sysconfig.get_config_var("SO"))',
21 local prefix
= os
.iorunv(python
.program
, { "-c", 'import sysconfig;print(sysconfig.get_path("data"))' })
22 local platlib
= os
.iorunv(python
.program
, { "-c", 'import sysconfig;print(sysconfig.get_path("platlib"))' })
23 target
:set("cython", cython
.program
)
24 target
:set("kind", "shared")
25 target
:set("prefixname", "")
26 target
:set("extension", suffix
:trim())
27 target
:set("installdir", prefix
:trim())
28 target
:add("runenvs", "PYTHONPATH", target
:targetdir())
29 target
:set("platlib", path
.relative(platlib
:trim(), prefix
:trim()))
30 local python
= target
:pkg(get_config("liba-python"))
31 local links
= python
:get("links")
32 if type(links
) ~= "table" then
35 for _
, link
in ipairs(links
) do
36 if link
:startswith("py") then
37 python
:set("links", link
)
42 on_buildcmd_file(function(target
, batchcmds
, sourcefile
, opt
)
43 local sourcefile_c
= sourcefile
:replace(".pyx", ".c")
44 local objectfile
= target
:objectfile(sourcefile_c
)
45 table.insert(target
:objectfiles(), objectfile
)
47 batchcmds
:show_progress(opt
.progress
, "${color.build.object}compiling.cython %s", sourcefile
)
48 batchcmds
:vrunv(target
:get("cython"), { "--fast-fail", sourcefile
})
50 batchcmds
:show_progress(opt
.progress
, "${color.build.object}compiling.$(mode) %s", sourcefile_c
)
51 batchcmds
:compile(sourcefile_c
, objectfile
)
53 batchcmds
:add_depfiles(sourcefile
)
54 batchcmds
:set_depmtime(os
.mtime(objectfile
))
55 batchcmds
:set_depcache(target
:dependfile(objectfile
))
59 if has_config("liba-python") then
60 add_requires(get_config("liba-python"), { system
= true })
63 add_defines("A_EXPORTS")
64 add_files("src/liba.pyx")
65 on_install(function(target
)
66 local installdir
= target
:installdir()
68 print("installing %s to %s ..", target
:name(), installdir
)
69 installdir
= path
.join(installdir
, target
:get("platlib"))
71 os
.vcp(target
:targetfile(), installdir
)
72 for _
, installfile
in ipairs(target
:installfiles()) do
73 os
.vcp(installfile
, installdir
)
77 add_packages(get_config("liba-python"))
78 add_installfiles("liba.pyi")