summaryrefslogtreecommitdiff
path: root/m4/fptools_set_platform_vars.m4
blob: 4c022da52b0e4507f05dc7a64c8cbb80c971491f (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
# FPTOOLS_SET_PLATFORMS_VARS
# ----------------------------------
# Set all the platform variables. First massage the default autoconf
# choices for build, host, and target, then parse it into
# <platform>Arch, <platform>Vendor, and <platform>OS, and finally define
# the other variables in terms of those.
AC_DEFUN([FPTOOLS_SET_PLATFORMS_VARS],
[
    # If no argument was given for a configuration variable, then discard
    # the guessed canonical system and use the configuration of the
    # bootstrapping ghc. If an argument was given, map it from gnu format
    # to ghc format.
    #
    # For why we do it this way, see: #3637, #1717, #2951
    #
    # In bindists, we haven't called AC_CANONICAL_{BUILD,HOST,TARGET}
    # so this justs uses $bootstrap_target.

    if test "$build_alias" = ""
    then
        FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP([build], [Build])
    else
        GHC_CONVERT_PLATFORM_PARTS([build], [Build])
    fi

    if test "$host_alias" = ""
    then
        FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP([host], [Host])
    else
        GHC_CONVERT_PLATFORM_PARTS([host], [Host])
    fi

    if test "$target_alias" = ""
    then
        if test "$host_alias" != ""
        then
            GHC_CONVERT_PLATFORM_PARTS([host], [Target])
        else
            FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP([target], [Target])
        fi
    else
        GHC_CONVERT_PLATFORM_PARTS([target], [Target])
    fi

    FPTOOLS_SET_PLATFORM_VARS([build], [Build])
    FPTOOLS_SET_PLATFORM_VARS([host], [Host])
    FPTOOLS_SET_PLATFORM_VARS([target], [Target])

    windows=NO
    case $host in
    *-unknown-mingw32)
        windows=YES
        ;;
    esac
])

dnl Attempt at arch agnostic distillation of the above, but it
dnl doesn't quite work yet. Perhaps after the configure script is
dnl more split up (#17191) this wil become more feasible.

dnl if test "[$]$1_alias" = ""
dnl then
dnl     if test "[$]$3_alias" != ""
dnl     then
dnl         GHC_CONVERT_PLATFORM_PARTS($3, $2)
dnl     else
dnl         FPTOOLS_SET_PLATFORMS_VARS($1, $2)
dnl     fi
dnl else
dnl     GHC_CONVERT_PLATFORM_PARTS($1, $2)
dnl fi

# FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP(platform,Platform)
# ----------------------------------
# Per the comment in FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP's body, we
# need to sometimes replace inferred platforms with the bootstrap
# compiler's target platform.
AC_DEFUN([FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP],
[
    if test "$bootstrap_target" != ""
    then
        $1=$bootstrap_target
        echo "$1 platform inferred as: [$]$1"
    else
        echo "Can't work out $1 platform"
        exit 1
    fi

    $2[Arch]=`echo "[$]$1" | sed 's/-.*//'`
    $2[Vendor]=`echo "[$]$1" | sed -e 's/.*-\(.*\)-.*/\1/'`
    $2[OS]=`echo "[$]$1" | sed 's/.*-//'`
])

# FPTOOLS_SET_PLATFORM_VARS(platform,Platform)
# ----------------------------------
# Set the platform variables for a single plaform (one of build, host,
# or target). Assumes <platform>Arch, <platform>Vendor, and <platform>OS
# are defined, and does everything else in terms of them.
AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS],
[

    $2Platform="[$]$2Arch-[$]$2Vendor-[$]$2OS"
    $2Platform_CPP=`echo "[$]$2Platform" | sed -e 's/\./_/g' -e 's/-/_/g'`
    $2Arch_CPP=`    echo "[$]$2Arch"     | sed -e 's/\./_/g' -e 's/-/_/g'`
    $2Vendor_CPP=`  echo "[$]$2Vendor"   | sed -e 's/\./_/g' -e 's/-/_/g'`
    $2OS_CPP=`      echo "[$]$2OS"       | sed -e 's/\./_/g' -e 's/-/_/g'`

    AC_MSG_NOTICE([GHC ]$1[ : $]$2[Platform])

    AC_SUBST($2Platform)
    AC_SUBST($2Platform_CPP)

    AC_SUBST($2Arch_CPP)
    AC_SUBST($2OS_CPP)
    AC_SUBST($2Vendor_CPP)

    GHC_SELECT_FILE_EXTENSIONS([$]$1, [exeext_]$1, [soext_]$1)

    AC_SUBST(exeext_$1)
    AC_SUBST(soext_$1)
])