__init__.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import os
  2. import itertools
  3. from devtools.yamaker.modules import GLOBAL, Linkable, Switch
  4. from devtools.yamaker import pathutil
  5. from devtools.yamaker.project import NixProject
  6. WINDOWS_SRCS = [
  7. "close.c",
  8. "dup2.c",
  9. "error.c",
  10. "float+.h",
  11. "fpending.c",
  12. "fseeko.c",
  13. "getdtablesize.c",
  14. "getopt.c",
  15. "getopt1.c",
  16. "getopt_int.h",
  17. "gettimeofday.c",
  18. "isnand-nolibm.h",
  19. "isnanf-nolibm.h",
  20. "isnanl-nolibm.h",
  21. "localeconv.c",
  22. "mkdtemp.c",
  23. "msvc-inval.c",
  24. "msvc-inval.h",
  25. "msvc-nothrow.c",
  26. "msvc-nothrow.h",
  27. "nl_langinfo.c",
  28. "obstack.c",
  29. "raise.c",
  30. "regex.c",
  31. "regex.h",
  32. "sigaction.c",
  33. "siglist.h",
  34. "sigprocmask.c",
  35. "strsignal.c",
  36. "w32spawn.h",
  37. "waitpid.c",
  38. ]
  39. DARWIN_SRCS = [
  40. "error.c",
  41. "fpending.c",
  42. "obstack.c",
  43. "regex.c",
  44. "secure_getenv.c",
  45. ]
  46. EXCESSIVE_SRCS = [
  47. "alloca.h",
  48. "asprintf.c",
  49. "fflush.c",
  50. "fpurge.c",
  51. "fseek.c",
  52. "freading.c",
  53. "langinfo.h",
  54. "limits.h",
  55. "locale.h",
  56. "math.h",
  57. "signal.h",
  58. "spawn.h",
  59. "stdio.h",
  60. "stdlib.h",
  61. "string.h",
  62. "sys/stat.h",
  63. "sys/time.h",
  64. "sys/types.h",
  65. "sys/wait.h",
  66. "time.h",
  67. "unistd.h",
  68. "wchar.h",
  69. "wctype.h",
  70. ]
  71. MUSL_SRCS = [
  72. "error.c",
  73. "obstack.c",
  74. "regex.c",
  75. ]
  76. def post_install(self):
  77. with self.yamakes["lib"] as gnulib:
  78. gnulib.SRCS.remove("freadahead.c")
  79. gnulib.SRCS.remove("fseeko.c")
  80. # Provide sys/random.h implementations which is used disregarding HAVE_SYS_RANDOM configuration value
  81. gnulib.PEERDIR.add("contrib/libs/libc_compat")
  82. gnulib.after(
  83. "SRCS",
  84. Switch(
  85. MUSL=Linkable(
  86. SRCS=[src for src in MUSL_SRCS if pathutil.is_source(src)],
  87. ),
  88. OS_WINDOWS=Linkable(
  89. SRCS=[src for src in WINDOWS_SRCS if pathutil.is_source(src)],
  90. ADDINCL=[GLOBAL(f"{self.arcdir}/lib/platform/win64")],
  91. ),
  92. OS_DARWIN=Linkable(
  93. SRCS=[src for src in DARWIN_SRCS if pathutil.is_source(src)],
  94. ),
  95. ),
  96. )
  97. gnulib.after(
  98. "SRCS",
  99. """
  100. IF (NOT MUSL)
  101. SRCS(
  102. freadahead.c
  103. )
  104. ENDIF()
  105. """,
  106. )
  107. for src in WINDOWS_SRCS:
  108. if pathutil.is_source(src) and src in gnulib.SRCS:
  109. gnulib.SRCS.remove(src)
  110. for src in EXCESSIVE_SRCS:
  111. os.remove(f"{self.dstdir}/lib/{src}")
  112. if pathutil.is_source(src):
  113. gnulib.SRCS.remove(src)
  114. m4 = NixProject(
  115. arcdir="contrib/tools/m4",
  116. owners=["g:cpp-contrib"],
  117. nixattr="m4",
  118. ignore_commands=[
  119. "bash",
  120. "cat",
  121. "sed",
  122. ],
  123. # fmt: off
  124. copy_sources=[
  125. # these are included from regex.c and should not be added into SRCS
  126. "lib/intprops.h",
  127. "lib/regcomp.c",
  128. "lib/regex_internal.c",
  129. "lib/regex_internal.h",
  130. "lib/regexec.c",
  131. ] + [f"lib/{src}" for src in itertools.chain(WINDOWS_SRCS, DARWIN_SRCS)],
  132. # fmt: on
  133. use_full_libnames=True,
  134. install_targets=[
  135. "libm4",
  136. "m4",
  137. ],
  138. keep_paths=[
  139. "lib/platform/win64/*.h",
  140. "lib/platform/win64/sys/*.h",
  141. # Keep this for now, these were backported from the future
  142. "lib/fpending.c",
  143. "lib/freadahead.c",
  144. "lib/fseeko.c",
  145. "lib/stdio-impl.h",
  146. ],
  147. platform_dispatchers=[
  148. "lib/config.h",
  149. "lib/configmake.h",
  150. ],
  151. disable_includes=[
  152. "InnoTekLIBC/backend.h",
  153. "bits/libc-lock.h",
  154. "gettextP.h",
  155. "lc-charset-dispatch.h",
  156. "libc-lock.h",
  157. "libio/",
  158. "localename-table.h",
  159. "locale/",
  160. "../locale/localeinfo.h",
  161. "OS.h",
  162. "os2.h",
  163. "os2-spawn.h",
  164. "mbtowc-lock.h",
  165. "mbrtowc-impl.h",
  166. "relocatable.h",
  167. "sigsegv.h",
  168. "streq.h",
  169. "synch.h",
  170. "sys/ps.h",
  171. "sys/single_threaded.h",
  172. "unistring-notinline.h",
  173. "vasprintf.h",
  174. ],
  175. put={
  176. "libm4": "lib",
  177. "m4": ".",
  178. },
  179. post_install=post_install,
  180. )
  181. m4.copy_top_sources_except |= {
  182. "ABOUT-NLS",
  183. "ChangeLog",
  184. "ChangeLog-2014",
  185. }