summaryrefslogtreecommitdiff
path: root/m4/fptools_set_haskell_platform_vars.m4
blob: 9c0c5e052bd5bacc8a356ba35412f09d4c7018e0 (plain)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS
# ----------------------------------
# Drop in shell functions used by FPTOOLS_SET_HASKELL_PLATFORM_VARS
AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS],
[
    checkArch() {
        case [$]1 in
        i386)
            test -z "[$]2" || eval "[$]2=ArchX86"
            ;;
        x86_64|amd64)
            test -z "[$]2" || eval "[$]2=ArchX86_64"
            ;;
        powerpc)
            test -z "[$]2" || eval "[$]2=ArchPPC"
            ;;
        powerpc64)
            test -z "[$]2" || eval "[$]2=\"ArchPPC_64 ELF_V1\""
            ;;
        powerpc64le)
            test -z "[$]2" || eval "[$]2=\"ArchPPC_64 ELF_V2\""
            ;;
        s390x)
            test -z "[$]2" || eval "[$]2=ArchS390X"
            ;;
        arm)
            GET_ARM_ISA()
            test -z "[$]2" || eval "[$]2=\"ArchARM \$ARM_ISA \$ARM_ISA_EXT \$ARM_ABI\""
            ;;
        aarch64)
            test -z "[$]2" || eval "[$]2=ArchAArch64"
            ;;
        alpha)
            test -z "[$]2" || eval "[$]2=ArchAlpha"
            ;;
        mips|mipseb)
            test -z "[$]2" || eval "[$]2=ArchMipseb"
            ;;
        mipsel)
            test -z "[$]2" || eval "[$]2=ArchMipsel"
            ;;
        riscv64)
            test -z "[$]2" || eval "[$]2=ArchRISCV64"
            ;;
        wasm32)
            test -z "[$]2" || eval "[$]2=ArchWasm32"
            ;;
        loongarch64)
            test -z "[$]2" || eval "[$]2=ArchLoongArch64"
            ;;
        hppa|hppa1_1|ia64|m68k|nios2|riscv32|loongarch32|rs6000|s390|sh4|vax)
            test -z "[$]2" || eval "[$]2=ArchUnknown"
            ;;
        javascript)
            test -z "[$]2" || eval "[$]2=ArchJavaScript"
            ;;
        *)
            echo "Unknown arch [$]1"
            exit 1
            ;;
        esac
    }

    checkVendor() {
        case [$]1 in
        dec|none|unknown|hp|apple|next|sun|sgi|ibm|montavista|portbld|alpine)
            ;;
        *)
            AC_MSG_WARN([Unknown vendor [$]1])
            ;;
        esac
    }

    checkOS() {
        case [$]1 in
        linux|linux-android)
            test -z "[$]2" || eval "[$]2=OSLinux"
            ;;
        darwin|ios|watchos|tvos)
            test -z "[$]2" || eval "[$]2=OSDarwin"
            ;;
        solaris2)
            test -z "[$]2" || eval "[$]2=OSSolaris2"
            ;;
        mingw32|windows)
            test -z "[$]2" || eval "[$]2=OSMinGW32"
            ;;
        freebsd)
            test -z "[$]2" || eval "[$]2=OSFreeBSD"
            ;;
        dragonfly)
            test -z "[$]2" || eval "[$]2=OSDragonFly"
            ;;
        kfreebsdgnu)
            test -z "[$]2" || eval "[$]2=OSKFreeBSD"
            ;;
        openbsd)
            test -z "[$]2" || eval "[$]2=OSOpenBSD"
            ;;
        netbsd)
            test -z "[$]2" || eval "[$]2=OSNetBSD"
            ;;
        haiku)
            test -z "[$]2" || eval "[$]2=OSHaiku"
            ;;
        nto-qnx)
            test -z "[$]2" || eval "[$]2=OSQNXNTO"
            ;;
        wasi)
            test -z "[$]2" || eval "[$]2=OSWasi"
            ;;
        dragonfly|hpux|linuxaout|freebsd2|nextstep2|nextstep3|sunos4|ultrix)
            test -z "[$]2" || eval "[$]2=OSUnknown"
            ;;
        aix)
            test -z "[$]2" || eval "[$]2=OSAIX"
            ;;
        gnu)
            test -z "[$]2" || eval "[$]2=OSHurd"
            ;;
        ghcjs|js)
            test -z "[$]2" || eval "[$]2=OSGhcjs"
            ;;
        *)
            echo "Unknown OS '[$]1'"
            exit 1
            ;;
        esac
    }
])

