Fix Control.Arrow (***) diagram (fixes #25698)
[ghc.git] / m4 / prep_target_file.m4
blobbcce8883be12b5e7303522745795777c717ab1db
1 # Note [Preparing variables for GHC.Toolchain.Target]
2 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 # In configure, we generate default.target and default.host.target files that
4 # contain a value of the Haskell type GHC.Toolchain.Target.Target.
6 # Since we substitute in those files with configured variables, we have to
7 # preparate them as Haskell values, for example, turning YES/NO into
8 # True,False, or empty variables into Nothing or Just something otherwise.
10 # This toolchain will additionally be used to validate the one generated by
11 # ghc-toolchain. See Note [ghc-toolchain consistency checking].
13 # PREP_MAYBE_SIMPLE_PROGRAM
14 # =========================
16 # Issue a substitution of [$1MaybeProg] with
17 # * Nothing, if $1 is empty
18 # * Just (Program {prgPath = "$$1", prgFlags = []}), otherwise
20 # $1 = optional value
21 AC_DEFUN([PREP_MAYBE_SIMPLE_PROGRAM],[
22     if test -z "$$1"; then
23         $1MaybeProg=Nothing
24     else
25         $1MaybeProg="Just (Program {prgPath = \"$$1\", prgFlags = @<:@@:>@})"
26     fi
27     AC_SUBST([$1MaybeProg])
30 # PREP_MAYBE_STRING
31 # =========================
33 # Issue a substitution of [$1MaybeStr] with
34 # * Nothing, if $1 is empty
35 # * Just "$$1", otherwise
37 # $1 = optional value
38 AC_DEFUN([PREP_MAYBE_STRING],[
39     if test -z "$$1"; then
40         $1MaybeStr=Nothing
41     else
42         $1MaybeStr="Just \"$$1\""
43     fi
44     AC_SUBST([$1MaybeStr])
47 # PREP_BOOLEAN
48 # ============
50 # Issue a substitution with True/False of [$1Bool] when $1 has YES/NO value
51 # $1 = boolean variable to substitute
52 AC_DEFUN([PREP_BOOLEAN],[
53     case "$$1" in
54         YES)
55           $1Bool=True
56           ;;
57         NO)
58           $1Bool=False
59           ;;
60         *)
61           AC_MSG_WARN([m4/prep_target_file.m4: Expecting YES/NO but got $$1 in $1. Defaulting to False.])
62           $1Bool=False
63           ;;
64     esac
65     AC_SUBST([$1Bool])
68 # PREP_NOT_BOOLEAN
69 # ============
71 # Issue a substitution with True/False of [Not$1Bool] when $1 has NO/YES value
72 # $1 = boolean variable to substitute
73 AC_DEFUN([PREP_NOT_BOOLEAN],[
74     case "$$1" in
75         NO)
76           Not$1Bool=True
77           ;;
78         YES)
79           Not$1Bool=False
80           ;;
81         *)
82           AC_MSG_WARN([m4/prep_target_file.m4: Expecting YES/NO but got $$1 in $1. Defaulting to False.])
83           Not$1Bool=False
84           ;;
85     esac
86     AC_SUBST([Not$1Bool])
89 # PREP_LIST
90 # ============
92 # Issue a substitution with ["list","of","args"] of [$1List] when $1 is a
93 # space-separated list of args
94 # i.e.
95 # "arg1 arg2 arg3"
96 # ==>
97 # ["arg1","arg2","arg3"]
99 # $1 = list variable to substitute
100 dnl In autoconf, '@<:@' stands for '[', and '@:>@' for ']'.
101 AC_DEFUN([PREP_LIST],[
102     # shell array
103     set -- $$1
104     $1List="@<:@"
105     if test "[$]#" -eq 0; then
106         # no arguments
107         true
108     else
109         $1List="${$1List}\"[$]1\""
110         shift # drop first elem
111         for arg in "[$]@"
112         do
113             $1List="${$1List},\"$arg\""
114         done
115     fi
116     $1List="${$1List}@:>@"
118     AC_SUBST([$1List])
121 # Eventually: PREP_BUILD_TARGET_FILE, PREP_HOST_TARGET_FILE, PREP_TARGET_TARGET_FILE
122 # Prepares required substitutions to generate the target file
123 AC_DEFUN([PREP_TARGET_FILE],[
125     dnl Target target
126     PREP_BOOLEAN([MergeObjsSupportsResponseFiles])
127     PREP_BOOLEAN([TargetHasGnuNonexecStack])
128     PREP_BOOLEAN([LeadingUnderscore])
129     PREP_BOOLEAN([ArSupportsAtFile])
130     PREP_BOOLEAN([ArSupportsDashL])
131     PREP_BOOLEAN([TargetHasIdentDirective])
132     PREP_BOOLEAN([CONF_GCC_SUPPORTS_NO_PIE])
133     PREP_BOOLEAN([LdHasFilelist])
134     PREP_BOOLEAN([LdHasSingleModule])
135     PREP_BOOLEAN([LdIsGNULd])
136     PREP_BOOLEAN([LdHasNoCompactUnwind])
137     PREP_BOOLEAN([TargetHasSubsectionsViaSymbols])
138     PREP_BOOLEAN([Unregisterised])
139     PREP_BOOLEAN([TablesNextToCode])
140     PREP_BOOLEAN([UseLibffiForAdjustors])
141     PREP_BOOLEAN([ArIsGNUAr])
142     PREP_BOOLEAN([ArNeedsRanLib])
143     PREP_NOT_BOOLEAN([CrossCompiling])
144     PREP_LIST([MergeObjsArgs])
145     PREP_LIST([ArArgs])
146     PREP_LIST([CONF_GCC_LINKER_OPTS_STAGE2])
147     PREP_LIST([HaskellCPPArgs])
148     PREP_LIST([JavaScriptCPPArgs])
149     PREP_LIST([CmmCPPArgs])
150     PREP_LIST([CmmCPPArgs_STAGE0])
151     PREP_MAYBE_SIMPLE_PROGRAM([WindresCmd])
152     PREP_MAYBE_STRING([TargetVendor_CPP])
153     PREP_MAYBE_STRING([HostVendor_CPP])
154     PREP_LIST([CONF_CPP_OPTS_STAGE2])
155     PREP_LIST([CONF_CXX_OPTS_STAGE2])
156     PREP_LIST([CONF_CC_OPTS_STAGE2])
158     dnl Host target
159     PREP_BOOLEAN([ArSupportsAtFile_STAGE0])
160     PREP_BOOLEAN([ArSupportsDashL_STAGE0])
161     PREP_LIST([AR_OPTS_STAGE0])
162     PREP_LIST([CONF_CC_OPTS_STAGE0])
163     PREP_LIST([CONF_CPP_OPTS_STAGE0])
164     PREP_LIST([CONF_CXX_OPTS_STAGE0])
165     PREP_LIST([CONF_GCC_LINKER_OPTS_STAGE0])
168     if test -z "$MergeObjsCmd"; then
169       MergeObjsCmdMaybe=Nothing
170     else
171       MergeObjsCmdMaybe="Just (MergeObjs {mergeObjsProgram = Program {prgPath = \"$MergeObjsCmd\", prgFlags = $MergeObjsArgsList}, mergeObjsSupportsResponseFiles = $MergeObjsSupportsResponseFilesBool})"
172     fi
173     AC_SUBST([MergeObjsCmdMaybe])
175     dnl PREP_ENDIANNESS
176     case "$TargetWordBigEndian" in
177         YES)
178             TargetEndianness=BigEndian
179             ;;
180         NO)
181             TargetEndianness=LittleEndian
182             ;;
183         *)
184             AC_MSG_ERROR([m4/prep_target_file.m4: Expecting YES/NO but got $TargetWordBigEndian in TargetWordBigEndian])
185             ;;
186     esac
187     AC_SUBST([TargetEndianness])
190 AC_DEFUN()