Autoconf: detect and set CFLAGS/CPPFLAGS needed for C99 mode
[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])
8
9 dnl--------------------------------------------------------------------
10 dnl * Deal with arguments telling us gmp is somewhere odd
11 dnl--------------------------------------------------------------------
12
13 FP_GMP
14
15 bootstrap_target=@TargetPlatform@
16 FPTOOLS_SET_PLATFORM_VARS
17
18 # Requires FPTOOLS_SET_PLATFORM_VARS to be run first.
19 FP_FIND_ROOT
20
21 # ToDo: if Stage1Only=YES, should be YES
22 CrossCompiling=NO
23 CrossCompilePrefix=""
24 TargetPlatformFull="${target}"
25
26 AC_SUBST(CrossCompiling)
27 AC_SUBST(CrossCompilePrefix)
28 AC_SUBST(TargetPlatformFull)
29
30 Unregisterised="@Unregisterised@"
31 AC_SUBST(Unregisterised)
32
33 #
34 dnl ** Check Perl installation **
35 #
36 AC_PATH_PROG(PerlCmd,perl)
37 if test -z "$PerlCmd"; then
38    echo "You must install perl before you can continue"
39    echo "Perhaps it is already installed, but not in your PATH?"
40    exit 1
41 fi
42
43 #
44 dnl ** figure out how to do a BSD-ish install **
45 #
46 AC_PROG_INSTALL
47
48 #
49 dnl ** how to do symlinks **
50 #
51 AC_PROG_LN_S()
52
53 #
54 dnl ** Find the path to sed **
55 #
56 AC_PATH_PROG(SedCmd,gsed sed,sed)
57
58 XCODE_VERSION()
59
60 dnl ** Which gcc to use?
61 dnl --------------------------------------------------------------
62 FIND_GCC([WhatGccIsCalled], [gcc], [gcc])
63 CC="$WhatGccIsCalled"
64 export CC
65
66 # --with-hs-cpp/--with-hs-cpp-flags
67 FP_CPP_CMD_WITH_ARGS(HaskellCPPCmd, HaskellCPPArgs)
68 AC_SUBST([HaskellCPPCmd])
69 AC_SUBST([HaskellCPPArgs])
70
71 # Here is where we re-target which specific version of the LLVM
72 # tools we are looking for. In the past, GHC supported a number of
73 # versions of LLVM simultaneously, but that stopped working around
74 # 3.5/3.6 release of LLVM.
75 LlvmVersion=@LlvmVersion@
76
77 dnl ** Which LLVM llc to use?
78 dnl --------------------------------------------------------------
79 FIND_LLVM_PROG([LLC], [llc], [llc], [$LlvmVersion])
80 LlcCmd="$LLC"
81 AC_SUBST([LlcCmd])
82
83 dnl ** Which LLVM opt to use?
84 dnl --------------------------------------------------------------
85 FIND_LLVM_PROG([OPT], [opt], [opt], [$LlvmVersion])
86 OptCmd="$OPT"
87 AC_SUBST([OptCmd])
88
89 dnl ** Which ld to use?
90 dnl --------------------------------------------------------------
91 FIND_LD([LdCmd])
92 AC_SUBST([LdCmd])
93
94 dnl ** Have libdw?
95 dnl --------------------------------------------------------------
96 AC_CHECK_LIB(dw, dwfl_begin, [HaveLibdw=YES], [HaveLibdw=NO])
97 AC_SUBST(HaveLibdw)
98
99 FP_GCC_VERSION
100 AC_PROG_CPP
101
102 FP_PROG_LD_IS_GNU
103 FP_PROG_LD_BUILD_ID
104 FP_PROG_LD_NO_COMPACT_UNWIND
105 FP_PROG_LD_FILELIST
106
107 #
108 dnl ** Check gcc version and flags we need to pass it **
109 #
110 FP_GCC_EXTRA_FLAGS
111
112 FP_SET_CFLAGS_C99([CC],[CFLAGS],[CPPFLAGS])
113 dnl FP_SET_CFLAGS_C99([CC_STAGE0],[CONF_CC_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
114 FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
115 FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
116
117 FPTOOLS_SET_C_LD_FLAGS([target],[CFLAGS],[LDFLAGS],[IGNORE_LINKER_LD_FLAGS],[CPPFLAGS])
118 FPTOOLS_SET_C_LD_FLAGS([build],[CONF_CC_OPTS_STAGE0],[CONF_GCC_LINKER_OPTS_STAGE0],[CONF_LD_LINKER_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
119 FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE1],[CONF_GCC_LINKER_OPTS_STAGE1],[CONF_LD_LINKER_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
120 # Stage 3 won't be supported by cross-compilation
121 FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE2],[CONF_GCC_LINKER_OPTS_STAGE2],[CONF_LD_LINKER_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
122
123 AC_SUBST(CONF_CC_OPTS_STAGE0)
124 AC_SUBST(CONF_CC_OPTS_STAGE1)
125 AC_SUBST(CONF_CC_OPTS_STAGE2)
126 AC_SUBST(CONF_GCC_LINKER_OPTS_STAGE0)
127 AC_SUBST(CONF_GCC_LINKER_OPTS_STAGE1)
128 AC_SUBST(CONF_GCC_LINKER_OPTS_STAGE2)
129 AC_SUBST(CONF_LD_LINKER_OPTS_STAGE0)
130 AC_SUBST(CONF_LD_LINKER_OPTS_STAGE1)
131 AC_SUBST(CONF_LD_LINKER_OPTS_STAGE2)
132 AC_SUBST(CONF_CPP_OPTS_STAGE0)
133 AC_SUBST(CONF_CPP_OPTS_STAGE1)
134 AC_SUBST(CONF_CPP_OPTS_STAGE2)
135
136 dnl ** Set up the variables for the platform in the settings file.
137 dnl May need to use gcc to find platform details.
138 dnl --------------------------------------------------------------
139 FPTOOLS_SET_HASKELL_PLATFORM_VARS
140
141 dnl WordSize for settings.in
142 AC_CHECK_SIZEOF(void *, 4)
143 WordSize=$ac_cv_sizeof_void_p
144 AC_SUBST(WordSize)
145
146 #
147 dnl ** how to invoke `ar' and `ranlib'
148 #
149 FP_PROG_AR_SUPPORTS_ATFILE
150 FP_PROG_AR_NEEDS_RANLIB
151
152 FP_SETTINGS
153
154 #
155 AC_CONFIG_FILES(settings mk/config.mk mk/install.mk)
156 AC_OUTPUT
157
158 # We get caught by
159 #     http://savannah.gnu.org/bugs/index.php?1516
160 #     $(eval ...) inside conditionals causes errors
161 # with make 3.80, so warn the user if it looks like they're about to
162 # try to use it.
163 # We would use "grep -q" here, but Solaris's grep doesn't support it.
164 checkMake380() {
165     if $1 --version 2>&1 | head -1 | grep 'GNU Make 3\.80' > /dev/null
166     then
167         echo
168         echo "WARNING: It looks like \"$1\" is GNU make 3.80."
169         echo "This version cannot be used to build GHC."
170         echo "Please use GNU make >= 3.81."
171     fi
172 }
173
174 checkMake380 make
175 checkMake380 gmake
176
177 echo "****************************************************"
178 echo "Configuration done, ready to 'make install'"
179 echo "(see README and INSTALL files for more info.)"
180 echo "****************************************************"