0001_Support_M4_building_on_FreeBSD.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. From c07d3368b31e587db7a73352c4fa3c25f0e488b7 Mon Sep 17 00:00:00 2001
  2. From: Luke Yoo <w.lukeyoo@gmail.com>
  3. Date: Tue, 13 Dec 2022 04:48:39 -0800
  4. Subject: [PATCH] Support M4 building on FreeBSD
  5. This is based on the OpenBSD support in `v0.2.2`
  6. For later versions, it may be supported without it
  7. ---
  8. m4/internal/gnulib/config-freebsd.h | 232 ++++++++++++++++++++++++++++
  9. m4/internal/gnulib/gnulib.BUILD | 13 ++
  10. m4/internal/gnulib/gnulib.bzl | 18 +++
  11. m4/internal/repository.bzl | 4 +
  12. 4 files changed, 267 insertions(+)
  13. create mode 100644 m4/internal/gnulib/config-freebsd.h
  14. diff --git a/m4/internal/gnulib/config-freebsd.h b/m4/internal/gnulib/config-freebsd.h
  15. new file mode 100644
  16. index 0000000..639748e
  17. --- /dev/null
  18. +++ b/m4/internal/gnulib/config-freebsd.h
  19. @@ -0,0 +1,232 @@
  20. +{GNULIB_CONFIG_HEADER}
  21. +
  22. +#define _GL_ATTRIBUTE_FORMAT_PRINTF(x, y)
  23. +
  24. +#define O_BINARY 0
  25. +#define O_TEXT 0
  26. +
  27. +extern char **environ;
  28. +
  29. +/******************************************************************************/
  30. +
  31. +#define CHECK_PRINTF_SAFE 1
  32. +#define C_LOCALE_MAYBE_EILSEQ 1
  33. +#define DBL_EXPBIT0_BIT 20
  34. +#define DBL_EXPBIT0_WORD 1
  35. +#define FAULT_YIELDS_SIGBUS 0
  36. +#define FLT_EXPBIT0_BIT 23
  37. +#define FLT_EXPBIT0_WORD 0
  38. +#define FUNC_FFLUSH_STDIN 0
  39. +#define FUNC_NL_LANGINFO_YESEXPR_WORKS 1
  40. +#define FUNC_REALPATH_WORKS 1
  41. +#define GETTIMEOFDAY_TIMEZONE struct timezone
  42. +#define GNULIB_CANONICALIZE_LGPL 1
  43. +#define GNULIB_CLOSE_STREAM 1
  44. +#define GNULIB_DIRNAME 1
  45. +#define GNULIB_FD_SAFER_FLAG 1
  46. +#define GNULIB_FFLUSH 1
  47. +#define GNULIB_FILENAMECAT 1
  48. +#define GNULIB_FOPEN_SAFER 1
  49. +#define GNULIB_FSCANF 1
  50. +#define GNULIB_LOCK 1
  51. +#define GNULIB_MSVC_NOTHROW 1
  52. +#define GNULIB_PIPE2_SAFER 1
  53. +#define GNULIB_SCANF 1
  54. +#define GNULIB_SIGPIPE 1
  55. +#define GNULIB_SNPRINTF 1
  56. +#define GNULIB_STRERROR 1
  57. +#define HAVE_ALLOCA 0
  58. +#define HAVE_BTOWC 1
  59. +#define HAVE_CANONICALIZE_FILE_NAME 1
  60. +#define HAVE_DECL_ALARM 1
  61. +#define HAVE_DECL_CLEARERR_UNLOCKED 0
  62. +#define HAVE_DECL_FEOF_UNLOCKED 0
  63. +#define HAVE_DECL_FERROR_UNLOCKED 1
  64. +#define HAVE_DECL_FFLUSH_UNLOCKED 1
  65. +#define HAVE_DECL_FGETS_UNLOCKED 1
  66. +#define HAVE_DECL_FPURGE 0
  67. +#define HAVE_DECL_FPUTC_UNLOCKED 0
  68. +#define HAVE_DECL_FPUTS_UNLOCKED 0
  69. +#define HAVE_DECL_FREAD_UNLOCKED 0
  70. +#define HAVE_DECL_FSEEKO 1
  71. +#define HAVE_DECL_FTELLO 1
  72. +#define HAVE_DECL_FWRITE_UNLOCKED 0
  73. +#define HAVE_DECL_GETCHAR_UNLOCKED 1
  74. +#define HAVE_DECL_GETC_UNLOCKED 1
  75. +#define HAVE_DECL_GETDTABLESIZE 1
  76. +#define HAVE_DECL_ISBLANK 1
  77. +#define HAVE_DECL_PROGRAM_INVOCATION_NAME 0
  78. +#define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 0
  79. +#define HAVE_DECL_PUTCHAR_UNLOCKED 1
  80. +#define HAVE_DECL_PUTC_UNLOCKED 1
  81. +#define HAVE_DECL_SIGALTSTACK 1
  82. +#define HAVE_DECL_SNPRINTF 1
  83. +#define HAVE_DECL_STRERROR_R 1
  84. +#define HAVE_DECL_STRNDUP 1
  85. +#define HAVE_DECL_STRNLEN 1
  86. +#define HAVE_DECL_STRSIGNAL 1
  87. +#define HAVE_DECL_SYS_SIGLIST 1
  88. +#define HAVE_DECL__SNPRINTF 0
  89. +#define HAVE_DECL___ARGV 0
  90. +#define HAVE_DUP2 1
  91. +#define HAVE_ENVIRON_DECL 1
  92. +#define HAVE_FCNTL 1
  93. +#define HAVE_FREXPL_IN_LIBC 1
  94. +#define HAVE_FREXP_IN_LIBC 1
  95. +#define HAVE_FSEEKO 1
  96. +#define HAVE_GETCWD 1
  97. +#define HAVE_GETDTABLESIZE 1
  98. +#define HAVE_GETEGID 1
  99. +#define HAVE_GETEUID 1
  100. +#define HAVE_GETGID 1
  101. +#define HAVE_GETOPT_H 1
  102. +#define HAVE_GETOPT_LONG_ONLY 1
  103. +#define HAVE_GETTIMEOFDAY 1
  104. +#define HAVE_GETUID 1
  105. +#define HAVE_INTMAX_T 1
  106. +#define HAVE_INTTYPES_H 1
  107. +#define HAVE_INTTYPES_H_WITH_UINTMAX 1
  108. +#define HAVE_ISBLANK 1
  109. +#define HAVE_ISNAND_IN_LIBC 1
  110. +#define HAVE_ISNANF_IN_LIBC 1
  111. +#define HAVE_ISNANL_IN_LIBC 1
  112. +#define HAVE_ISWCNTRL 1
  113. +#define HAVE_ISWCTYPE 1
  114. +#define HAVE_LANGINFO_CODESET 1
  115. +#define HAVE_LANGINFO_H 1
  116. +#define HAVE_LDEXPL_IN_LIBC 1
  117. +#define HAVE_LDEXP_IN_LIBC 1
  118. +#define HAVE_LIBINTL_H 1
  119. +#define HAVE_LIMITS_H 1
  120. +#define HAVE_LINK 1
  121. +#define HAVE_LONG_LONG_INT 1
  122. +#define HAVE_LSTAT 1
  123. +#define HAVE_MALLOC_H 1
  124. +#define HAVE_MALLOC_POSIX 1
  125. +#define HAVE_MAP_ANONYMOUS 1
  126. +#define HAVE_MATH_H 1
  127. +#define HAVE_MBRTOWC 1
  128. +#define HAVE_MBSINIT 1
  129. +#define HAVE_MBSTATE_T 1
  130. +#define HAVE_MBTOWC 1
  131. +#define HAVE_MEMORY_H 1
  132. +#define HAVE_MINMAX_IN_SYS_PARAM_H 1
  133. +#define HAVE_MKDTEMP 1
  134. +#define HAVE_MKSTEMP 1
  135. +#define HAVE_MPROTECT 1
  136. +#define HAVE_NL_LANGINFO 1
  137. +#define HAVE_PIPE 1
  138. +#define HAVE_PIPE2 1
  139. +#define HAVE_POSIX_SPAWN 1
  140. +#define HAVE_POSIX_SPAWNATTR_T 1
  141. +#define HAVE_POSIX_SPAWN_FILE_ACTIONS_T 1
  142. +#define HAVE_PTHREAD_MUTEX_RECURSIVE 1
  143. +#define HAVE_PTHREAD_RWLOCK 1
  144. +#define HAVE_RAISE 1
  145. +#define HAVE_RAWMEMCHR 1
  146. +#define HAVE_READLINK 1
  147. +#define HAVE_REALPATH 1
  148. +#define HAVE_SECURE_GETENV 1
  149. +#define HAVE_SETRLIMIT 1
  150. +#define HAVE_SIGACTION 1
  151. +#define HAVE_SIGALTSTACK 1
  152. +#define HAVE_SIGINTERRUPT 1
  153. +#define HAVE_SIGSET_T 1
  154. +#define HAVE_SIG_ATOMIC_T 1
  155. +#define HAVE_SNPRINTF 0
  156. +#define HAVE_SNPRINTF_RETVAL_C99 1
  157. +#define HAVE_SPAWN_H 1
  158. +#define HAVE_STACK_OVERFLOW_HANDLING 1
  159. +#define HAVE_STACK_T 1
  160. +#define HAVE_STDINT_H 1
  161. +#define HAVE_STDINT_H_WITH_UINTMAX 1
  162. +#define HAVE_STDLIB_H 1
  163. +#define HAVE_STRCHRNUL 1
  164. +#define HAVE_STRERROR_R 1
  165. +#define HAVE_STRINGS_H 1
  166. +#define HAVE_STRING_H 1
  167. +#define HAVE_STRNDUP 1
  168. +#define HAVE_STRNLEN 1
  169. +#define HAVE_STRSIGNAL 1
  170. +#define HAVE_STRUCT_SIGACTION_SA_SIGACTION 1
  171. +#define HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC 1
  172. +#define HAVE_SYMLINK 1
  173. +#define HAVE_SYS_CDEFS_H 1
  174. +#define HAVE_SYS_MMAN_H 1
  175. +#define HAVE_SYS_PARAM_H 1
  176. +#define HAVE_SYS_SOCKET_H 1
  177. +#define HAVE_SYS_STAT_H 1
  178. +#define HAVE_SYS_TIME_H 1
  179. +#define HAVE_SYS_TYPES_H 1
  180. +#define HAVE_SYS_WAIT_H 1
  181. +#define HAVE_TOWLOWER 1
  182. +#define HAVE_UCONTEXT_H 0
  183. +#define HAVE_UNISTD_H 1
  184. +#define HAVE_UNSIGNED_LONG_LONG_INT 1
  185. +#define HAVE_VAR___PROGNAME 1
  186. +#define HAVE_VASPRINTF 1
  187. +#define HAVE_WAITID 1
  188. +#define HAVE_WCHAR_H 1
  189. +#define HAVE_WCHAR_T 1
  190. +#define HAVE_WCRTOMB 1
  191. +#define HAVE_WCSLEN 1
  192. +#define HAVE_WCSNLEN 1
  193. +#define HAVE_WCTYPE_H 1
  194. +#define HAVE_WINT_T 1
  195. +#define HAVE_WORKING_O_NOATIME 0
  196. +#define HAVE_WORKING_O_NOFOLLOW 1
  197. +#define HAVE__BOOL 1
  198. +#define HAVE___BUILTIN_EXPECT 1
  199. +#define HAVE___FPURGE 1
  200. +#define HAVE___FREADING 1
  201. +#define HAVE___INLINE 1
  202. +#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
  203. +#define MALLOC_0_IS_NONNULL 1
  204. +# define __USE_MINGW_ANSI_STDIO 1
  205. +#define PROMOTED_MODE_T mode_t
  206. +#define SIGNAL_SAFE_LIST 1
  207. +#define STDC_HEADERS 1
  208. +#define TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC 1
  209. +#define USER_LABEL_PREFIX
  210. +#define USE_POSIX_THREADS 1
  211. +#define USE_POSIX_THREADS_WEAK 1
  212. +# define _ALL_SOURCE 1
  213. +# define _DARWIN_C_SOURCE 1
  214. +# define _GNU_SOURCE 1
  215. +# define _NETBSD_SOURCE 1
  216. +# define _OPENBSD_SOURCE 1
  217. +# define _POSIX_PTHREAD_SEMANTICS 1
  218. +# define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1
  219. +# define __STDC_WANT_IEC_60559_BFP_EXT__ 1
  220. +# define __STDC_WANT_IEC_60559_DFP_EXT__ 1
  221. +# define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1
  222. +# define __STDC_WANT_IEC_60559_TYPES_EXT__ 1
  223. +# define __STDC_WANT_LIB_EXT2__ 1
  224. +# define __STDC_WANT_MATH_SPEC_FUNCS__ 1
  225. +# define _TANDEM_SOURCE 1
  226. +# define _HPUX_ALT_XOPEN_SOCKET_API 1
  227. +# define __EXTENSIONS__ 1
  228. +#define USE_UNLOCKED_IO 0
  229. +#define _DARWIN_USE_64_BIT_INODE 1
  230. +#define _NETBSD_SOURCE 1
  231. +#define _REGEX_INCLUDE_LIMITS_H 1
  232. +#define _REGEX_LARGE_OFFSETS 1
  233. +#define _USE_STD_STAT 1
  234. +#define re_comp rpl_re_comp
  235. +#define re_compile_fastmap rpl_re_compile_fastmap
  236. +#define re_compile_pattern rpl_re_compile_pattern
  237. +#define re_exec rpl_re_exec
  238. +#define re_match rpl_re_match
  239. +#define re_match_2 rpl_re_match_2
  240. +#define re_search rpl_re_search
  241. +#define re_search_2 rpl_re_search_2
  242. +#define re_set_registers rpl_re_set_registers
  243. +#define re_set_syntax rpl_re_set_syntax
  244. +#define re_syntax_options rpl_re_syntax_options
  245. +#define regcomp rpl_regcomp
  246. +#define regerror rpl_regerror
  247. +#define regexec rpl_regexec
  248. +#define regfree rpl_regfree
  249. +#define restrict __restrict
  250. +
  251. +{GNULIB_CONFIG_FOOTER}
  252. diff --git a/m4/internal/gnulib/gnulib.BUILD b/m4/internal/gnulib/gnulib.BUILD
  253. index b3d3e1c..16bdb8f 100644
  254. --- a/m4/internal/gnulib/gnulib.BUILD
  255. +++ b/m4/internal/gnulib/gnulib.BUILD
  256. @@ -23,6 +23,9 @@ cc_library(
  257. "@bazel_tools//src/conditions:windows": [
  258. "config-windows/config.h",
  259. ],
  260. + "@bazel_tools//src/conditions:freebsd": [
  261. + "config-freebsd/config.h",
  262. + ],
  263. "//conditions:default": [
  264. "config-linux/config.h",
  265. ],
  266. @@ -34,6 +37,9 @@ cc_library(
  267. "@bazel_tools//src/conditions:windows": [
  268. "config-windows",
  269. ],
  270. + "@bazel_tools//src/conditions:freebsd": [
  271. + "config-freebsd",
  272. + ],
  273. "//conditions:default": [
  274. "config-linux",
  275. ],
  276. @@ -48,6 +54,12 @@ cc_library(
  277. deps = [":config_h"],
  278. )
  279. +cc_library(
  280. + name = "maybe_alloca_h",
  281. + hdrs = ["maybe-alloca/alloca.h"],
  282. + includes = ["maybe-alloca"],
  283. +)
  284. +
  285. _GNULIB_HDRS = glob([
  286. "lib/*.h",
  287. "lib/glthread/*.h",
  288. @@ -215,6 +227,7 @@ cc_library(
  289. visibility = ["//:__pkg__"],
  290. deps = [":config_h"] + select({
  291. "@bazel_tools//src/conditions:windows": [":gnulib_windows_shims"],
  292. + "@bazel_tools//src/conditions:freebsd": [":maybe_alloca_h"],
  293. "//conditions:default": [],
  294. }),
  295. )
  296. diff --git a/m4/internal/gnulib/gnulib.bzl b/m4/internal/gnulib/gnulib.bzl
  297. index 85d19d9..10aa0a0 100644
  298. --- a/m4/internal/gnulib/gnulib.bzl
  299. +++ b/m4/internal/gnulib/gnulib.bzl
  300. @@ -97,6 +97,10 @@ def gnulib_overlay(ctx, m4_version, extra_copts = []):
  301. "{GNULIB_CONFIG_HEADER}": config_header,
  302. "{GNULIB_CONFIG_FOOTER}": _CONFIG_FOOTER,
  303. }, executable = False)
  304. + ctx.template("gnulib/config-freebsd/config.h", ctx.attr._gnulib_config_freebsd_h, substitutions = {
  305. + "{GNULIB_CONFIG_HEADER}": config_header,
  306. + "{GNULIB_CONFIG_FOOTER}": _CONFIG_FOOTER,
  307. + }, executable = False)
  308. for shim in _WINDOWS_STDLIB_SHIMS:
  309. in_h = "gnulib/lib/{}.in.h".format(shim.replace("/", "_"))
  310. @@ -145,6 +149,20 @@ static const char * _replaced_get_charset_aliases (void)
  311. "SIGSTKSZ": "GNULIB_SIGSTKSZ",
  312. })
  313. + # Some platforms have alloca() but in <stdlib.h>
  314. + ctx.file(
  315. + "gnulib/maybe-alloca/alloca.h",
  316. + content =
  317. + """
  318. + #if defined(__GLIBC__)
  319. + #include_next <alloca.h>
  320. + #else
  321. + #include <stdlib.h>
  322. + #endif
  323. + """,
  324. + executable = False,
  325. + )
  326. +
  327. _WINDOWS_STDLIB_SHIMS = [
  328. "alloca",
  329. "errno",
  330. diff --git a/m4/internal/repository.bzl b/m4/internal/repository.bzl
  331. index c668d8c..3a8363f 100644
  332. --- a/m4/internal/repository.bzl
  333. +++ b/m4/internal/repository.bzl
  334. @@ -146,5 +146,9 @@ m4_repository = repository_rule(
  335. default = "//m4/internal:gnulib/config-windows.h",
  336. allow_single_file = True,
  337. ),
  338. + "_gnulib_config_freebsd_h": attr.label(
  339. + default = "//m4/internal:gnulib/config-freebsd.h",
  340. + allow_single_file = True,
  341. + ),
  342. },
  343. )
  344. --
  345. 2.38.1