]> git.saurik.com Git - apt.git/blame - buildlib/tools.m4
Bugs
[apt.git] / buildlib / tools.m4
CommitLineData
d7bccc73
AL
1# tl_CHECK_TOOL_PREFIX will work _BEFORE_ AC_CANONICAL_HOST, etc., has been
2# called. It should be called again after these have been called.
3#
4# Basically we want to check if the host alias specified by the user is
5# different from the build alias. The rules work like this:-
6#
7# If host is not specified, it defaults to NONOPT
8# If build is not specified, it defaults to NONOPT
9# If nonopt is not specified, we guess all other values
10
11dnl Replace AC_CHECK_TOOL_PREFIX
12undefine([AC_CHECK_TOOL_PREFIX])
13define([AC_CHECK_TOOL_PREFIX], [tl_CHECK_TOOL_PREFIX])
14
15AC_DEFUN(tl_CHECK_TOOL_PREFIX,
16[AC_PROVIDE([AC_CHECK_TOOL_PREFIX])
17AC_BEFORE([AC_CANONICAL_HOST])
18AC_BEFORE([AC_CANONICAL_BUILD])
19dnl Quick check
20if test "$host_alias" = ""; then
21 if test $host = NONE; then
22 thost=$nonopt
23 else
24 thost=$host
25 fi
26 if test $thost != $build -a $thost != NONE; then
27 ac_tool_prefix=${thost}-
28 ac_tool_dir=${thost}
29 else
30 ac_tool_prefix=
31 ac_tool_dir=
32 fi
33else
34 if test $host != $build; then
35 ac_tool_prefix=${host_alias}-
36 ac_tool_dir=${host_alias}
37 else
38 ac_tool_prefix=
39 ac_tool_dir=
40 fi
41fi
42])
43
44dnl replacement for AC_CHECK_TOOL
45undefine([AC_CHECK_TOOL])
46define([AC_CHECK_TOOL], [tl_CHECK_TOOL($1, $2, $3, $4)])
47
48dnl tl_CHECK_TOOL - AC_CHECK_TOOL, with a couple of extra checks
49dnl tl_CHECK_TOOL(VARIABLE, PROG-TO-CHECK-FOR[, VALUE-IF-NOT-FOUND [, PATH
50dnl [, REJECT]])
51AC_DEFUN(tl_CHECK_TOOL,
52[AC_REQUIRE([AC_CHECK_TOOL_PREFIX])
53AC_CHECK_PROG($1, ${ac_tool_prefix}$2, ${ac_tool_prefix}$2,
54 ifelse([$3], , [$2], ), $4, $5)
55if test -z "$ac_cv_prog_$1_dir";then ac_cv_prog_$1_dir=""; fi
56if test "$ac_tool_dir" != ""; then
57 if test -z "$ac_cv_prog_$1" -a "$5" != "/usr/${ac_tool_dir}/bin/$2" -a \
58 "$5" != "/usr/local/${ac_tool_dir}/bin/$2"; then
59 if test -f /usr/${ac_tool_dir}/bin/$2; then $1="/usr/${ac_tool_dir}/bin/$2"; ac_cv_prog_$1_dir=/usr/${ac_tool_dir}
60 elif test -f /usr/local/${ac_tool_dir}/bin/$2; then $1="/usr/local/${ac_tool_dir}/bin/$2"; ac_cv_prog_$1_dir=/usr/local/${ac_tool_dir}
61 fi
62 fi
63fi
64ifelse([$3], , , [
65if test -z "$ac_cv_prog_$1"; then
66if test -n "$ac_tool_prefix"; then
67 AC_CHECK_PROG($1, $2, $2, $3, $4, $5)
68else
69 $1="$3"
70fi
71fi])
72])
73
74dnl tl_CHECK_TOOLS -
75dnl do a tl_CHECK_TOOL for multiple tools (like AC_CHECK_PROGS)
76dnl tl_CHECK_TOOLS(VARIABLE, PROGS-TO-CHECK-FOR [, VALUE-IF-NOT-FOUND
77dnl [, PATH]])
78AC_DEFUN(tl_CHECK_TOOLS,
79[for ac_tool in $2
80do
81tl_CHECK_TOOL($1, [$]ac_tool, [$]ac_tool, , $4)
82test -n "[$]$1" && break
83done
84ifelse([$3], , , [test -n "[$]$1" || $1="$3"
85])])
86
87dnl replace AC_PROG_CC and AC_PROG_CXX
88undefine([AC_PROG_CC])
89define([AC_PROG_CC], [tl_PROG_CC])
90undefine([AC_PROG_CXX])
91define([AC_PROG_CXX], [tl_PROG_CXX])
92
93dnl tl_PROG_CC, tl_PROG_CXX - same as old AC_PROG_CC and AC_PROG_CXX, but
94dnl use AC_CHECK_TOOL/tl_CHECK_TOOLS instead of AC_CHECK_PROG, etc.
95AC_DEFUN(tl_PROG_CC,
96[AC_BEFORE([$0], [AC_PROG_CPP])dnl
97AC_PROVIDE([AC_PROG_CC])dnl
98tl_CHECK_TOOL(CC, gcc, gcc)
99if test -z "$CC"; then
100 AC_CHECK_TOOL(CC, cc, cc, , , /usr/ucb/cc)
101 test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
102fi
103if test -n "$ac_tool_prefix" -a "`echo $CC | grep '$ac_tool_prefix'`" = "" \
104 -a "`echo $CC | grep -- '-b'`" = ""; then
105 if test -z "$ac_cv_prog_CC_dir" && $CC -v 2>&1 | grep -q gcc; then
106 AC_CACHE_CHECK([if $CC -b${ac_tool_dir} works], tl_cv_prog_cc_bhost,[
107 old_cc="${CC}"
108 CC="${CC} -b${ac_tool_dir}"
109 AC_LANG_SAVE
110 AC_LANG_C
111 AC_TRY_COMPILER([main(){return(0);}], tl_cv_prog_cc_bhost, ac_cv_prog_cc_cross)
112 AC_LANG_RESTORE])
113 if test $tl_cv_prog_cc_bhost = "yes"; then
114 ac_cv_prog_cc_works=yes
115 cctest=yes
116 else
117 CC="${old_cc}"
118 fi
119 fi
120fi
121
122if test "$cctest" != "yes"; then
123 tl_PROG_CC_WORKS
124fi
125AC_PROG_CC_GNU
126
127if test $ac_cv_prog_gcc = yes; then
128 GCC=yes
129dnl Check whether -g works, even if CFLAGS is set, in case the package
130dnl plays around with CFLAGS (such as to build both debugging and
131dnl normal versions of a library), tasteless as that idea is.
132 ac_test_CFLAGS="${CFLAGS+set}"
133 ac_save_CFLAGS="$CFLAGS"
134 CFLAGS=
135 AC_PROG_CC_G
136 if test "$ac_test_CFLAGS" = set; then
137 CFLAGS="$ac_save_CFLAGS"
138 elif test $ac_cv_prog_cc_g = yes; then
139 CFLAGS="-g -O2"
140 else
141 CFLAGS="-O2"
142 fi
143else
144 GCC=
145 test "${CFLAGS+set}" = set || CFLAGS="-g"
146fi
147])
148
149AC_DEFUN(tl_PROG_CXX,
150[AC_BEFORE([$0], [AC_PROG_CXXCPP])dnl
151AC_PROVIDE([AC_PROG_CXX])dnl
152tl_CHECK_TOOLS(CXX, $CCC c++ g++ gcc CC cxx cc++, gcc)
153if test -n "$CXX"; then
154 if test -n "$ac_tool_prefix" -a "`echo $CXX | grep '$ac_tool_prefix'`" = "" \
155 -a "`echo $CXX | grep -- '-b'`" = ""; then
156 if test -z "$ac_cv_prog_CXX_dir" && $CXX -v 2>&1 | grep -q gcc; then
157 AC_CACHE_CHECK([if $CXX -b${ac_tool_dir} works], tl_cv_prog_cxx_bhost,[
158 old_cxx="${CXX}"
159 CXX="${CXX} -b${ac_tool_dir}"
160 AC_LANG_SAVE
161 AC_LANG_CPLUSPLUS
162 AC_TRY_COMPILER([main(){return(0);}], tl_cv_prog_cxx_bhost, ac_cv_prog_cxx_cross)
163 AC_LANG_RESTORE])
164 if test $tl_cv_prog_cxx_bhost = "yes"; then
165 ac_cv_prog_cxx_works=yes
166 cxxtest=yes
167 else
168 CXX="${old_cxx}"
169 fi
170 fi
171 fi
172
173 if test "$cxxtest" != "yes"; then
174 tl_PROG_CXX_WORKS
175 fi
176 AC_PROG_CXX_GNU
177
178 if test $ac_cv_prog_gxx = yes; then
179 GXX=yes
180dnl Check whether -g works, even if CXXFLAGS is set, in case the package
181dnl plays around with CXXFLAGS (such as to build both debugging and
182dnl normal versions of a library), tasteless as that idea is.
183 ac_test_CXXFLAGS="${CXXFLAGS+set}"
184 ac_save_CXXFLAGS="$CXXFLAGS"
185 CXXFLAGS=
186 AC_PROG_CXX_G
187 if test "$ac_test_CXXFLAGS" = set; then
188 CXXFLAGS="$ac_save_CXXFLAGS"
189 elif test $ac_cv_prog_cxx_g = yes; then
190 CXXFLAGS="-g -O2"
191 else
192 CXXFLAGS="-O2"
193 fi
194 else
195 GXX=
196 test "${CXXFLAGS+set}" = set || CXXFLAGS="-g"
197 fi
198fi
199])
200
201AC_DEFUN(tl_PROG_CC_WORKS,
202[AC_PROVIDE(AC_PROG_CC_WORKS)
203AC_CACHE_CHECK([whether the C compiler ($CC $CFLAGS $LDFLAGS) works],
204 ac_cv_prog_cc_works, [
205AC_LANG_SAVE
206AC_LANG_C
207AC_TRY_COMPILER([main(){return(0);}], ac_cv_prog_cc_works, ac_cv_prog_cc_cross)
208AC_LANG_RESTORE
209if test $ac_cv_prog_cc_works = no; then
210 AC_MSG_ERROR([installation or configuration problem: C compiler cannot create executables.])
211fi])
212AC_MSG_CHECKING([whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler])
213AC_MSG_RESULT($ac_cv_prog_cc_cross)
214cross_compiling=$ac_cv_prog_cc_cross
215])
216
217AC_DEFUN(tl_PROG_CXX_WORKS,
218[AC_PROVIDE(AC_PROG_CXX_WORKS)
219AC_CACHE_CHECK([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works],
220 ac_cv_prog_cxx_works, [
221AC_LANG_SAVE
222AC_LANG_CPLUSPLUS
223AC_TRY_COMPILER([main(){return(0);}], ac_cv_prog_cxx_works, ac_cv_prog_cxx_cross)
224AC_LANG_RESTORE
225if test $ac_cv_prog_cxx_works = no; then
226 AC_MSG_ERROR([installation or configuration problem: C++ compiler cannot create executables.])
227fi])
228AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler])
229AC_MSG_RESULT($ac_cv_prog_cxx_cross)
230cross_compiling=$ac_cv_prog_cxx_cross
231])