summaryrefslogtreecommitdiff
path: root/m4/fptools_set_platform_vars.m4
blob: 185661a3dfd17b69f4afb7b971831b9d1c31db26 (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
# FPTOOLS_SET_PLATFORM_VARS
# ----------------------------------
# Set the platform variables
AC_DEFUN([FPTOOLS_SET_PLATFORM_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
        if test "$bootstrap_target" != ""
        then
            build=$bootstrap_target
            echo "Build platform inferred as: $build"
        else
            echo "Can't work out build platform"
            exit 1
        fi

        BuildArch=`echo "$build" | sed 's/-.*//'`
        BuildVendor=`echo "$build" | sed -e 's/.*-\(.*\)-.*/\1/'`
        BuildOS=`echo "$build" | sed 's/.*-//'`
    else
        GHC_CONVERT_CPU([$build_cpu], [BuildArch])
        GHC_CONVERT_VENDOR([$build_vendor], [BuildVendor])
        GHC_CONVERT_OS([$build_os], [$BuildArch], [BuildOS])
    fi

    if test "$host_alias" = ""
    then
        if test "$bootstrap_target" != ""
        then
            host=$bootstrap_target
            echo "Host platform inferred as: $host"
        else
            echo "Can't work out host platform"
            exit 1
        fi

        HostArch=`echo "$host" | sed 's/-.*//'`
        HostVendor=`echo "$host" | sed -e 's/.*-\(.*\)-.*/\1/'`
        HostOS=`echo "$host" | sed 's/.*-//'`
    else
        GHC_CONVERT_CPU([$host_cpu], [HostArch])
        GHC_CONVERT_VENDOR([$host_vendor], [HostVendor])
        GHC_CONVERT_OS([$host_os], [$HostArch], [HostOS])
    fi

    if test "$target_alias" = ""
    then
        if test "$host_alias" != ""
        then
            GHC_CONVERT_CPU([$host_cpu], [TargetArch])
            GHC_CONVERT_VENDOR([$host_vendor], [TargetVendor])
            GHC_CONVERT_OS([$host_os], [$TargetArch],[TargetOS])
        else
            if test "$bootstrap_target" != ""
            then
                target=$bootstrap_target
                echo "Target platform inferred as: $target"
            else
                echo "Can't work out target platform"
                exit 1
            fi

            TargetArch=`echo "$target" | sed 's/-.*//'`
            TargetVendor=`echo "$target" | sed -e 's/.*-\(.*\)-.*/\1/'`
            TargetOS=`echo "$target" | sed 's/.*-//'`
        fi
    else
        GHC_CONVERT_CPU([$target_cpu], [TargetArch])
        GHC_CONVERT_VENDOR([$target_vendor], [TargetVendor])
        GHC_CONVERT_OS([$target_os], [$TargetArch], [TargetOS])
    fi

    GHC_LLVM_TARGET([$target],[$target_cpu],[$target_vendor],[$target_os],[LlvmTarget])

    GHC_SELECT_FILE_EXTENSIONS([$host], [exeext_host], [soext_host])
    GHC_SELECT_FILE_EXTENSIONS([$target], [exeext_target], [soext_target])
    windows=NO
    case $host in
    *-unknown-mingw32)
        windows=YES
        ;;
    esac

    BuildPlatform="$BuildArch-$BuildVendor-$BuildOS"
    BuildPlatform_CPP=`echo "$BuildPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
    BuildArch_CPP=`    echo "$BuildArch"     | sed -e 's/\./_/g' -e 's/-/_/g'`
    BuildVendor_CPP=`  echo "$BuildVendor"   | sed -e 's/\./_/g' -e 's/-/_/g'`
    BuildOS_CPP=`      echo "$BuildOS"       | sed -e 's/\./_/g' -e 's/-/_/g'`

    HostPlatform="$HostArch-$HostVendor-$HostOS"
    HostPlatform_CPP=`echo "$HostPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
    HostArch_CPP=`    echo "$HostArch"     | sed -e 's/\./_/g' -e 's/-/_/g'`
    HostVendor_CPP=`  echo "$HostVendor"   | sed -e 's/\./_/g' -e 's/-/_/g'`
    HostOS_CPP=`      echo "$HostOS"       | sed -e 's/\./_/g' -e 's/-/_/g'`

    TargetPlatform="$TargetArch-$TargetVendor-$TargetOS"
    TargetPlatform_CPP=`echo "$TargetPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
    TargetArch_CPP=`    echo "$TargetArch"     | sed -e 's/\./_/g' -e 's/-/_/g'`
    TargetVendor_CPP=`  echo "$TargetVendor"   | sed -e 's/\./_/g' -e 's/-/_/g'`
    TargetOS_CPP=`      echo "$TargetOS"       | sed -e 's/\./_/g' -e 's/-/_/g'`

    # we intend to pass trough --targets to llvm as is.
    LLVMTarget_CPP=`    echo "$LlvmTarget"`

    echo "GHC build  : $BuildPlatform"
    echo "GHC host   : $HostPlatform"
    echo "GHC target : $TargetPlatform"
    echo "LLVM target: $LlvmTarget"

    AC_SUBST(BuildPlatform)
    AC_SUBST(HostPlatform)
    AC_SUBST(TargetPlatform)
    AC_SUBST(HostPlatform_CPP)
    AC_SUBST(BuildPlatform_CPP)
    AC_SUBST(TargetPlatform_CPP)

    AC_SUBST(HostArch_CPP)
    AC_SUBST(BuildArch_CPP)
    AC_SUBST(TargetArch_CPP)

    AC_SUBST(HostOS_CPP)
    AC_SUBST(BuildOS_CPP)
    AC_SUBST(TargetOS_CPP)
    AC_SUBST(LLVMTarget_CPP)

    AC_SUBST(HostVendor_CPP)
    AC_SUBST(BuildVendor_CPP)
    AC_SUBST(TargetVendor_CPP)

    AC_SUBST(exeext_host)
    AC_SUBST(exeext_target)
    AC_SUBST(soext_host)
    AC_SUBST(soext_target)
])