__init__.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import os
  2. from devtools.yamaker.modules import Linkable, Switch
  3. from devtools.yamaker.project import NixProject
  4. # libidn contains some weird proxy headers
  5. # intended to emulate glibc compatibility layer.
  6. #
  7. # This headers make use of non-standard include_next statement,
  8. # thus breaking the MSVC build.
  9. # Some of these files are licensed under GPL license, which is non-acceptable.
  10. #
  11. # They will be removed during post_install
  12. GLIBC_EMULATION_HEADERS = (
  13. "gl/fcntl.h",
  14. "gl/limits.h",
  15. "gl/progname.h",
  16. "gl/stddef.h",
  17. "gl/stdio.h",
  18. "gl/stdlib.h",
  19. "gl/string.h",
  20. "gl/sys/stat.h",
  21. "gl/sys/types.h",
  22. "gl/time.h",
  23. "gl/version-etc.h",
  24. "gl/unistd.h",
  25. "lib/gl/limits.h",
  26. "lib/gl/langinfo.h",
  27. "lib/gl/stddef.h",
  28. "lib/gl/stdlib.h",
  29. "lib/gl/string.h",
  30. "lib/gl/sys/types.h",
  31. "lib/gl/unistd.h",
  32. )
  33. GLIBC_EMULATION_SOURCES = (
  34. "gl/cloexec.c",
  35. "gl/fcntl.c",
  36. "gl/unistd.c",
  37. "gl/progname.c",
  38. "gl/version-etc.c",
  39. "lib/gl/unistd.c",
  40. )
  41. LINUX_SPECIFIC_SRCS = [
  42. "gl/getprogname.c",
  43. ]
  44. WINDOWS_SPECIFIC_SRCS = [
  45. "gl/getprogname.c",
  46. "lib/gl/strverscmp.c",
  47. ]
  48. def post_install(self):
  49. # libidn.map bears GPL-3.0 license and thus can not be used
  50. os.remove(f"{self.dstdir}/lib/libidn.map")
  51. with self.yamakes["static"] as libidn:
  52. # Drop the stuff that breaks Windows build
  53. for src in GLIBC_EMULATION_HEADERS:
  54. os.remove(f"{self.dstdir}/{src}")
  55. for src in GLIBC_EMULATION_SOURCES:
  56. os.remove(f"{self.dstdir}/{src}")
  57. libidn.SRCS.remove(src)
  58. # Support Darwin.
  59. for src in LINUX_SPECIFIC_SRCS:
  60. libidn.SRCS.remove(src)
  61. libidn.after(
  62. "SRCS",
  63. Switch(
  64. OS_LINUX=Linkable(SRCS=LINUX_SPECIFIC_SRCS),
  65. OS_WINDOWS=Linkable(SRCS=WINDOWS_SPECIFIC_SRCS),
  66. ),
  67. )
  68. self.make_dll_dispatcher(
  69. switch_flag="USE_IDN",
  70. switch_as_enum=True,
  71. handle_local=True,
  72. default_local_flags={
  73. "CFLAGS": ("USE_LOCAL_IDN_CFLAGS",),
  74. "LDFLAGS": ("USE_LOCAL_IDN_LDFLAGS", "-lidn"),
  75. },
  76. exports_script="libidn.exports",
  77. before_switch="""
  78. IF(EXPORT_CMAKE)
  79. OPENSOURCE_EXPORT_REPLACEMENT(
  80. CMAKE IDN
  81. CMAKE_TARGET IDN::IDN
  82. )
  83. ENDIF()
  84. """,
  85. or_local_condition="EXPORT_CMAKE",
  86. )
  87. libidn = NixProject(
  88. owners=["g:cpp-contrib"],
  89. arcdir="contrib/libs/libidn",
  90. nixattr="libidn",
  91. ignore_commands=["bash", "sed", "cat"],
  92. inclink={
  93. "include": [
  94. "lib/idn-free.h",
  95. "lib/idn-int.h",
  96. "lib/idna.h",
  97. "lib/pr29.h",
  98. "lib/punycode.h",
  99. "lib/stringprep.h",
  100. "lib/tld.h",
  101. ]
  102. },
  103. addincl_global={"static": {"../include"}},
  104. install_targets=[
  105. "libidn",
  106. "libgnu",
  107. ],
  108. put={
  109. "libidn": "static",
  110. },
  111. put_with={
  112. "libidn": {"libgnu"},
  113. },
  114. disable_includes={
  115. "cheri.h",
  116. "getopt-cdefs.h",
  117. "getopt-pfx-core.h",
  118. "msvc-nothrow.h",
  119. "random.h",
  120. "sys/ps.h",
  121. # sys/random.h is not (yet) present in current version of glibc
  122. # just disable it, as it is not included anyway
  123. "sys/random.h",
  124. "unistring-notinline.h",
  125. },
  126. platform_dispatchers=("config.h",),
  127. keep_paths=["dynamic/libidn.exports"],
  128. copy_sources=("lib/gl/strverscmp.c", "lib/gl/libc-config.h", "lib/gl/cdefs.h"),
  129. post_install=post_install,
  130. use_full_libnames=True,
  131. )