xmake.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. set_project("libffi")
  2. add_rules("mode.debug", "mode.release")
  3. add_rules("utils.install.cmake_importfiles")
  4. set_configvar("PACKAGE", "libffi")
  5. set_configvar("PACKAGE_NAME", "libffi")
  6. set_configvar("PACKAGE_TARNAME", "libffi")
  7. set_configvar("PACKAGE_BUGREPORT", "")
  8. set_configvar("PACKAGE_URL", "")
  9. option("vers")
  10. set_default("3.4.2")
  11. set_showmenu(true)
  12. option_end()
  13. if has_config("vers") then
  14. set_version(get_config("vers"))
  15. set_configvar("VERSION", get_config("vers"))
  16. set_configvar("PACKAGE_VERSION", get_config("vers"))
  17. set_configvar("PACKAGE_STRING", "libffi " .. get_config("vers"))
  18. end
  19. local targetarch = is_plat("windows") and "X86_WIN64" or "X86_64"
  20. if is_plat("windows") then
  21. if is_arch("x86") then
  22. targetarch = "X86_WIN32"
  23. elseif is_arch("x64") then
  24. targetarch = "X86_WIN64"
  25. elseif is_arch("arm") then
  26. targetarch = "ARM_WIN32"
  27. elseif is_arch("arm64") then
  28. targetarch = "ARM_WIN64"
  29. end
  30. elseif is_plat("macosx") and is_arch("i386", "x86") then
  31. targetarch = "X86_DARWIN"
  32. elseif is_plat("bsd") and is_arch("i386", "x86") then
  33. targetarch = "X86_FREEBSD"
  34. else
  35. if is_arch("i386", "x86") then
  36. targetarch = "X86"
  37. elseif is_arch("x64") then
  38. targetarch = "X86_64"
  39. elseif is_arch("arm") then
  40. targetarch = "ARM"
  41. elseif is_arch("arm64") then
  42. targetarch = "ARM64"
  43. elseif is_arch("mips64") then
  44. targetarch = "MIPS64"
  45. elseif is_arch("riscv") then
  46. targetarch = "RISCV"
  47. end
  48. end
  49. set_configvar("TARGET", targetarch)
  50. includes("@builtin/check")
  51. set_configvar("STDC_HEADERS", 1)
  52. set_configvar("LT_OBJDIR", ".libs/")
  53. configvar_check_cincludes("HAVE_INTTYPES_H", "inttypes.h")
  54. configvar_check_cincludes("HAVE_MEMORY_H", "memory.h")
  55. configvar_check_cincludes("HAVE_STDINT_H", "stdint.h")
  56. configvar_check_cincludes("HAVE_STDLIB_H", "stdlib.h")
  57. configvar_check_cincludes("HAVE_STRINGS_H", "strings.h")
  58. configvar_check_cincludes("HAVE_STRING_H", "string.h")
  59. configvar_check_cincludes("HAVE_SYS_STAT_H", "sys/stat.h")
  60. configvar_check_cincludes("HAVE_SYS_TYPES_H", "sys/types.h")
  61. configvar_check_cincludes("HAVE_ALLOCA_H", "alloca.h")
  62. configvar_check_cfuncs("HAVE_ALLOCA", "alloca", {includes = "alloca.h"})
  63. configvar_check_csnippets("HAVE_LONG_DOUBLE", [[assert(sizeof(long double) > sizeof(double));]], {includes = "assert.h", tryrun = true, default = 0})
  64. configvar_check_csnippets("SIZEOF_DOUBLE", [[printf("%d", sizeof(double));]], {tryrun = true, output = true, number = true})
  65. configvar_check_csnippets("SIZEOF_LONG_DOUBLE", [[printf("%d", sizeof(long double));]], {tryrun = true, output = true, number = true})
  66. configvar_check_csnippets("SIZEOF_SIZE_T", [[printf("%d", sizeof(size_t));]], {tryrun = true, output = true, number = true})
  67. if not is_plat("windows") then
  68. set_configvar("HAVE_AS_X86_PCREL", 1)
  69. end
  70. if is_plat("macosx") then
  71. set_configvar("SYMBOL_UNDERSCORE", 1)
  72. end
  73. if is_plat("linux") then
  74. set_configvar("HAVE_HIDDEN_VISIBILITY_ATTRIBUTE", 1)
  75. set_configvar("EH_FRAME_FLAGS", "a")
  76. end
  77. if is_plat("macosx") and is_arch("arm64") then
  78. set_configvar("FFI_EXEC_TRAMPOLINE_TABLE", 1)
  79. else
  80. set_configvar("FFI_EXEC_TRAMPOLINE_TABLE", 0)
  81. end
  82. rule("asm.preprocess")
  83. set_extensions(".S")
  84. on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
  85. import("lib.detect.find_tool")
  86. local rootdir = path.join(target:autogendir(), "rules", "asm.preprocess")
  87. local filename = path.basename(sourcefile) .. ".asm"
  88. local sourcefile_or = path.absolute(sourcefile)
  89. local sourcefile_cx = target:autogenfile(sourcefile, {rootdir = rootdir, filename = filename})
  90. -- preprocessing
  91. local envs = target:toolchain("msvc"):runenvs()
  92. local cl = find_tool("cl", {envs = envs})
  93. batchcmds:execv(cl.program, {"/nologo", "/EP", "/Iinclude",
  94. "/I" .. path.directory(sourcefile_or), sourcefile_or}, {envs = envs, stdout = sourcefile_cx})
  95. local objectfile = target:objectfile(sourcefile_cx)
  96. table.insert(target:objectfiles(), objectfile)
  97. batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", sourcefile_cx)
  98. batchcmds:compile(sourcefile_cx, objectfile)
  99. batchcmds:add_depfiles(sourcefile)
  100. batchcmds:set_depmtime(os.mtime(objectfile))
  101. batchcmds:set_depcache(target:dependfile(objectfile))
  102. end)
  103. rule_end()
  104. if is_plat("windows") then
  105. add_rules("asm.preprocess", {override = true})
  106. end
  107. target("ffi")
  108. set_kind("$(kind)")
  109. if is_plat("windows") and is_kind("shared") then
  110. add_defines("FFI_BUILDING_DLL")
  111. end
  112. if is_kind("static") then
  113. add_defines("FFI_STATIC_BUILD")
  114. end
  115. set_configdir("include")
  116. add_configfiles("fficonfig.h.in")
  117. add_configfiles("include/ffi.h.in", {pattern = "@(.-)@"})
  118. add_includedirs("include")
  119. add_headerfiles("include/ffi.h")
  120. add_files("src/prep_cif.c", "src/types.c", "src/closures.c", "src/tramp.c")
  121. if not is_arch("arm") and not is_arch("arm64") then
  122. add_files("src/raw_api.c", "src/java_raw_api.c")
  123. end
  124. if is_plat("windows") and is_arch("x86") then
  125. add_asflags("/GZ")
  126. end
  127. if is_arch("i386", "x86") then
  128. add_files("src/x86/ffi.c")
  129. add_files(is_plat("windows") and "src/x86/sysv_intel.S" or "src/x86/sysv.S")
  130. add_includedirs("src/x86")
  131. add_headerfiles("src/x86/ffitarget.h")
  132. elseif is_arch("x86_64") then
  133. add_files("src/x86/ffi64.c", "src/x86/unix64.S", "src/x86/ffiw64.c", "src/x86/win64.S")
  134. add_includedirs("src/x86")
  135. add_headerfiles("src/x86/ffitarget.h")
  136. elseif is_arch("x64") then
  137. add_files("src/x86/ffi64.c", "src/x86/ffiw64.c", "src/x86/win64_intel.S")
  138. add_includedirs("src/x86")
  139. add_headerfiles("src/x86/ffitarget.h")
  140. elseif is_arch("arm") then
  141. add_files("src/arm/ffi.c")
  142. add_files(is_plat("windows") and "src/arm/sysv_msvc_arm32.S" or "src/arm/sysv.S")
  143. add_includedirs("src/arm")
  144. add_headerfiles("src/arm/ffitarget.h")
  145. elseif is_arch("arm64") then
  146. add_files("src/aarch64/ffi.c")
  147. add_files(is_plat("windows") and "src/aarch64/win64_armasm.S" or "src/aarch64/sysv.S")
  148. add_includedirs("src/aarch64")
  149. add_headerfiles("src/aarch64/ffitarget.h")
  150. elseif is_arch("mips64") then
  151. add_files("src/mips/ffi.c", "src/mips/n32.S")
  152. add_headerfiles("src/mips/ffitarget.h")
  153. elseif is_arch("riscv") then
  154. add_files("src/riscv/ffi.c", "src/riscv/sysv.S")
  155. add_headerfiles("src/riscv/ffitarget.h")
  156. elseif is_arch("wasm32") then
  157. add_files("src/wasm32/ffi.c")
  158. add_headerfiles("src/wasm32/ffitarget.h")
  159. end
  160. before_build(function (target)
  161. import("core.base.semver")
  162. if semver.compare(target:version(), "v3.4.4") <= 0 then
  163. io.replace("include/ffi.h", "!defined FFI_BUILDING", target:is_static() and "0" or "1", {plain = true})
  164. end
  165. end)