# Note [autoconf assembler checks and -flto]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Autoconf's AC_COMPILE_IFELSE macro is fragile in the case of checks
# which require that the assembler is run. Specifically, GCC does not run
# the assembler if invoked with `-c -flto`; it merely dumps its internal
# AST to the object file, to be compiled and assembled during the final
# link.
#
# This can cause configure checks like that for the
# .subsections_via_symbols directive to pass unexpected (see #16440),
# leading the build system to incorrectly conclude that the directive is
# supported.
#
# For this reason, it is important that configure checks that rely on the
# assembler failing use AC_LINK_IFELSE rather than AC_COMPILE_IFELSE,
# ensuring that the assembler sees the check.

# GHC_SUBSECTIONS_VIA_SYMBOLS
# ----------------------------------
# check for Apple-style dead-stripping support
# (.subsections-via-symbols assembler directive)
AC_DEFUN([GHC_SUBSECTIONS_VIA_SYMBOLS],
[
    AC_MSG_CHECKING(for .subsections_via_symbols)
    dnl See Note [autoconf assembler checks and -flto]
    AC_LINK_IFELSE(
        [AC_LANG_PROGRAM([], [__asm__ (".subsections_via_symbols");])],
        [AC_MSG_RESULT(yes)
         if test x"$TargetArch" = xaarch64; then
            dnl subsections via symbols is busted on arm64
            TargetHasSubsectionsViaSymbols=NO
         else
            TargetHasSubsectionsViaSymbols=YES
            AC_DEFINE([HAVE_SUBSECTIONS_VIA_SYMBOLS],[1],
                   [Define to 1 if Apple-style dead-stripping is supported.])
         fi
        ],
        [TargetHasSubsectionsViaSymbols=NO
         AC_MSG_RESULT(no)])
])

# GHC_IDENT_DIRECTIVE
# ----------------------------------
# check for .ident assembler directive
AC_DEFUN([GHC_IDENT_DIRECTIVE],
[
    AC_MSG_CHECKING(whether your assembler supports .ident directive)
    dnl See Note [autoconf assembler checks and -flto]
    AC_LINK_IFELSE(
        [AC_LANG_PROGRAM([__asm__ (".ident \"GHC x.y.z\"");], [])],
        [AC_MSG_RESULT(yes)
         TargetHasIdentDirective=YES],
        [AC_MSG_RESULT(no)
         TargetHasIdentDirective=NO])
])

# GHC_GNU_NONEXEC_STACK
# ----------------------------------
# *** check for GNU non-executable stack note support (ELF only)
#     (.section .note.GNU-stack,"",@progbits)
#
# This test doesn't work with "gcc -g" in gcc 4.4 (GHC trac #3889:
#     Error: can't resolve `.note.GNU-stack' {.note.GNU-stack section} - `.Ltext0' {.text section}
# so we empty CFLAGS while running this test
AC_DEFUN([GHC_GNU_NONEXEC_STACK],
[
    CFLAGS2="$CFLAGS"
    CFLAGS=
    case $TargetArch in
      arm)
        dnl See #13937.
        progbits="%progbits"
        ;;
      *)
        progbits="@progbits"
        ;;
    esac
    AC_MSG_CHECKING(for GNU non-executable stack support)
    dnl See Note [autoconf assembler checks and -flto]
    AC_LINK_IFELSE(
       dnl the `main` function is placed after the .note.GNU-stack directive
       dnl so we need to ensure that the active segment is correctly set,
       dnl otherwise `main` will be placed in the wrong segment.
        [AC_LANG_PROGRAM([
           __asm__ (".section .note.GNU-stack,\"\",$progbits");
           __asm__ (".section .text");
         ], [0])],
        [AC_MSG_RESULT(yes)
         TargetHasGnuNonexecStack=YES],
        [AC_MSG_RESULT(no)
         TargetHasGnuNonexecStack=NO])
    CFLAGS="$CFLAGS2"
])

# FPTOOLS_SET_HASKELL_PLATFORM_VARS
# ----------------------------------
# Set the Haskell platform variables
AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
[
    AC_REQUIRE([FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS])
    checkArch "[$]$1Arch" "Haskell$1Arch"
    checkVendor "[$]$1Vendor"
    checkOS "[$]$1OS" "Haskell$1Os"
])