xmake.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. set_project("libintl")
  2. add_rules("mode.debug", "mode.release")
  3. set_configvar("PACKAGE", "gettext-runtime")
  4. set_configvar("PACKAGE_NAME", "gettext-runtime")
  5. set_configvar("PACKAGE_TARNAME", "gettext-runtime")
  6. set_configvar("PACKAGE_BUGREPORT", "[email protected]")
  7. set_configvar("PACKAGE_URL", "")
  8. option("installprefix")
  9. set_default("")
  10. set_showmenu(true)
  11. option_end()
  12. set_configvar("INSTALLPREFIX", get_config("installprefix"))
  13. if has_config("installprefix") then
  14. add_defines("LOCALEDIR=\"" .. get_config("installprefix") .. "/locale\"")
  15. add_defines("LOCALE_ALIAS_PATH=\"" .. get_config("installprefix") .. "/locale\"")
  16. end
  17. option("vers")
  18. set_default("")
  19. set_showmenu(true)
  20. option_end()
  21. if has_config("vers") then
  22. set_version(get_config("vers"))
  23. set_configvar("VERSION", get_config("vers"))
  24. set_configvar("PACKAGE_VERSION", get_config("vers"))
  25. set_configvar("PACKAGE_STRING", "gettext-runtime " .. get_config("vers"))
  26. end
  27. option("relocatable")
  28. set_default(true)
  29. set_showmenu(true)
  30. option_end()
  31. if has_config("relocatable") then
  32. add_defines("ENABLE_RELOCATABLE=1")
  33. set_configvar("ENABLE_RELOCATABLE", 1)
  34. end
  35. includes("check_cfuncs.lua")
  36. includes("check_ctypes.lua")
  37. includes("check_macros.lua")
  38. includes("check_links.lua")
  39. includes("check_cincludes.lua")
  40. includes("check_csnippets.lua")
  41. -- general autoconf variables
  42. option("GNULIB_STRERROR")
  43. add_csnippets("strerror", [[#include <string.h>
  44. int test() { if (!*strerror(-2)) { return 1; } return 0; }]])
  45. set_configvar("GNULIB_STRERROR", 1)
  46. option_end()
  47. add_options("GNULIB_STRERROR")
  48. option("HAVE_UID_T")
  49. add_ctypes("uid_t")
  50. add_cincludes("stdlib.h")
  51. option_end()
  52. if not has_config("HAVE_UID_T") then
  53. set_configvar("uid_t", "int", {quote = false})
  54. end
  55. option("HAVE_SSIZE_T")
  56. add_ctypes("ssize_t")
  57. add_cincludes("sys/types.h")
  58. option_end()
  59. if not has_config("HAVE_SSIZE_T") then
  60. set_configvar("ssize_t", "int", {quote = false})
  61. end
  62. option("HAVE_NLINK_T")
  63. add_ctypes("nlink_t")
  64. add_cincludes("sys/types.h")
  65. option_end()
  66. if not has_config("HAVE_NLINK_T") then
  67. set_configvar("nlink_t", "int", {quote = false})
  68. end
  69. set_configvar("LT_OBJDIR", ".libs/")
  70. set_configvar("HAVE_INLINE", 1)
  71. set_configvar("_ALL_SOURCE", 1)
  72. set_configvar("_DARWIN_C_SOURCE", 1)
  73. set_configvar("_GNU_SOURCE", 1)
  74. set_configvar("_NETBSD_SOURCE", 1)
  75. set_configvar("_OPENBSD_SOURCE", 1)
  76. set_configvar("_POSIX_PTHREAD_SEMANTICS", 1)
  77. set_configvar("__STDC_WANT_IEC_60559_ATTRIBS_EXT__", 1)
  78. set_configvar("__STDC_WANT_IEC_60559_BFP_EXT__", 1)
  79. set_configvar("__STDC_WANT_IEC_60559_DFP_EXT__", 1)
  80. set_configvar("__STDC_WANT_IEC_60559_FUNCS_EXT__", 1)
  81. set_configvar("__STDC_WANT_IEC_60559_TYPES_EXT__", 1)
  82. set_configvar("__STDC_WANT_LIB_EXT2__", 1)
  83. set_configvar("__STDC_WANT_MATH_SPEC_FUNCS__", 1)
  84. set_configvar("_TANDEM_SOURCE", 1)
  85. set_configvar("__EXTENSIONS__", 1)
  86. set_configvar("ENABLE_EXTRA", 1)
  87. set_configvar("_USE_STD_STAT", 1)
  88. set_configvar("__USE_MINGW_ANSI_STDIO", 1)
  89. set_configvar("STDC_HEADERS", 1)
  90. set_configvar("USE_UNLOCKED_IO", 1)
  91. set_configvar("GNULIB_MSVC_NOTHROW", 1)
  92. set_configvar("GNULIB_CANONICALIZE_LGPL", 1)
  93. set_configvar("GNULIB_TEST_CANONICALIZE_FILE_NAME", 1)
  94. set_configvar("GNULIB_TEST_ENVIRON", 1)
  95. set_configvar("GNULIB_TEST_LSTAT", 1)
  96. set_configvar("GNULIB_TEST_MALLOC_POSIX", 1)
  97. set_configvar("GNULIB_TEST_RAISE", 1)
  98. set_configvar("GNULIB_TEST_READ", 1)
  99. set_configvar("GNULIB_TEST_READLINK", 1)
  100. set_configvar("GNULIB_TEST_REALPATH", 1)
  101. set_configvar("GNULIB_TEST_SIGPROCMASK", 1)
  102. set_configvar("GNULIB_TEST_STAT", 1)
  103. set_configvar("GNULIB_TEST_STRERROR", 1)
  104. set_configvar("GNULIB_TEST_STRNLEN", 1)
  105. set_configvar("GNULIB_TEST_WCWIDTH", 1)
  106. set_configvar("GNULIB_UNISTR_U8_MBTOUCR", 1)
  107. set_configvar("GNULIB_UNISTR_U8_UCTOMB", 1)
  108. configvar_check_cincludes("ENABLE_NLS", "libintl.h", {default = 0})
  109. configvar_check_cincludes("HAVE_DLFCN_H", "dlfcn.h")
  110. configvar_check_cincludes("HAVE_INTTYPES_H", "inttypes.h")
  111. configvar_check_cincludes("HAVE_MACH_O_DYLD_H", "mach-o/dyld.h")
  112. configvar_check_cincludes("HAVE_MEMORY_H", "memory.h")
  113. configvar_check_cincludes("HAVE_STDINT_H", "stdint.h")
  114. configvar_check_cincludes("HAVE_STDDEF_H", "stddef.h")
  115. configvar_check_cincludes("HAVE_STDLIB_H", "stdlib.h")
  116. configvar_check_cincludes("HAVE_STRINGS_H", "strings.h")
  117. configvar_check_cincludes("HAVE_STRING_H", "string.h")
  118. configvar_check_cincludes("HAVE_SYS_STAT_H", "sys/stat.h")
  119. configvar_check_cincludes("HAVE_SYS_TYPES_H", "sys/types.h")
  120. configvar_check_cincludes("HAVE_SYS_MMAN_H", "sys/mman.h")
  121. configvar_check_cincludes("HAVE_UNISTD_H", "unistd.h")
  122. configvar_check_cincludes("HAVE_ALLOCA_H", "alloca.h")
  123. configvar_check_cincludes("HAVE_SEARCH_H", "search.h")
  124. configvar_check_cincludes("HAVE_SYS_BITYPES_H", "sys/bitypes.h")
  125. configvar_check_cincludes("HAVE_WCHAR_H", "wchar.h")
  126. configvar_check_cincludes("HAVE_WCTYPE_H", "wctype.h")
  127. configvar_check_cincludes("HAVE_WINSOCK2_H", "winsock2.h")
  128. configvar_check_cincludes("HAVE_CRTDEFS_H", "crtdefs.h")
  129. configvar_check_cincludes("HAVE_BP_SYM_H", "bp-sym.h")
  130. configvar_check_cincludes("HAVE_XLOCALE_H", "xlocale.h")
  131. configvar_check_cfuncs("HAVE__NSGETEXECUTABLEPATH", "_NSGetExecutablePath")
  132. configvar_check_cfuncs("HAVE_MSVC_INVALID_PARAMETER_HANDLER", "_set_invalid_parameter_handler")
  133. configvar_check_cfuncs("HAVE_SETLOCALE", "setlocale", {includes = "locale.h"})
  134. configvar_check_cfuncs("HAVE_SYMLINK", "symlink", {includes = "unistd.h"})
  135. configvar_check_cfuncs("GNULIB_FSCANF", "fscanf", {includes = "stdio.h"})
  136. configvar_check_cfuncs("GNULIB_SCANF", "scanf", {includes = "stdio.h"})
  137. configvar_check_cfuncs("HAVE_CANONICALIZE_FILE_NAME", "canonicalize_file_name", {includes = "stdlib.h", defines = "_GNU_SOURCE"})
  138. configvar_check_cfuncs("HAVE_DECL_CLEARERR_UNLOCKED", "clearerr_unlocked", {includes = "stdio.h", default = 0})
  139. configvar_check_cfuncs("HAVE_DECL_FEOF_UNLOCKED", "feof_unlocked", {includes = "stdio.h", default = 0})
  140. configvar_check_cfuncs("HAVE_DECL_FERROR_UNLOCKED", "ferror_unlocked", {includes = "stdio.h", default = 0})
  141. configvar_check_cfuncs("HAVE_DECL_FFLUSH_UNLOCKED", "fflush_unlocked", {includes = "stdio.h", default = 0})
  142. configvar_check_cfuncs("HAVE_DECL_FGETS_UNLOCKED", "fgets_unlocked", {includes = "stdio.h", defines = "_GNU_SOURCE", default = 0})
  143. configvar_check_cfuncs("HAVE_DECL_FPUTC_UNLOCKED", "fputc_unlocked", {includes = "stdio.h", default = 0})
  144. configvar_check_cfuncs("HAVE_DECL_FREAD_UNLOCKED", "fread_unlocked", {includes = "stdio.h", default = 0})
  145. configvar_check_cfuncs("HAVE_DECL_FWRITE_UNLOCKED", "fwrite_unlocked", {includes = "stdio.h", default = 0})
  146. configvar_check_cfuncs("HAVE_DECL_GETCHAR_UNLOCKED", "getchar_unlocked", {includes = "stdio.h", default = 0})
  147. configvar_check_cfuncs("HAVE_DECL_GETC_UNLOCKED", "getc_unlocked", {includes = "stdio.h", default = 0})
  148. configvar_check_cfuncs("HAVE_DECL_PUTCHAR_UNLOCKED", "putchar_unlocked", {includes = "stdio.h", default = 0})
  149. configvar_check_cfuncs("HAVE_DECL_PUTC_UNLOCKED", "putc_unlocked", {includes = "stdio.h", default = 0})
  150. configvar_check_cfuncs("HAVE_DECL_SETENV", "setenv", {includes = "stdlib.h", default = 0})
  151. configvar_check_cfuncs("HAVE_DECL_STRERROR_R", "strerror_r", {includes = "string.h", default = 0})
  152. configvar_check_cfuncs("HAVE_SETENV", "setenv", {includes = "stdlib.h"})
  153. configvar_check_cfuncs("HAVE_PUTENV", "putenv", {includes = "stdlib.h"})
  154. configvar_check_cfuncs("HAVE_GETCWD", "getcwd", {includes = "unistd.h"})
  155. configvar_check_cfuncs("HAVE_GETEXECNAME", "getexecname", {includes = "stdlib.h"})
  156. configvar_check_cfuncs("HAVE_GETPROGNAME", "getprogname", {includes = "stdlib.h"})
  157. configvar_check_cfuncs("HAVE_LSTAT", "lstat", {includes = "sys/stat.h"})
  158. configvar_check_cfuncs("HAVE_MALLOC_POSIX", "malloc", {includes = "stdlib.h"})
  159. configvar_check_cfuncs("HAVE_ATEXIT", "atexit", {includes = "stdlib.h"})
  160. configvar_check_cfuncs("HAVE_MBRTOWC", "mbrtowc", {includes = "wchar.h"})
  161. configvar_check_cfuncs("HAVE_WCRTOMB", "wcrtomb", {includes = "wchar.h"})
  162. configvar_check_cfuncs("HAVE_WCSLEN", "wcslen", {includes = "wchar.h"})
  163. configvar_check_cfuncs("HAVE_WCWIDTH", "wcwidth", {includes = "wchar.h"})
  164. configvar_check_cfuncs("HAVE_WCSNLEN", "wcsnlen", {includes = "wchar.h"})
  165. configvar_check_cfuncs("HAVE_MBSINIT", "mbsinit", {includes = "wchar.h"})
  166. configvar_check_cfuncs("HAVE_BTOWC", "btowc", {includes = "wchar.h"})
  167. configvar_check_cfuncs("HAVE_ISWBLANK", "iswblank", {includes = "wctype.h"})
  168. configvar_check_cfuncs("HAVE_ISWCNTRL", "iswcntrl", {includes = "wctype.h"})
  169. configvar_check_cfuncs("HAVE_RAISE", "raise", {includes = "signal.h"})
  170. configvar_check_cfuncs("HAVE_READLINK", "readlink", {includes = "unistd.h"})
  171. configvar_check_cfuncs("HAVE_READLINKAT", "readlinkat", {includes = "unistd.h"})
  172. configvar_check_cfuncs("HAVE_REALPATH", "realpath", {includes = "stdlib.h"})
  173. configvar_check_cfuncs("FUNC_REALPATH_WORKS", "realpath", {includes = "stdlib.h"})
  174. configvar_check_cfuncs("HAVE_TSEARCH", "tsearch", {includes = "search.h"})
  175. configvar_check_cfuncs("HAVE_STPCPY", "stpcpy", {includes = "string.h"})
  176. configvar_check_cfuncs("HAVE_STRDUP", "strdup", {includes = "string.h"})
  177. configvar_check_cfuncs("HAVE_STRTOUL", "strtoul", {includes = "string.h"})
  178. configvar_check_cfuncs("HAVE_MEMPCPY", "mempcpy", {includes = "string.h", defines = "_GNU_SOURCE"})
  179. configvar_check_cfuncs("HAVE_MMAP", "mmap", {includes = "sys/mman.h"})
  180. configvar_check_cfuncs("HAVE_MPROTECT", "mprotect", {includes = "sys/mman.h"})
  181. configvar_check_cfuncs("HAVE_MUNMAP", "munmap", {includes = "sys/mman.h"})
  182. configvar_check_ctypes("HAVE_LONG_LONG_INT", "long long int")
  183. configvar_check_ctypes("HAVE_UNSIGNED_LONG_LONG_INT", "unsigned long long int")
  184. configvar_check_ctypes("HAVE__BOOL", "_Bool")
  185. configvar_check_ctypes("HAVE_WCHAR_T", "wchar_t", {includes = "wchar.h"})
  186. configvar_check_ctypes("HAVE_WINT_T", "wint_t", {includes = "wchar.h"})
  187. configvar_check_ctypes("HAVE_SIGSET_T", "sigset_t", {includes = "signal.h"})
  188. configvar_check_macros("HAVE_MSVC_INVALID_PARAMETER_HANDLER", "_MSC_VER")
  189. configvar_check_csnippets("HAVE_VISIBILITY", [[
  190. extern __attribute__((__visibility__("hidden"))) int hiddenvar;
  191. extern __attribute__((__visibility__("default"))) int exportedvar;
  192. extern __attribute__((__visibility__("hidden"))) int hiddenfunc(void);
  193. extern __attribute__((__visibility__("default"))) int exportedfunc(void);]], {default = 0})
  194. configvar_check_csnippets("HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC", [[#include <sys/types.h>
  195. #include <sys/stat.h>
  196. struct stat st;
  197. void test() { st.st_atim.tv_nsec; }]])
  198. configvar_check_csnippets("TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC", [[#include <sys/types.h>
  199. #include <sys/stat.h>
  200. #if HAVE_SYS_TIME_H
  201. # include <sys/time.h>
  202. #endif
  203. #include <time.h>
  204. struct timespec ts;
  205. struct stat st;
  206. void test() { st.st_atim = ts; }]])
  207. configvar_check_csnippets("PROGRAM_INVOCATION_NAME", [[#define _GNU_SOURCE
  208. #include <errno.h>
  209. extern char *program_invocation_name;]])
  210. configvar_check_csnippets("PROGRAM_INVOCATION_SHORT_NAME", [[#define _GNU_SOURCE
  211. #include <errno.h>
  212. extern char *program_invocation_short_name;]])
  213. configvar_check_csnippets("GNULIB_SIGPIPE", [[#include <signal.h>
  214. #ifndef SIGPIPE
  215. #error SIGPIPE not defined
  216. #endif]])
  217. configvar_check_csnippets("HAVE_LANGINFO_CODESET", [[#include <langinfo.h>
  218. int test() { char* cs = nl_langinfo(CODESET); return !cs; }]])
  219. configvar_check_csnippets("HAVE_ENVIRON_DECL=0", [[extern struct {int foo;} environ;
  220. void test() {environ.foo = 1;}]], {includes = is_plat("windows") and "stdlib.h" or "unistd.h", default = 1})
  221. -- config.h variables
  222. configvar_check_ctypes("HAVE_STDINT_H_WITH_UINTMAX", "uintmax_t", {includes = "stdint.h"})
  223. configvar_check_ctypes("HAVE_UINTMAX_T", "uintmax_t", {includes = "stdint.h"})
  224. if is_plat("android") then
  225. configvar_check_cfuncs("HAVE_PTHREAD_API", "pthread_create", {includes = "pthread.h"})
  226. else
  227. configvar_check_links("HAVE_PTHREAD_API", "pthread")
  228. end
  229. configvar_check_csnippets("HAVE_ALLOCA", [[
  230. #ifdef __GNUC__
  231. # define alloca __builtin_alloca
  232. #elif defined _MSC_VER
  233. # include <malloc.h>
  234. # define alloca _alloca
  235. #else
  236. # include <alloca.h>
  237. #endif
  238. void test() { char *p = (char *)alloca(1); }
  239. ]])
  240. if is_plat("windows") and is_kind("shared") then
  241. set_configvar("WOE32DLL", 1)
  242. end
  243. set_configvar("SETLOCALE_NULL_ALL_MTSAFE", is_plat("windows", "linux") and 1 or 0)
  244. set_configvar("SETLOCALE_NULL_ONE_MTSAFE", 1)
  245. set_configvar("NEED_SETLOCALE_IMPROVED", is_plat("mingw") and 1 or 0)
  246. set_configvar("NEED_SETLOCALE_MTSAFE", is_plat("windows", "linux") and 0 or 1)
  247. -- libgnuintl.h variables
  248. set_configvar("HAVE_NAMELESS_LOCALES", 0)
  249. configvar_check_cfuncs("HAVE_NEWLOCALE", "newlocale", {includes = (is_plat("macosx") and "xlocale.h" or "locale.h"), default = 0})
  250. configvar_check_cfuncs("HAVE_POSIX_PRINTF", "printf", {includes = "stdio.h", default = 0})
  251. configvar_check_cfuncs("HAVE_WPRINTF", "wprintf", {includes = "wchar.h", default = 0})
  252. configvar_check_cfuncs("HAVE_SNPRINTF", "snprintf", {includes = "stdio.h", default = 0})
  253. configvar_check_cfuncs("HAVE_ASPRINTF", "asprintf", {includes = "stdio.h", default = 0})
  254. target("intl")
  255. set_kind("$(kind)")
  256. add_defines("HAVE_CONFIG_H", "NO_XMALLOC", "IN_LIBRARY", "IN_LIBINTL")
  257. if is_kind("shared") then
  258. add_defines("BUILDING_LIBINTL", "BUILDING_DLL")
  259. end
  260. if is_plat("windows") then
  261. add_syslinks("advapi32")
  262. end
  263. set_configvar("HAVE_ICONV", 0)
  264. set_configvar("HAVE_ICONV_H", 0)
  265. add_defines("DEPENDS_ON_LIBICONV=0")
  266. set_configdir("gettext-runtime")
  267. add_configfiles("gettext-runtime/(intl/libgnuintl.in.h)", {filename = "libgnuintl.h", pattern = "@(.-)@"})
  268. add_configfiles("gettext-runtime/intl/(export.h)", {filename = "export.h", pattern = "@(.-)@"})
  269. add_configfiles("gettext-runtime/(config.h.in)", {filename = "config.h"})
  270. add_includedirs("gettext-runtime", "gettext-runtime/intl")
  271. add_files("gettext-runtime/intl/bindtextdom.c",
  272. "gettext-runtime/intl/dcigettext.c",
  273. "gettext-runtime/intl/dcngettext.c",
  274. "gettext-runtime/intl/dcgettext.c",
  275. "gettext-runtime/intl/dgettext.c",
  276. "gettext-runtime/intl/dngettext.c",
  277. "gettext-runtime/intl/explodename.c",
  278. "gettext-runtime/intl/finddomain.c",
  279. "gettext-runtime/intl/gettext.c",
  280. "gettext-runtime/intl/hash-string.c",
  281. "gettext-runtime/intl/intl-compat.c",
  282. "gettext-runtime/intl/l10nflist.c",
  283. "gettext-runtime/intl/langprefs.c",
  284. "gettext-runtime/intl/loadmsgcat.c",
  285. "gettext-runtime/intl/localealias.c",
  286. "gettext-runtime/intl/localename.c",
  287. "gettext-runtime/intl/localename-table.c",
  288. "gettext-runtime/intl/localcharset.c",
  289. "gettext-runtime/intl/lock.c",
  290. "gettext-runtime/intl/log.c",
  291. "gettext-runtime/intl/ngettext.c",
  292. "gettext-runtime/intl/osdep.c",
  293. "gettext-runtime/intl/plural.c",
  294. "gettext-runtime/intl/plural-exp.c",
  295. "gettext-runtime/intl/printf.c",
  296. "gettext-runtime/intl/relocatable.c",
  297. "gettext-runtime/intl/setlocale.c",
  298. "gettext-runtime/intl/setlocale-lock.c",
  299. "gettext-runtime/intl/setlocale_null.c",
  300. "gettext-runtime/intl/threadlib.c",
  301. "gettext-runtime/intl/textdomain.c",
  302. "gettext-runtime/intl/version.c",
  303. "gettext-runtime/intl/xsize.c")
  304. if is_plat("windows") then
  305. add_files("gettext-runtime/intl/windows-mutex.c",
  306. "gettext-runtime/intl/windows-rwlock.c",
  307. "gettext-runtime/intl/windows-recmutex.c",
  308. "gettext-runtime/intl/windows-once.c")
  309. end
  310. before_build(function (target)
  311. os.cp("gettext-runtime/intl/libgnuintl.h", "gettext-runtime/intl/libintl.h")
  312. local lines = io.readfile("gettext-runtime/export.h")
  313. io.replace("gettext-runtime/intl/libgnuintl.h", "#define _LIBINTL_H 1", "#define _LIBINTL_H 1\n" .. lines, {plain = true})
  314. io.replace("gettext-runtime/intl/libgnuintl.h", "extern", "extern LIBINTL_DLL_EXPORTED", {plain = true})
  315. end)
  316. after_install(function (target)
  317. io.replace("gettext-runtime/intl/libintl.h", "extern", (target:is_plat("windows") and target:kind() == "shared") and "extern __declspec(dllimport)" or "extern", {plain = true})
  318. os.cp("gettext-runtime/intl/libintl.h", path.join(target:installdir(), "include", "libintl.h"))
  319. end)
  320. target_end()