add some comments
[binutils-gdb.git] / bfd / acinclude.m4
1 dnl See whether we need to use fopen-bin.h rather than fopen-same.h.
2 AC_DEFUN(BFD_BINARY_FOPEN,
3 [AC_REQUIRE([AC_CANONICAL_SYSTEM])
4 case "${host}" in
5 changequote(,)dnl
6 i[345]86-*-msdos* | i[345]86-*-go32* | i[345]86-*-mingw32* | *-*-cygwin32* | *-*-windows)
7 changequote([,])dnl
8 AC_DEFINE(USE_BINARY_FOPEN) ;;
9 esac])dnl
10
11 dnl Get a default for CC_FOR_BUILD to put into Makefile.
12 AC_DEFUN(BFD_CC_FOR_BUILD,
13 [# Put a plausible default for CC_FOR_BUILD in Makefile.
14 if test -z "$CC_FOR_BUILD"; then
15 if test "x$cross_compiling" = "xno"; then
16 CC_FOR_BUILD='$(CC)'
17 else
18 CC_FOR_BUILD=gcc
19 fi
20 fi
21 AC_SUBST(CC_FOR_BUILD)
22 # Also set EXEEXT_FOR_BUILD.
23 if test "x$cross_compiling" = "xno"; then
24 EXEEXT_FOR_BUILD='$(EXEEXT)'
25 else
26 AC_CACHE_CHECK([for build system executable suffix], bfd_cv_build_exeext,
27 [cat > ac_c_test.c << 'EOF'
28 int main() {
29 /* Nothing needed here */
30 }
31 EOF
32 ${CC_FOR_BUILD} -o ac_c_test am_c_test.c 1>&5 2>&5
33 bfd_cv_build_exeext=`echo ac_c_test.* | grep -v ac_c_test.c | sed -e s/ac_c_test//`
34 rm -f ac_c_test*
35 test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no])
36 EXEEXT_FOR_BUILD=""
37 test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext}
38 fi
39 AC_SUBST(EXEEXT_FOR_BUILD)])dnl
40
41 dnl See whether we need a declaration for a function.
42 AC_DEFUN(BFD_NEED_DECLARATION,
43 [AC_MSG_CHECKING([whether $1 must be declared])
44 AC_CACHE_VAL(bfd_cv_decl_needed_$1,
45 [AC_TRY_COMPILE([
46 #include <stdio.h>
47 #ifdef HAVE_STRING_H
48 #include <string.h>
49 #else
50 #ifdef HAVE_STRINGS_H
51 #include <strings.h>
52 #endif
53 #endif
54 #ifdef HAVE_STDLIB_H
55 #include <stdlib.h>
56 #endif
57 #ifdef HAVE_UNISTD_H
58 #include <unistd.h>
59 #endif],
60 [char *(*pfn) = (char *(*)) $1],
61 bfd_cv_decl_needed_$1=no, bfd_cv_decl_needed_$1=yes)])
62 AC_MSG_RESULT($bfd_cv_decl_needed_$1)
63 if test $bfd_cv_decl_needed_$1 = yes; then
64 bfd_tr_decl=NEED_DECLARATION_`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
65 AC_DEFINE_UNQUOTED($bfd_tr_decl)
66 fi
67 ])dnl
68
69
70 # This file is derived from `gettext.m4'. The difference is that the
71 # included macros assume Cygnus-style source and build trees.
72
73 # Macro to add for using GNU gettext.
74 # Ulrich Drepper <drepper@cygnus.com>, 1995.
75 #
76 # This file file be copied and used freely without restrictions. It can
77 # be used in projects which are not available under the GNU Public License
78 # but which still want to provide support for the GNU gettext functionality.
79 # Please note that the actual code is *not* freely available.
80
81 # serial 3
82
83 AC_DEFUN(CY_WITH_NLS,
84 [AC_MSG_CHECKING([whether NLS is requested])
85 dnl Default is enabled NLS
86 AC_ARG_ENABLE(nls,
87 [ --disable-nls do not use Native Language Support],
88 USE_NLS=$enableval, USE_NLS=yes)
89 AC_MSG_RESULT($USE_NLS)
90 AC_SUBST(USE_NLS)
91
92 USE_INCLUDED_LIBINTL=no
93
94 dnl If we use NLS figure out what method
95 if test "$USE_NLS" = "yes"; then
96 AC_DEFINE(ENABLE_NLS)
97 AC_MSG_CHECKING([whether included gettext is requested])
98 AC_ARG_WITH(included-gettext,
99 [ --with-included-gettext use the GNU gettext library included here],
100 nls_cv_force_use_gnu_gettext=$withval,
101 nls_cv_force_use_gnu_gettext=no)
102 AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
103
104 nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
105 if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
106 dnl User does not insist on using GNU NLS library. Figure out what
107 dnl to use. If gettext or catgets are available (in this order) we
108 dnl use this. Else we have to fall back to GNU NLS library.
109 dnl catgets is only used if permitted by option --with-catgets.
110 nls_cv_header_intl=
111 nls_cv_header_libgt=
112 CATOBJEXT=NONE
113
114 AC_CHECK_HEADER(libintl.h,
115 [AC_CACHE_CHECK([for gettext in libc], gt_cv_func_gettext_libc,
116 [AC_TRY_LINK([#include <libintl.h>], [return (int) gettext ("")],
117 gt_cv_func_gettext_libc=yes, gt_cv_func_gettext_libc=no)])
118
119 if test "$gt_cv_func_gettext_libc" != "yes"; then
120 AC_CHECK_LIB(intl, bindtextdomain,
121 [AC_CACHE_CHECK([for gettext in libintl],
122 gt_cv_func_gettext_libintl,
123 [AC_TRY_LINK([], [return (int) gettext ("")],
124 gt_cv_func_gettext_libintl=yes,
125 gt_cv_func_gettext_libintl=no)])])
126 fi
127
128 if test "$gt_cv_func_gettext_libc" = "yes" \
129 || test "$gt_cv_func_gettext_libintl" = "yes"; then
130 AC_DEFINE(HAVE_GETTEXT)
131 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
132 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
133 if test "$MSGFMT" != "no"; then
134 AC_CHECK_FUNCS(dcgettext)
135 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
136 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
137 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
138 AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
139 return _nl_msg_cat_cntr],
140 [CATOBJEXT=.gmo
141 DATADIRNAME=share],
142 [CATOBJEXT=.mo
143 DATADIRNAME=lib])
144 INSTOBJEXT=.mo
145 fi
146 fi
147 ])
148
149 dnl In the standard gettext, we would now check for catgets.
150 dnl However, we never want to use catgets for our releases.
151
152 if test "$CATOBJEXT" = "NONE"; then
153 dnl Neither gettext nor catgets in included in the C library.
154 dnl Fall back on GNU gettext library.
155 nls_cv_use_gnu_gettext=yes
156 fi
157 fi
158
159 if test "$nls_cv_use_gnu_gettext" = "yes"; then
160 dnl Mark actions used to generate GNU NLS library.
161 INTLOBJS="\$(GETTOBJS)"
162 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
163 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt)
164 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
165 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
166 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
167 AC_SUBST(MSGFMT)
168 USE_INCLUDED_LIBINTL=yes
169 CATOBJEXT=.gmo
170 INSTOBJEXT=.mo
171 DATADIRNAME=share
172 INTLDEPS='$(top_builddir)/../intl/libintl.a'
173 INTLLIBS=$INTLDEPS
174 LIBS=`echo $LIBS | sed -e 's/-lintl//'`
175 nls_cv_header_intl=libintl.h
176 nls_cv_header_libgt=libgettext.h
177 fi
178
179 dnl Test whether we really found GNU xgettext.
180 if test "$XGETTEXT" != ":"; then
181 dnl If it is no GNU xgettext we define it as : so that the
182 dnl Makefiles still can work.
183 if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
184 : ;
185 else
186 AC_MSG_RESULT(
187 [found xgettext programs is not GNU xgettext; ignore it])
188 XGETTEXT=":"
189 fi
190 fi
191
192 # We need to process the po/ directory.
193 POSUB=po
194 else
195 DATADIRNAME=share
196 nls_cv_header_intl=libintl.h
197 nls_cv_header_libgt=libgettext.h
198 fi
199
200 # If this is used in GNU gettext we have to set USE_NLS to `yes'
201 # because some of the sources are only built for this goal.
202 if test "$PACKAGE" = gettext; then
203 USE_NLS=yes
204 USE_INCLUDED_LIBINTL=yes
205 fi
206
207 dnl These rules are solely for the distribution goal. While doing this
208 dnl we only have to keep exactly one list of the available catalogs
209 dnl in configure.in.
210 for lang in $ALL_LINGUAS; do
211 GMOFILES="$GMOFILES $lang.gmo"
212 POFILES="$POFILES $lang.po"
213 done
214
215 dnl Make all variables we use known to autoconf.
216 AC_SUBST(USE_INCLUDED_LIBINTL)
217 AC_SUBST(CATALOGS)
218 AC_SUBST(CATOBJEXT)
219 AC_SUBST(DATADIRNAME)
220 AC_SUBST(GMOFILES)
221 AC_SUBST(INSTOBJEXT)
222 AC_SUBST(INTLDEPS)
223 AC_SUBST(INTLLIBS)
224 AC_SUBST(INTLOBJS)
225 AC_SUBST(POFILES)
226 AC_SUBST(POSUB)
227 ])
228
229 AC_DEFUN(CY_GNU_GETTEXT,
230 [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
231 AC_REQUIRE([AC_PROG_CC])dnl
232 AC_REQUIRE([AC_PROG_RANLIB])dnl
233 AC_REQUIRE([AC_ISC_POSIX])dnl
234 AC_REQUIRE([AC_HEADER_STDC])dnl
235 AC_REQUIRE([AC_C_CONST])dnl
236 AC_REQUIRE([AC_C_INLINE])dnl
237 AC_REQUIRE([AC_TYPE_OFF_T])dnl
238 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
239 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
240 AC_REQUIRE([AC_FUNC_MMAP])dnl
241
242 AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
243 unistd.h values.h sys/param.h])
244 AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
245 __argz_count __argz_stringify __argz_next])
246
247 if test "${ac_cv_func_stpcpy+set}" != "set"; then
248 AC_CHECK_FUNCS(stpcpy)
249 fi
250 if test "${ac_cv_func_stpcpy}" = "yes"; then
251 AC_DEFINE(HAVE_STPCPY)
252 fi
253
254 AM_LC_MESSAGES
255 CY_WITH_NLS
256
257 if test "x$CATOBJEXT" != "x"; then
258 if test "x$ALL_LINGUAS" = "x"; then
259 LINGUAS=
260 else
261 AC_MSG_CHECKING(for catalogs to be installed)
262 NEW_LINGUAS=
263 for lang in ${LINGUAS=$ALL_LINGUAS}; do
264 case "$ALL_LINGUAS" in
265 *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
266 esac
267 done
268 LINGUAS=$NEW_LINGUAS
269 AC_MSG_RESULT($LINGUAS)
270 fi
271
272 dnl Construct list of names of catalog files to be constructed.
273 if test -n "$LINGUAS"; then
274 for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
275 fi
276 fi
277
278 dnl The reference to <locale.h> in the installed <libintl.h> file
279 dnl must be resolved because we cannot expect the users of this
280 dnl to define HAVE_LOCALE_H.
281 if test $ac_cv_header_locale_h = yes; then
282 INCLUDE_LOCALE_H="#include <locale.h>"
283 else
284 INCLUDE_LOCALE_H="\
285 /* The system does not provide the header <locale.h>. Take care yourself. */"
286 fi
287 AC_SUBST(INCLUDE_LOCALE_H)
288
289 dnl Determine which catalog format we have (if any is needed)
290 dnl For now we know about two different formats:
291 dnl Linux libc-5 and the normal X/Open format
292 if test -f $srcdir/po2tbl.sed.in; then
293 if test "$CATOBJEXT" = ".cat"; then
294 AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
295
296 dnl Transform the SED scripts while copying because some dumb SEDs
297 dnl cannot handle comments.
298 sed -e '/^#/d' $srcdir/$msgformat-msg.sed > po2msg.sed
299 fi
300 dnl po2tbl.sed is always needed.
301 sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
302 $srcdir/po2tbl.sed.in > po2tbl.sed
303 fi
304
305 dnl In the intl/Makefile.in we have a special dependency which makes
306 dnl only sense for gettext. We comment this out for non-gettext
307 dnl packages.
308 if test "$PACKAGE" = "gettext"; then
309 GT_NO="#NO#"
310 GT_YES=
311 else
312 GT_NO=
313 GT_YES="#YES#"
314 fi
315 AC_SUBST(GT_NO)
316 AC_SUBST(GT_YES)
317
318 MKINSTALLDIRS="\$(srcdir)/../../mkinstalldirs"
319 AC_SUBST(MKINSTALLDIRS)
320
321 dnl *** For now the libtool support in intl/Makefile is not for real.
322 l=
323 AC_SUBST(l)
324
325 dnl Generate list of files to be processed by xgettext which will
326 dnl be included in po/Makefile. But only do this if the po directory
327 dnl exists in srcdir.
328 if test -d $srcdir/po; then
329 test -d po || mkdir po
330 if test "x$srcdir" != "x."; then
331 if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
332 posrcprefix="$srcdir/"
333 else
334 posrcprefix="../$srcdir/"
335 fi
336 else
337 posrcprefix="../"
338 fi
339 rm -f po/POTFILES
340 sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
341 < $srcdir/po/POTFILES.in > po/POTFILES
342 fi
343 ])
344
345 # Search path for a program which passes the given test.
346 # Ulrich Drepper <drepper@cygnus.com>, 1996.
347 #
348 # This file file be copied and used freely without restrictions. It can
349 # be used in projects which are not available under the GNU Public License
350 # but which still want to provide support for the GNU gettext functionality.
351 # Please note that the actual code is *not* freely available.
352
353 # serial 1
354
355 dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
356 dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
357 AC_DEFUN(AM_PATH_PROG_WITH_TEST,
358 [# Extract the first word of "$2", so it can be a program name with args.
359 set dummy $2; ac_word=[$]2
360 AC_MSG_CHECKING([for $ac_word])
361 AC_CACHE_VAL(ac_cv_path_$1,
362 [case "[$]$1" in
363 /*)
364 ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
365 ;;
366 *)
367 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
368 for ac_dir in ifelse([$5], , $PATH, [$5]); do
369 test -z "$ac_dir" && ac_dir=.
370 if test -f $ac_dir/$ac_word; then
371 if [$3]; then
372 ac_cv_path_$1="$ac_dir/$ac_word"
373 break
374 fi
375 fi
376 done
377 IFS="$ac_save_ifs"
378 dnl If no 4th arg is given, leave the cache variable unset,
379 dnl so AC_PATH_PROGS will keep looking.
380 ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
381 ])dnl
382 ;;
383 esac])dnl
384 $1="$ac_cv_path_$1"
385 if test -n "[$]$1"; then
386 AC_MSG_RESULT([$]$1)
387 else
388 AC_MSG_RESULT(no)
389 fi
390 AC_SUBST($1)dnl
391 ])
392
393 # Check whether LC_MESSAGES is available in <locale.h>.
394 # Ulrich Drepper <drepper@cygnus.com>, 1995.
395 #
396 # This file file be copied and used freely without restrictions. It can
397 # be used in projects which are not available under the GNU Public License
398 # but which still want to provide support for the GNU gettext functionality.
399 # Please note that the actual code is *not* freely available.
400
401 # serial 1
402
403 AC_DEFUN(AM_LC_MESSAGES,
404 [if test $ac_cv_header_locale_h = yes; then
405 AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
406 [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
407 am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
408 if test $am_cv_val_LC_MESSAGES = yes; then
409 AC_DEFINE(HAVE_LC_MESSAGES)
410 fi
411 fi])
412
413
414 dnl Check for existence of a type $1 in sys/procfs.h
415
416 AC_DEFUN(BFD_HAVE_SYS_PROCFS_TYPE,
417 [AC_MSG_CHECKING([for $1 in sys/procfs.h])
418 AC_CACHE_VAL(bfd_cv_have_sys_procfs_type_$1,
419 [AC_TRY_COMPILE([#include <sys/procfs.h>],
420 [$1 avar],
421 bfd_cv_have_sys_procfs_type_$1=yes
422 AC_DEFINE([HAVE_]translit($1, [a-z], [A-Z])),
423 bfd_cv_have_sys_procfs_type_$1=no
424 )])
425 AC_MSG_RESULT($bfd_cv_have_sys_procfs_type_$1)
426 ])
427
428
429 dnl Check for existence of member $2 in type $1 in sys/procfs.h
430
431 AC_DEFUN(BFD_HAVE_SYS_PROCFS_TYPE_MEMBER,
432 [AC_MSG_CHECKING([for $1.$2 in sys/procfs.h])
433 AC_CACHE_VAL(bfd_cv_have_sys_procfs_type_member_$1_$2,
434 [AC_TRY_COMPILE([#include <sys/procfs.h>],
435 [$1 avar; void* aref = (void*) &avar.$2],
436 bfd_cv_have_sys_procfs_type_member_$1_$2=yes
437 AC_DEFINE([HAVE_]translit($1, [a-z], [A-Z])[_]translit($2, [a-z], [A-Z])),
438 bfd_cv_have_sys_procfs_type_member_$1_$2=no
439 )])
440 AC_MSG_RESULT($bfd_cv_have_sys_procfs_type_member_$1_$2)
441 ])
442
443