xmake.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package("python2")
  2. set_homepage("https://www.python.org/")
  3. set_description("The python programming language.")
  4. if is_host("windows") then
  5. if os.arch() == "x64" then
  6. add_urls("https://cdn.jsdelivr.net/gh/xmake-mirror/python-releases@$(version)/python-$(version).win64.tar.gz",
  7. "https://github.com/xmake-mirror/python-releases/raw/$(version)/python-$(version).win64.tar.gz",
  8. "https://gitlab.com/xmake-mirror/python-releases/-/raw/$(version)/python-$(version).win64.tar.gz")
  9. add_versions("2.7.15", "c81c4604b4176ff26be8d37cf48a2582e71a5e8f475b531c2e5d032a39511acb")
  10. else
  11. add_urls("https://cdn.jsdelivr.net/gh/xmake-mirror/python-releases@$(version)/python-$(version).win32.tar.gz",
  12. "https://github.com/xmake-mirror/python-releases/raw/$(version)/python-$(version).win32.tar.gz",
  13. "https://gitlab.com/xmake-mirror/python-releases/-/raw/$(version)/python-$(version).win32.tar.gz")
  14. add_versions("2.7.15", "4a7be2b440b74776662daaeb6bb6c5574bb6d0f4ddc0ad03ce63571ab2353303")
  15. end
  16. else
  17. set_urls("https://www.python.org/ftp/python/$(version)/Python-$(version).tgz",
  18. "https://github.com/xmake-mirror/cpython/releases/download/v$(version)/Python-$(version).tgz")
  19. add_versions("2.7.15", "18617d1f15a380a919d517630a9cd85ce17ea602f9bbdc58ddc672df4b0239db")
  20. end
  21. if is_host("macosx", "linux") then
  22. add_deps("openssl", {host = true})
  23. end
  24. if is_host("linux") then
  25. add_syslinks("util", "pthread", "dl")
  26. end
  27. add_resources("2.7.15", "setuptools", "https://files.pythonhosted.org/packages/c2/f7/c7b501b783e5a74cf1768bc174ee4fb0a8a6ee5af6afa92274ff964703e0/setuptools-40.8.0.zip", "6e4eec90337e849ade7103723b9a99631c1f0d19990d6e8412dc42f5ae8b304d")
  28. add_resources("2.7.15", "pip", "https://files.pythonhosted.org/packages/36/fa/51ca4d57392e2f69397cd6e5af23da2a8d37884a605f9e3f2d3bfdc48397/pip-19.0.3.tar.gz", "6e6f197a1abfb45118dbb878b5c859a0edbdd33fd250100bc015b67fded4b9f2")
  29. add_resources("2.7.15", "wheel", "https://files.pythonhosted.org/packages/b7/cf/1ea0f5b3ce55cacde1e84cdde6cee1ebaff51bd9a3e6c7ba4082199af6f6/wheel-0.33.1.tar.gz", "66a8fd76f28977bb664b098372daef2b27f60dc4d1688cfab7b37a09448f0e9d")
  30. on_load(function (package)
  31. -- add PATH
  32. package:addenv("PATH", "bin")
  33. -- set includedirs
  34. local version = package:version()
  35. if package:is_plat("windows") then
  36. package:add("includedirs", "include")
  37. else
  38. package:add("includedirs", ("include/python%d.%d"):format(version:major(), version:minor()))
  39. end
  40. -- define install_resources()
  41. package:data_set("install_resources", function()
  42. -- imports
  43. import("lib.detect.find_file")
  44. -- set python environments
  45. local envs = {}
  46. envs.PYTHONPATH = package:installdir("lib", "python" .. version:major() .. "." .. version:minor(), "site-packages")
  47. package:addenv("PYTHONPATH", envs.PYTHONPATH)
  48. -- install resources
  49. local python = path.join(package:installdir("bin"), "python" .. (is_host("windows") and ".exe" or ""))
  50. for _, name in ipairs({"setuptools", "pip", "wheel"}) do
  51. local resourcedir = assert(package:resourcedir(name), "resource(%s): not found!", name)
  52. local setupfile = assert(find_file("setup.py", path.join(resourcedir, "*")), "resource(%s): setup.py not found!", name)
  53. local oldir = os.cd(path.directory(setupfile))
  54. os.vrunv(python, {"setup.py", "install", "--prefix=" .. package:installdir()}, {envs = envs})
  55. os.cd(oldir)
  56. end
  57. end)
  58. end)
  59. on_install("@windows", "@msys", "@cygwin", function (package)
  60. os.cp("python.exe", path.join(package:installdir("bin"), "python2.exe"))
  61. os.mv("*.exe", package:installdir("bin"))
  62. os.mv("*.dll", package:installdir("bin"))
  63. os.mv("libs/*", package:installdir("lib"))
  64. os.cp("*", package:installdir())
  65. package:data("install_resources")()
  66. end)
  67. on_install("@macosx", "@linux", function (package)
  68. -- init configs
  69. local configs = {"--enable-ipv6", "--without-ensurepip"}
  70. table.insert(configs, "--datadir=" .. package:installdir("share"))
  71. table.insert(configs, "--datarootdir=" .. package:installdir("share"))
  72. -- add flags
  73. local cflags = {}
  74. local ldflags = {}
  75. if package:is_plat("macosx") then
  76. local xcode_dir = get_config("xcode")
  77. local xcode_sdkver = get_config("xcode_sdkver") or get_config("xcode_sdkver_macosx")
  78. if xcode_dir and xcode_sdkver then
  79. -- help Python's build system (setuptools/pip) to build things on SDK-based systems
  80. -- the setup.py looks at "-isysroot" to get the sysroot (and not at --sysroot)
  81. local xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk"
  82. table.insert(cflags, "-isysroot " .. xcode_sdkdir)
  83. table.insert(cflags, "-I" .. path.join(xcode_sdkdir, "/usr/include"))
  84. table.insert(ldflags, "-isysroot " .. xcode_sdkdir)
  85. -- for the Xlib.h, Python needs this header dir with the system Tk
  86. -- yep, this needs the absolute path where zlib needed a path relative to the SDK.
  87. table.insert(cflags, "-I" .. path.join(xcode_sdkdir, "/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"))
  88. end
  89. -- avoid linking to libgcc https://mail.python.org/pipermail/python-dev/2012-February/116205.html
  90. local target_minver = get_config("target_minver") or get_config("target_minver_macosx")
  91. if target_minver then
  92. table.insert(configs, "MACOSX_DEPLOYMENT_TARGET=" .. target_minver)
  93. end
  94. end
  95. if #cflags > 0 then
  96. table.insert(configs, "CFLAGS=" .. table.concat(cflags, " "))
  97. end
  98. if #ldflags > 0 then
  99. table.insert(configs, "LDFLAGS=" .. table.concat(ldflags, " "))
  100. end
  101. -- add openssl libs path for detecting
  102. io.gsub("setup.py", "/usr/local/ssl", package:dep("openssl"):installdir())
  103. -- allow python modules to use ctypes.find_library to find xmake's stuff
  104. if is_host("macosx") then
  105. io.gsub("Lib/ctypes/macholib/dyld.py", "DEFAULT_LIBRARY_FALLBACK = %[", format("DEFAULT_LIBRARY_FALLBACK = [ '%s/lib',", package:installdir()))
  106. end
  107. -- unset these so that installing pip and setuptools puts them where we want
  108. -- and not into some other Python the user has installed.
  109. import("package.tools.autoconf").configure(package, configs, {envs = {PYTHONHOME = "", PYTHONPATH = ""}})
  110. os.vrunv("make", {"install", "-j4", "PYTHONAPPSDIR=" .. package:installdir()})
  111. package:data("install_resources")()
  112. end)
  113. on_test(function (package)
  114. os.vrun("python2 --version")
  115. os.vrun("python2 -c \"import pip\"")
  116. os.vrun("python2 -c \"import setuptools\"")
  117. os.vrun("python2 -c \"import wheel\"")
  118. if package:kind() ~= "binary" then
  119. assert(package:has_cfuncs("PyModule_New", {includes = "Python.h"}))
  120. end
  121. end)