aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/m4/.yandex_meta/__init__.py
blob: 36977f99c686c89f86372364349529b4347e2bc0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import os
import itertools

from devtools.yamaker.modules import GLOBAL, Linkable, Switch
from devtools.yamaker import pathutil
from devtools.yamaker.project import NixProject


WINDOWS_SRCS = [
    "close.c",
    "dup2.c",
    "error.c",
    "float+.h",
    "fpending.c",
    "fseeko.c",
    "getdtablesize.c",
    "getopt.c",
    "getopt1.c",
    "getopt_int.h",
    "gettimeofday.c",
    "isnand-nolibm.h",
    "isnanf-nolibm.h",
    "isnanl-nolibm.h",
    "localeconv.c",
    "mkdtemp.c",
    "msvc-inval.c",
    "msvc-inval.h",
    "msvc-nothrow.c",
    "msvc-nothrow.h",
    "nl_langinfo.c",
    "obstack.c",
    "raise.c",
    "regex.c",
    "regex.h",
    "sigaction.c",
    "siglist.h",
    "sigprocmask.c",
    "strsignal.c",
    "w32spawn.h",
    "waitpid.c",
]

DARWIN_SRCS = [
    "error.c",
    "fpending.c",
    "obstack.c",
    "regex.c",
    "secure_getenv.c",
]

EXCESSIVE_SRCS = [
    "alloca.h",
    "asprintf.c",
    "fflush.c",
    "fpurge.c",
    "fseek.c",
    "freading.c",
    "langinfo.h",
    "limits.h",
    "locale.h",
    "math.h",
    "signal.h",
    "spawn.h",
    "stdio.h",
    "stdlib.h",
    "string.h",
    "sys/stat.h",
    "sys/time.h",
    "sys/types.h",
    "sys/wait.h",
    "time.h",
    "unistd.h",
    "wchar.h",
    "wctype.h",
]

MUSL_SRCS = [
    "error.c",
    "obstack.c",
    "regex.c",
]


def post_install(self):

    with self.yamakes["lib"] as gnulib:
        gnulib.SRCS.remove("freadahead.c")
        gnulib.SRCS.remove("fseeko.c")

        # Provide sys/random.h implementations which is used disregarding HAVE_SYS_RANDOM configuration value
        gnulib.PEERDIR.add("contrib/libs/libc_compat")

        gnulib.after(
            "SRCS",
            Switch(
                MUSL=Linkable(
                    SRCS=[src for src in MUSL_SRCS if pathutil.is_source(src)],
                ),
                OS_WINDOWS=Linkable(
                    SRCS=[src for src in WINDOWS_SRCS if pathutil.is_source(src)],
                    ADDINCL=[GLOBAL(f"{self.arcdir}/lib/platform/win64")],
                ),
                OS_DARWIN=Linkable(
                    SRCS=[src for src in DARWIN_SRCS if pathutil.is_source(src)],
                ),
            ),
        )

        gnulib.after(
            "SRCS",
            """
            IF (NOT MUSL)
                SRCS(
                    freadahead.c
                )
            ENDIF()
            """,
        )

        for src in WINDOWS_SRCS:
            if pathutil.is_source(src) and src in gnulib.SRCS:
                gnulib.SRCS.remove(src)

        for src in EXCESSIVE_SRCS:
            os.remove(f"{self.dstdir}/lib/{src}")
            if pathutil.is_source(src):
                gnulib.SRCS.remove(src)


m4 = NixProject(
    arcdir="contrib/tools/m4",
    owners=["g:cpp-contrib"],
    nixattr="m4",
    ignore_commands=[
        "bash",
        "cat",
        "sed",
    ],
    # fmt: off
    copy_sources=[
        # these are included from regex.c and should not be added into SRCS
        "lib/intprops.h",
        "lib/regcomp.c",
        "lib/regex_internal.c",
        "lib/regex_internal.h",
        "lib/regexec.c",
    ] + [f"lib/{src}" for src in itertools.chain(WINDOWS_SRCS, DARWIN_SRCS)],
    # fmt: on
    use_full_libnames=True,
    install_targets=[
        "libm4",
        "m4",
    ],
    keep_paths=[
        "lib/platform/win64/*.h",
        "lib/platform/win64/sys/*.h",
        # Keep this for now, these were backported from the future
        "lib/fpending.c",
        "lib/freadahead.c",
        "lib/fseeko.c",
        "lib/stdio-impl.h",
    ],
    platform_dispatchers=[
        "lib/config.h",
        "lib/configmake.h",
    ],
    disable_includes=[
        "InnoTekLIBC/backend.h",
        "bits/libc-lock.h",
        "gettextP.h",
        "lc-charset-dispatch.h",
        "libc-lock.h",
        "libio/",
        "localename-table.h",
        "locale/",
        "../locale/localeinfo.h",
        "OS.h",
        "os2.h",
        "os2-spawn.h",
        "mbtowc-lock.h",
        "mbrtowc-impl.h",
        "relocatable.h",
        "sigsegv.h",
        "streq.h",
        "synch.h",
        "sys/ps.h",
        "sys/single_threaded.h",
        "unistring-notinline.h",
        "vasprintf.h",
    ],
    put={
        "libm4": "lib",
        "m4": ".",
    },
    post_install=post_install,
)

m4.copy_top_sources_except |= {
    "ABOUT-NLS",
    "ChangeLog",
    "ChangeLog-2014",
}