xmake.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. set_project("libiconv")
  2. add_rules("mode.debug", "mode.release")
  3. set_configvar("PACKAGE", "libiconv")
  4. set_configvar("PACKAGE_NAME", "libiconv")
  5. set_configvar("PACKAGE_TARNAME", "libiconv")
  6. set_configvar("PACKAGE_BUGREPORT", "")
  7. set_configvar("PACKAGE_URL", "")
  8. option("relocatable")
  9. set_default(true)
  10. set_showmenu(true)
  11. set_configvar("ENABLE_RELOCATABLE", 1)
  12. option_end()
  13. add_options("relocatable")
  14. option("installprefix")
  15. set_default("")
  16. set_showmenu(true)
  17. option_end()
  18. set_configvar("INSTALLPREFIX", get_config("installprefix"))
  19. option("vers")
  20. set_default("")
  21. set_showmenu(true)
  22. option_end()
  23. if has_config("vers") then
  24. set_configvar("VERSION", get_config("vers"))
  25. set_configvar("PACKAGE_VERSION", get_config("vers"))
  26. set_configvar("PACKAGE_STRING", "libiconv " .. get_config("vers"))
  27. end
  28. includes("@builtin/check")
  29. -- config.h variables
  30. option("__NO_BROKEN_WCHAR_H")
  31. set_showmenu(false)
  32. add_csnippets("wchar.h", [[#include <wchar.h>
  33. wchar_t w;]])
  34. option_end()
  35. set_configvar("BROKEN_WCHAR_H", has_config("__NO_BROKEN_WCHAR_H") and 0 or 1)
  36. option("GNULIB_STRERROR")
  37. set_showmenu(false)
  38. add_csnippets("strerror", [[#include <string.h>
  39. int test() { if (!*strerror(-2)) { return 1; } return 0; }]])
  40. set_configvar("GNULIB_STRERROR", 1)
  41. option_end()
  42. add_options("GNULIB_STRERROR")
  43. configvar_check_cfuncs("HAVE_ICONV", "iconv", {includes = "iconv.h"})
  44. option("ICONV_NO_CONST")
  45. set_showmenu(false)
  46. add_csnippets("ICONV_NO_CONST", [[#include <iconv.h>
  47. extern
  48. #ifdef __cplusplus
  49. "C"
  50. #endif
  51. #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
  52. size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
  53. #else
  54. size_t iconv();
  55. #endif]])
  56. option_end()
  57. set_configvar("ICONV_CONST", (has_config("HAVE_ICONV") and not has_config("ICONV_NO_CONST")) and "const" or "", {quote = false})
  58. set_configvar("LT_OBJDIR", ".libs/")
  59. set_configvar("_ALL_SOURCE", 1)
  60. set_configvar("_DARWIN_C_SOURCE", 1)
  61. set_configvar("_GNU_SOURCE", 1)
  62. set_configvar("_NETBSD_SOURCE", 1)
  63. set_configvar("_OPENBSD_SOURCE", 1)
  64. set_configvar("_POSIX_PTHREAD_SEMANTICS", 1)
  65. set_configvar("__STDC_WANT_IEC_60559_ATTRIBS_EXT__", 1)
  66. set_configvar("__STDC_WANT_IEC_60559_BFP_EXT__", 1)
  67. set_configvar("__STDC_WANT_IEC_60559_DFP_EXT__", 1)
  68. set_configvar("__STDC_WANT_IEC_60559_FUNCS_EXT__", 1)
  69. set_configvar("__STDC_WANT_IEC_60559_TYPES_EXT__", 1)
  70. set_configvar("__STDC_WANT_LIB_EXT2__", 1)
  71. set_configvar("__STDC_WANT_MATH_SPEC_FUNCS__", 1)
  72. set_configvar("_TANDEM_SOURCE", 1)
  73. set_configvar("__EXTENSIONS__", 1)
  74. set_configvar("ENABLE_EXTRA", 1)
  75. set_configvar("_USE_STD_STAT", 1)
  76. set_configvar("STDC_HEADERS", 1)
  77. set_configvar("USE_UNLOCKED_IO", 1)
  78. set_configvar("WORDS_LITTLEENDIAN", 1)
  79. set_configvar("GNULIB_MSVC_NOTHROW", 1)
  80. set_configvar("GNULIB_CANONICALIZE_LGPL", 1)
  81. set_configvar("GNULIB_TEST_CANONICALIZE_FILE_NAME", 1)
  82. set_configvar("GNULIB_TEST_ENVIRON", 1)
  83. set_configvar("GNULIB_TEST_LSTAT", 1)
  84. set_configvar("GNULIB_TEST_MALLOC_POSIX", 1)
  85. set_configvar("GNULIB_TEST_RAISE", 1)
  86. set_configvar("GNULIB_TEST_READ", 1)
  87. set_configvar("GNULIB_TEST_READLINK", 1)
  88. set_configvar("GNULIB_TEST_REALPATH", 1)
  89. set_configvar("GNULIB_TEST_SIGPROCMASK", 1)
  90. set_configvar("GNULIB_TEST_STAT", 1)
  91. set_configvar("GNULIB_TEST_STRERROR", 1)
  92. if not is_plat("android") then
  93. set_configvar("ssize_t", "int", {quote = false})
  94. set_configvar("uid_t", "int", {quote = false})
  95. end
  96. configvar_check_ctypes("USE_MBSTATE_T", "mbstate_t", {includes = "wchar.h", default = 0})
  97. configvar_check_cincludes("ENABLE_NLS", "libintl.h", {default = 0})
  98. configvar_check_cincludes("HAVE_DLFCN_H", "dlfcn.h")
  99. configvar_check_cincludes("HAVE_FCNTL", "fcntl.h")
  100. configvar_check_cincludes("HAVE_INTTYPES_H", "inttypes.h")
  101. configvar_check_cincludes("HAVE_MACH_O_DYLD_H", "mach-o/dyld.h")
  102. configvar_check_cincludes("HAVE_MEMORY_H", "memory.h")
  103. configvar_check_cincludes("HAVE_STDINT_H", "stdint.h")
  104. configvar_check_cincludes("HAVE_STDLIB_H", "stdlib.h")
  105. configvar_check_cincludes("HAVE_STRINGS_H", "strings.h")
  106. configvar_check_cincludes("HAVE_STRING_H", "string.h")
  107. configvar_check_cincludes("HAVE_SYS_STAT_H", "sys/stat.h")
  108. configvar_check_cincludes("HAVE_SYS_TYPES_H", "sys/types.h")
  109. configvar_check_cincludes("HAVE_UNISTD_H", "unistd.h")
  110. configvar_check_cincludes("HAVE_ALLOCA_H", "alloca.h")
  111. configvar_check_cincludes("HAVE_SEARCH_H", "search.h")
  112. configvar_check_cincludes("HAVE_SYS_BITYPES_H", "sys/bitypes.h")
  113. configvar_check_cfuncs("HAVE__NSGETEXECUTABLEPATH", "_NSGetExecutablePath")
  114. configvar_check_cfuncs("HAVE_MSVC_INVALID_PARAMETER_HANDLER", "_set_invalid_parameter_handler")
  115. configvar_check_cfuncs("HAVE_SETLOCALE", "setlocale", {includes = "locale.h"})
  116. configvar_check_cfuncs("HAVE_SYMLINK", "symlink", {includes = "unistd.h"})
  117. configvar_check_cfuncs("GNULIB_FSCANF", "fscanf", {includes = "stdio.h"})
  118. configvar_check_cfuncs("GNULIB_SCANF", "scanf", {includes = "stdio.h"})
  119. configvar_check_cfuncs("HAVE_ALLOCA", "alloca", {includes = "alloca.h"})
  120. configvar_check_cfuncs("HAVE_CANONICALIZE_FILE_NAME", "canonicalize_file_name", {includes = "stdlib.h", defines = "_GNU_SOURCE"})
  121. configvar_check_cfuncs("HAVE_DECL_CLEARERR_UNLOCKED", "clearerr_unlocked", {includes = "stdio.h", default = 0})
  122. configvar_check_cfuncs("HAVE_DECL_FEOF_UNLOCKED", "feof_unlocked", {includes = "stdio.h", default = 0})
  123. configvar_check_cfuncs("HAVE_DECL_FERROR_UNLOCKED", "ferror_unlocked", {includes = "stdio.h", default = 0})
  124. configvar_check_cfuncs("HAVE_DECL_FFLUSH_UNLOCKED", "fflush_unlocked", {includes = "stdio.h", default = 0})
  125. configvar_check_cfuncs("HAVE_DECL_FGETS_UNLOCKED", "fgets_unlocked", {includes = "stdio.h", defines = "_GNU_SOURCE", default = 0})
  126. configvar_check_cfuncs("HAVE_DECL_FPUTC_UNLOCKED", "fputc_unlocked", {includes = "stdio.h", default = 0})
  127. configvar_check_cfuncs("HAVE_DECL_FREAD_UNLOCKED", "fread_unlocked", {includes = "stdio.h", default = 0})
  128. configvar_check_cfuncs("HAVE_DECL_FWRITE_UNLOCKED", "fwrite_unlocked", {includes = "stdio.h", default = 0})
  129. configvar_check_cfuncs("HAVE_DECL_GETCHAR_UNLOCKED", "getchar_unlocked", {includes = "stdio.h", default = 0})
  130. configvar_check_cfuncs("HAVE_DECL_GETC_UNLOCKED", "getc_unlocked", {includes = "stdio.h", default = 0})
  131. configvar_check_cfuncs("HAVE_DECL_PUTCHAR_UNLOCKED", "putchar_unlocked", {includes = "stdio.h", default = 0})
  132. configvar_check_cfuncs("HAVE_DECL_PUTC_UNLOCKED", "putc_unlocked", {includes = "stdio.h", default = 0})
  133. configvar_check_cfuncs("HAVE_DECL_SETENV", "setenv", {includes = "stdlib.h", default = 0})
  134. configvar_check_cfuncs("HAVE_DECL_STRERROR_R", "strerror_r", {includes = "string.h", default = 0})
  135. configvar_check_cfuncs("HAVE_SETENV", "setenv", {includes = "stdlib.h"})
  136. configvar_check_cfuncs("HAVE_GETCWD", "getcwd", {includes = "unistd.h"})
  137. configvar_check_cfuncs("HAVE_GETEXECNAME", "getexecname", {includes = "stdlib.h"})
  138. configvar_check_cfuncs("HAVE_GETPROGNAME", "getprogname", {includes = "stdlib.h"})
  139. configvar_check_ctypes("HAVE_LONG_LONG_INT", "long long int")
  140. configvar_check_ctypes("HAVE_UNSIGNED_LONG_LONG_INT", "unsigned long long int")
  141. configvar_check_ctypes("HAVE__BOOL", "_Bool")
  142. configvar_check_cfuncs("HAVE_LSTAT", "lstat", {includes = "sys/stat.h"})
  143. configvar_check_cfuncs("HAVE_MALLOC_POSIX", "malloc", {includes = "stdlib.h"})
  144. configvar_check_cfuncs("HAVE_MBRTOWC", "mbrtowc", {includes = "wchar.h"})
  145. configvar_check_cfuncs("HAVE_WCRTOMB", "wcrtomb", {includes = "wchar.h"})
  146. configvar_check_cfuncs("HAVE_MBSINIT", "mbsinit", {includes = "wchar.h"})
  147. configvar_check_cfuncs("HAVE_RAISE", "raise", {includes = "signal.h"})
  148. configvar_check_cfuncs("HAVE_READLINK", "readlink", {includes = "unistd.h"})
  149. configvar_check_cfuncs("HAVE_READLINKAT", "readlinkat", {includes = "unistd.h"})
  150. configvar_check_cfuncs("HAVE_REALPATH", "realpath", {includes = "stdlib.h"})
  151. configvar_check_cfuncs("FUNC_REALPATH_WORKS", "realpath", {includes = "stdlib.h"})
  152. configvar_check_cfuncs("HAVE_TSEARCH", "tsearch", {includes = "search.h"})
  153. configvar_check_ctypes("HAVE_WCHAR_T", "wchar_t", {includes = "wchar.h"})
  154. configvar_check_ctypes("HAVE_SIGSET_T", "sigset_t", {includes = "signal.h"})
  155. configvar_check_csnippets("HAVE_VISIBILITY", [[
  156. extern __attribute__((__visibility__("hidden"))) int hiddenvar;
  157. extern __attribute__((__visibility__("default"))) int exportedvar;
  158. extern __attribute__((__visibility__("hidden"))) int hiddenfunc(void);
  159. extern __attribute__((__visibility__("default"))) int exportedfunc(void);]], {default = 0})
  160. configvar_check_csnippets("HAVE__ARGV", [[#include <stdlib.h>
  161. #ifndef __argv
  162. (void) __argv;
  163. #endif]], {default = 0})
  164. configvar_check_csnippets("HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC", [[#include <sys/types.h>
  165. #include <sys/stat.h>
  166. struct stat st;
  167. void test() { st.st_atim.tv_nsec; }]])
  168. configvar_check_csnippets("TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC", [[#include <sys/types.h>
  169. #include <sys/stat.h>
  170. #if HAVE_SYS_TIME_H
  171. # include <sys/time.h>
  172. #endif
  173. #include <time.h>
  174. struct timespec ts;
  175. struct stat st;
  176. void test() { st.st_atim = ts; }]])
  177. configvar_check_csnippets("PROGRAM_INVOCATION_NAME", [[#define _GNU_SOURCE
  178. #include <errno.h>
  179. extern char *program_invocation_name;]])
  180. configvar_check_csnippets("PROGRAM_INVOCATION_SHORT_NAME", [[#define _GNU_SOURCE
  181. #include <errno.h>
  182. extern char *program_invocation_short_name;]])
  183. configvar_check_csnippets("GNULIB_SIGPIPE", [[#include <signal.h>
  184. #ifndef SIGPIPE
  185. #error SIGPIPE not defined
  186. #endif]])
  187. configvar_check_csnippets("HAVE_LANGINFO_CODESET", [[#include <langinfo.h>
  188. int test() { char* cs = nl_langinfo(CODESET); return !cs; }]], {links = "c"})
  189. configvar_check_csnippets("HAVE_ENVIRON_DECL=0", [[extern struct {int foo;} environ;
  190. void test() {environ.foo = 1;}]], {includes = has_config("__HAVE_UNISTD_H") and "unistd.h" or "stdlib.h", default = 1})
  191. target("charset")
  192. set_kind("$(kind)")
  193. add_defines("HAVE_CONFIG_H")
  194. if is_kind("shared") then
  195. add_defines("BUILDING_LIBCHARSET")
  196. end
  197. set_configdir("libcharset")
  198. add_configfiles("libcharset/(include/localcharset.h.build.in)", {filename = "localcharset.h", pattern = "@(.-)@"})
  199. add_configfiles("libcharset/(include/libcharset.h.in)", {filename = "libcharset.h", pattern = "@(.-)@"})
  200. add_configfiles("libcharset/(config.h.in)", {filename = "config.h"})
  201. add_includedirs("libcharset/include", "libcharset")
  202. add_files("libcharset/lib/localcharset.c")
  203. after_install(function (target)
  204. os.cp("libcharset/include/libcharset.h.in", path.join(target:installdir(), "include", "libcharset.h"))
  205. os.cp("libcharset/include/localcharset.h.in", path.join(target:installdir(), "include", "localcharset.h"))
  206. end)
  207. target_end()
  208. target("iconv")
  209. set_kind("$(kind)")
  210. add_deps("charset", {inherit = false})
  211. add_defines("HAVE_CONFIG_H", "NO_XMALLOC", "IN_LIBRARY")
  212. if is_kind("shared") then
  213. add_defines("BUILDING_LIBICONV", "BUILDING_DLL")
  214. end
  215. set_configdir(".")
  216. set_configvar("DLL_VARIABLE", (is_plat("windows") and is_kind("shared")) and "__declspec(dllimport)" or "")
  217. add_configfiles("(include/iconv.h.build.in)", {filename = "iconv.h", pattern = "@(.-)@", variables = {EILSEQ = ""}})
  218. add_configfiles("(include/iconv.h.in)", {filename = "iconv.h.inst", pattern = "@(.-)@", variables = {EILSEQ = ""}})
  219. add_configfiles("(config.h.in)", {filename = "config.h"})
  220. add_includedirs(".", "lib", "include", "libcharset/include", {public = true})
  221. add_files("lib/iconv.c", "lib/relocatable.c", "libcharset/lib/localcharset.c")
  222. after_install(function (target)
  223. os.cp("include/iconv.h.inst", path.join(target:installdir(), "include", "iconv.h"))
  224. for _, name in ipairs(os.files("po/*.gmo")) do
  225. local locale = path.basename(name)
  226. os.cp(name, path.join(target:installdir(), "share", "locale", locale, "LC_MESSAGES", "libiconv.mo"))
  227. end
  228. end)
  229. target_end()
  230. target("icrt")
  231. set_kind("static")
  232. add_includedirs(".", "srclib", {public = true})
  233. set_configdir(".")
  234. add_configfiles("(srclib/uniwidth.in.h)", {filename = "uniwidth.h"})
  235. add_configfiles("(srclib/unitypes.in.h)", {filename = "unitypes.h"})
  236. add_files("srclib/progname.c", "srclib/safe-read.c", "srclib/uniwidth/width.c")
  237. if has_config("relocatable") then
  238. add_files("srclib/progreloc.c", "srclib/relocatable.c")
  239. end
  240. add_defines("EXEEXT=\"" .. (is_plat("windows") and ".exe" or "") .. "\"")
  241. on_install(function (target) end) -- disable installation
  242. target("iconv_no_i18n")
  243. set_kind("binary")
  244. add_deps("iconv", "icrt")
  245. if has_config("installprefix") then
  246. add_defines("INSTALLDIR=\"" .. path.join(get_config("installprefix"), "bin"):gsub("\\", "\\\\") .. "\"")
  247. add_defines("LOCALEDIR=\"" .. path.join(get_config("installprefix"), "share", "locale"):gsub("\\", "\\\\") .. "\"")
  248. end
  249. add_files("src/iconv_no_i18n.c")
  250. if is_plat("android") then
  251. -- Gnulib defines these macros to 0 on GNU and other platforms that do not distinguish between text and binary I/O.
  252. -- https://www.gnu.org/software/gnulib/manual/html_node/fcntl_002eh.html
  253. add_defines("O_BINARY=0")
  254. end