Update autoconf test for gcc to require 4.7 and up
[ghc.git] / distrib / configure.ac.in
1 dnl
2 dnl Binary distribution configure script
3 dnl
4 #!/bin/sh
5 #
6
7 AC_INIT([The Glorious Glasgow Haskell Compilation System], [@ProjectVersion@], [glasgow-haskell-bugs@haskell.org], [ghc-AC_PACKAGE_VERSION])
8
9 dnl--------------------------------------------------------------------
10 dnl * Deal with arguments telling us gmp is somewhere odd
11 dnl--------------------------------------------------------------------
12
13 FP_GMP
14
15 dnl Various things from the source distribution configure
16 bootstrap_target=@TargetPlatform@
17
18 HaskellHaveRTSLinker=@HaskellHaveRTSLinker@
19 AC_SUBST(HaskellHaveRTSLinker)
20
21 FFIIncludeDir=@FFIIncludeDir@
22 FFILibDir=@FFILibDir@
23 AC_SUBST(FFILibDir)
24 AC_SUBST(FFIIncludeDir)
25
26
27 # We have to run these unconditionally as FPTOOLS_SET_PLATFORM_VARS wants the
28 # values it computes.
29 AC_CANONICAL_BUILD
30 AC_CANONICAL_HOST
31 AC_CANONICAL_TARGET
32
33 FPTOOLS_SET_PLATFORM_VARS
34
35 # Requires FPTOOLS_SET_PLATFORM_VARS to be run first.
36 FP_FIND_ROOT
37
38 # ToDo: if Stage1Only=YES, should be YES
39 CrossCompiling=NO
40 CrossCompilePrefix=""
41 TargetPlatformFull="${target}"
42
43 AC_SUBST(CrossCompiling)
44 AC_SUBST(CrossCompilePrefix)
45 AC_SUBST(TargetPlatformFull)
46
47 Unregisterised="@Unregisterised@"
48 AC_SUBST(Unregisterised)
49
50 #
51 dnl ** Check Perl installation **
52 #
53 AC_PATH_PROG(PerlCmd,perl)
54 if test -z "$PerlCmd"; then
55    echo "You must install perl before you can continue"
56    echo "Perhaps it is already installed, but not in your PATH?"
57    exit 1
58 fi
59
60 #
61 dnl ** figure out how to do a BSD-ish install **
62 #
63 AC_PROG_INSTALL
64
65 #
66 dnl ** find `find`, used by get-win32-tarballs.sh (see #12502)
67 #
68 FP_PROG_FIND()
69 export FIND
70
71 #
72 dnl ** how to do symlinks **
73 #
74 AC_PROG_LN_S()
75
76 #
77 dnl ** Find the path to sed **
78 #
79 AC_PATH_PROG(SedCmd,gsed sed,sed)
80
81 XCODE_VERSION()
82
83 dnl ** Which gcc to use?
84 dnl --------------------------------------------------------------
85 AC_PROG_CC([gcc clang])
86
87 # --with-hs-cpp/--with-hs-cpp-flags
88 FP_CPP_CMD_WITH_ARGS(HaskellCPPCmd, HaskellCPPArgs)
89 AC_SUBST([HaskellCPPCmd])
90 AC_SUBST([HaskellCPPArgs])
91
92 # Here is where we re-target which specific version of the LLVM
93 # tools we are looking for. In the past, GHC supported a number of
94 # versions of LLVM simultaneously, but that stopped working around
95 # 3.5/3.6 release of LLVM.
96 LlvmVersion=@LlvmVersion@
97
98 dnl ** Which LLVM llc to use?
99 dnl --------------------------------------------------------------
100 FIND_LLVM_PROG([LLC], [llc], [$LlvmVersion])
101 LlcCmd="$LLC"
102 AC_SUBST([LlcCmd])
103
104 dnl ** Which LLVM opt to use?
105 dnl --------------------------------------------------------------
106 FIND_LLVM_PROG([OPT], [opt], [$LlvmVersion])
107 OptCmd="$OPT"
108 AC_SUBST([OptCmd])
109
110 FP_GCC_VERSION
111 FP_GCC_SUPPORTS_NO_PIE
112 AC_PROG_CPP
113
114 dnl ** Check gcc version and flags we need to pass it **
115 FP_GCC_EXTRA_FLAGS
116
117 FP_SET_CFLAGS_C99([CC],[CFLAGS],[CPPFLAGS])
118 dnl FP_SET_CFLAGS_C99([CC_STAGE0],[CONF_CC_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
119 FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
120 FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
121
122 FPTOOLS_SET_C_LD_FLAGS([target],[CFLAGS],[LDFLAGS],[IGNORE_LINKER_LD_FLAGS],[CPPFLAGS])
123 FPTOOLS_SET_C_LD_FLAGS([build],[CONF_CC_OPTS_STAGE0],[CONF_GCC_LINKER_OPTS_STAGE0],[CONF_LD_LINKER_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
124 FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE1],[CONF_GCC_LINKER_OPTS_STAGE1],[CONF_LD_LINKER_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
125 # Stage 3 won't be supported by cross-compilation
126 FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE2],[CONF_GCC_LINKER_OPTS_STAGE2],[CONF_LD_LINKER_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
127
128 AC_SUBST(CONF_CC_OPTS_STAGE0)
129 AC_SUBST(CONF_CC_OPTS_STAGE1)
130 AC_SUBST(CONF_CC_OPTS_STAGE2)
131 AC_SUBST(CONF_GCC_LINKER_OPTS_STAGE0)
132 AC_SUBST(CONF_GCC_LINKER_OPTS_STAGE1)
133 AC_SUBST(CONF_GCC_LINKER_OPTS_STAGE2)
134 AC_SUBST(CONF_LD_LINKER_OPTS_STAGE0)
135 AC_SUBST(CONF_LD_LINKER_OPTS_STAGE1)
136 AC_SUBST(CONF_LD_LINKER_OPTS_STAGE2)
137 AC_SUBST(CONF_CPP_OPTS_STAGE0)
138 AC_SUBST(CONF_CPP_OPTS_STAGE1)
139 AC_SUBST(CONF_CPP_OPTS_STAGE2)
140
141 dnl ** Which ld to use?
142 dnl --------------------------------------------------------------
143 FIND_LD([$target],[GccUseLdOpt])
144 CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt"
145 CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt"
146 LdCmd="$LD"
147 CFLAGS="$CFLAGS $GccUseLdOpt"
148 AC_SUBST([LdCmd])
149
150 FP_PROG_LD_IS_GNU
151 FP_PROG_LD_BUILD_ID
152 FP_PROG_LD_NO_COMPACT_UNWIND
153 FP_PROG_LD_FILELIST
154
155 dnl ** Set up the variables for the platform in the settings file.
156 dnl May need to use gcc to find platform details.
157 dnl --------------------------------------------------------------
158 FPTOOLS_SET_HASKELL_PLATFORM_VARS
159
160 dnl TargetWordSize for settings.in
161 AC_CHECK_SIZEOF(void *, 4)
162 if test "x$ac_cv_sizeof_void_p" = "x0"; then
163     AC_MSG_ERROR([Failed to determine machine word size. Does your toolchain actually work?])
164 fi
165 dnl Check that the toolchain we have is consistent with what the compiler expects
166 if test "x$ac_cv_sizeof_void_p" != "x@TargetWordSize@"; then
167     AC_MSG_ERROR([This binary distribution produces binaries for a target with
168                   word size of @TargetWordSize@, but your target toolchain produces binaries
169                   with a word size of $ac_cv_sizeof_void_p. Are you sure your toolchain
170                   targets the intended target platform of this compiler?])
171 fi
172 TargetWordSize=$ac_cv_sizeof_void_p
173 AC_SUBST(TargetWordSize)
174
175 #
176 dnl ** how to invoke `ar' and `ranlib'
177 #
178 FP_PROG_AR_SUPPORTS_ATFILE
179 FP_PROG_AR_NEEDS_RANLIB
180
181 dnl ** which strip to use?
182 dnl --------------------------------------------------------------
183 AC_CHECK_TARGET_TOOL([STRIP], [strip])
184 StripCmd="$STRIP"
185 AC_SUBST([StripCmd])
186
187 dnl ** Have libdw?
188 dnl --------------------------------------------------------------
189 dnl Check for a usable version of libdw/elfutils
190 dnl Currently we need 0.158 or newer.
191 BinDistNeedsLibdw=@UseLibdw@
192 if test "x$BinDistNeedsLibdw" = "xYES" ; then
193   AC_CHECK_LIB(dw, dwfl_attach_state,
194     [UseLibdw=YES],
195     [AC_MSG_ERROR([Binary distribution was built with libdw support but target system doesn't have supported libdw version (needs at least 0.158)])]
196   )
197 fi
198
199 FP_SETTINGS
200
201 #
202 AC_CONFIG_FILES(settings mk/config.mk mk/install.mk)
203 AC_OUTPUT
204
205 # We get caught by
206 #     http://savannah.gnu.org/bugs/index.php?1516
207 #     $(eval ...) inside conditionals causes errors
208 # with make 3.80, so warn the user if it looks like they're about to
209 # try to use it.
210 # We would use "grep -q" here, but Solaris's grep doesn't support it.
211 checkMake380() {
212     if $1 --version 2>&1 | head -1 | grep 'GNU Make 3\.80' > /dev/null
213     then
214         echo
215         echo "WARNING: It looks like \"$1\" is GNU make 3.80."
216         echo "This version cannot be used to build GHC."
217         echo "Please use GNU make >= 3.81."
218     fi
219 }
220
221 checkMake380 make
222 checkMake380 gmake
223
224 echo "****************************************************"
225 echo "Configuration done, ready to 'make install'"
226 echo "(see README and INSTALL files for more info.)"
227 echo "****************************************************"