Use an all-permissive copyright notice, recommended by RMS.
[gnulib.git] / m4 / lib-link.m4
1 # lib-link.m4 serial 4 (gettext-0.12)
2 dnl Copyright (C) 2001-2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible.
8
9 dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
10 dnl the libraries corresponding to explicit and implicit dependencies.
11 dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
12 dnl augments the CPPFLAGS variable.
13 AC_DEFUN([AC_LIB_LINKFLAGS],
14 [
15   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
16   AC_REQUIRE([AC_LIB_RPATH])
17   define([Name],[translit([$1],[./-], [___])])
18   define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
19                                [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
20   AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
21     AC_LIB_LINKFLAGS_BODY([$1], [$2])
22     ac_cv_lib[]Name[]_libs="$LIB[]NAME"
23     ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
24     ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
25   ])
26   LIB[]NAME="$ac_cv_lib[]Name[]_libs"
27   LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
28   INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
29   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
30   AC_SUBST([LIB]NAME)
31   AC_SUBST([LTLIB]NAME)
32   dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
33   dnl results of this search when this library appears as a dependency.
34   HAVE_LIB[]NAME=yes
35   undefine([Name])
36   undefine([NAME])
37 ])
38
39 dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode)
40 dnl searches for libname and the libraries corresponding to explicit and
41 dnl implicit dependencies, together with the specified include files and
42 dnl the ability to compile and link the specified testcode. If found, it
43 dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and
44 dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and
45 dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
46 dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
47 AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
48 [
49   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
50   AC_REQUIRE([AC_LIB_RPATH])
51   define([Name],[translit([$1],[./-], [___])])
52   define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
53                                [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
54
55   dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
56   dnl accordingly.
57   AC_LIB_LINKFLAGS_BODY([$1], [$2])
58
59   dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
60   dnl because if the user has installed lib[]Name and not disabled its use
61   dnl via --without-lib[]Name-prefix, he wants to use it.
62   ac_save_CPPFLAGS="$CPPFLAGS"
63   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
64
65   AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
66     ac_save_LIBS="$LIBS"
67     LIBS="$LIBS $LIB[]NAME"
68     AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no])
69     LIBS="$ac_save_LIBS"
70   ])
71   if test "$ac_cv_lib[]Name" = yes; then
72     HAVE_LIB[]NAME=yes
73     AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.])
74     AC_MSG_CHECKING([how to link with lib[]$1])
75     AC_MSG_RESULT([$LIB[]NAME])
76   else
77     HAVE_LIB[]NAME=no
78     dnl If $LIB[]NAME didn't lead to a usable library, we don't need
79     dnl $INC[]NAME either.
80     CPPFLAGS="$ac_save_CPPFLAGS"
81     LIB[]NAME=
82     LTLIB[]NAME=
83   fi
84   AC_SUBST([HAVE_LIB]NAME)
85   AC_SUBST([LIB]NAME)
86   AC_SUBST([LTLIB]NAME)
87   undefine([Name])
88   undefine([NAME])
89 ])
90
91 dnl Determine the platform dependent parameters needed to use rpath:
92 dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator,
93 dnl hardcode_direct, hardcode_minus_L.
94 AC_DEFUN([AC_LIB_RPATH],
95 [
96   AC_REQUIRE([AC_PROG_CC])                dnl we use $CC, $GCC, $LDFLAGS
97   AC_REQUIRE([AC_LIB_PROG_LD])            dnl we use $LD, $with_gnu_ld
98   AC_REQUIRE([AC_CANONICAL_HOST])         dnl we use $host
99   AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
100   AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [
101     CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
102     ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
103     . ./conftest.sh
104     rm -f ./conftest.sh
105     acl_cv_rpath=done
106   ])
107   wl="$acl_cv_wl"
108   libext="$acl_cv_libext"
109   shlibext="$acl_cv_shlibext"
110   hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
111   hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
112   hardcode_direct="$acl_cv_hardcode_direct"
113   hardcode_minus_L="$acl_cv_hardcode_minus_L"
114   dnl Determine whether the user wants rpath handling at all.
115   AC_ARG_ENABLE(rpath,
116     [  --disable-rpath         do not hardcode runtime library paths],
117     :, enable_rpath=yes)
118 ])
119
120 dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
121 dnl the libraries corresponding to explicit and implicit dependencies.
122 dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
123 AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
124 [
125   define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
126                                [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
127   dnl By default, look in $includedir and $libdir.
128   use_additional=yes
129   AC_LIB_WITH_FINAL_PREFIX([
130     eval additional_includedir=\"$includedir\"
131     eval additional_libdir=\"$libdir\"
132   ])
133   AC_LIB_ARG_WITH([lib$1-prefix],
134 [  --with-lib$1-prefix[=DIR]  search for lib$1 in DIR/include and DIR/lib
135   --without-lib$1-prefix     don't search for lib$1 in includedir and libdir],
136 [
137     if test "X$withval" = "Xno"; then
138       use_additional=no
139     else
140       if test "X$withval" = "X"; then
141         AC_LIB_WITH_FINAL_PREFIX([
142           eval additional_includedir=\"$includedir\"
143           eval additional_libdir=\"$libdir\"
144         ])
145       else
146         additional_includedir="$withval/include"
147         additional_libdir="$withval/lib"
148       fi
149     fi
150 ])
151   dnl Search the library and its dependencies in $additional_libdir and
152   dnl $LDFLAGS. Using breadth-first-seach.
153   LIB[]NAME=
154   LTLIB[]NAME=
155   INC[]NAME=
156   rpathdirs=
157   ltrpathdirs=
158   names_already_handled=
159   names_next_round='$1 $2'
160   while test -n "$names_next_round"; do
161     names_this_round="$names_next_round"
162     names_next_round=
163     for name in $names_this_round; do
164       already_handled=
165       for n in $names_already_handled; do
166         if test "$n" = "$name"; then
167           already_handled=yes
168           break
169         fi
170       done
171       if test -z "$already_handled"; then
172         names_already_handled="$names_already_handled $name"
173         dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
174         dnl or AC_LIB_HAVE_LINKFLAGS call.
175         uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
176         eval value=\"\$HAVE_LIB$uppername\"
177         if test -n "$value"; then
178           if test "$value" = yes; then
179             eval value=\"\$LIB$uppername\"
180             test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
181             eval value=\"\$LTLIB$uppername\"
182             test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
183           else
184             dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
185             dnl that this library doesn't exist. So just drop it.
186             :
187           fi
188         else
189           dnl Search the library lib$name in $additional_libdir and $LDFLAGS
190           dnl and the already constructed $LIBNAME/$LTLIBNAME.
191           found_dir=
192           found_la=
193           found_so=
194           found_a=
195           if test $use_additional = yes; then
196             if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
197               found_dir="$additional_libdir"
198               found_so="$additional_libdir/lib$name.$shlibext"
199               if test -f "$additional_libdir/lib$name.la"; then
200                 found_la="$additional_libdir/lib$name.la"
201               fi
202             else
203               if test -f "$additional_libdir/lib$name.$libext"; then
204                 found_dir="$additional_libdir"
205                 found_a="$additional_libdir/lib$name.$libext"
206                 if test -f "$additional_libdir/lib$name.la"; then
207                   found_la="$additional_libdir/lib$name.la"
208                 fi
209               fi
210             fi
211           fi
212           if test "X$found_dir" = "X"; then
213             for x in $LDFLAGS $LTLIB[]NAME; do
214               AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
215               case "$x" in
216                 -L*)
217                   dir=`echo "X$x" | sed -e 's/^X-L//'`
218                   if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
219                     found_dir="$dir"
220                     found_so="$dir/lib$name.$shlibext"
221                     if test -f "$dir/lib$name.la"; then
222                       found_la="$dir/lib$name.la"
223                     fi
224                   else
225                     if test -f "$dir/lib$name.$libext"; then
226                       found_dir="$dir"
227                       found_a="$dir/lib$name.$libext"
228                       if test -f "$dir/lib$name.la"; then
229                         found_la="$dir/lib$name.la"
230                       fi
231                     fi
232                   fi
233                   ;;
234               esac
235               if test "X$found_dir" != "X"; then
236                 break
237               fi
238             done
239           fi
240           if test "X$found_dir" != "X"; then
241             dnl Found the library.
242             LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
243             if test "X$found_so" != "X"; then
244               dnl Linking with a shared library. We attempt to hardcode its
245               dnl directory into the executable's runpath, unless it's the
246               dnl standard /usr/lib.
247               if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
248                 dnl No hardcoding is needed.
249                 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
250               else
251                 dnl Use an explicit option to hardcode DIR into the resulting
252                 dnl binary.
253                 dnl Potentially add DIR to ltrpathdirs.
254                 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
255                 haveit=
256                 for x in $ltrpathdirs; do
257                   if test "X$x" = "X$found_dir"; then
258                     haveit=yes
259                     break
260                   fi
261                 done
262                 if test -z "$haveit"; then
263                   ltrpathdirs="$ltrpathdirs $found_dir"
264                 fi
265                 dnl The hardcoding into $LIBNAME is system dependent.
266                 if test "$hardcode_direct" = yes; then
267                   dnl Using DIR/libNAME.so during linking hardcodes DIR into the
268                   dnl resulting binary.
269                   LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
270                 else
271                   if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
272                     dnl Use an explicit option to hardcode DIR into the resulting
273                     dnl binary.
274                     LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
275                     dnl Potentially add DIR to rpathdirs.
276                     dnl The rpathdirs will be appended to $LIBNAME at the end.
277                     haveit=
278                     for x in $rpathdirs; do
279                       if test "X$x" = "X$found_dir"; then
280                         haveit=yes
281                         break
282                       fi
283                     done
284                     if test -z "$haveit"; then
285                       rpathdirs="$rpathdirs $found_dir"
286                     fi
287                   else
288                     dnl Rely on "-L$found_dir".
289                     dnl But don't add it if it's already contained in the LDFLAGS
290                     dnl or the already constructed $LIBNAME
291                     haveit=
292                     for x in $LDFLAGS $LIB[]NAME; do
293                       AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
294                       if test "X$x" = "X-L$found_dir"; then
295                         haveit=yes
296                         break
297                       fi
298                     done
299                     if test -z "$haveit"; then
300                       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
301                     fi
302                     if test "$hardcode_minus_L" != no; then
303                       dnl FIXME: Not sure whether we should use
304                       dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
305                       dnl here.
306                       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
307                     else
308                       dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH
309                       dnl here, because this doesn't fit in flags passed to the
310                       dnl compiler. So give up. No hardcoding. This affects only
311                       dnl very old systems.
312                       dnl FIXME: Not sure whether we should use
313                       dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
314                       dnl here.
315                       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
316                     fi
317                   fi
318                 fi
319               fi
320             else
321               if test "X$found_a" != "X"; then
322                 dnl Linking with a static library.
323                 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
324               else
325                 dnl We shouldn't come here, but anyway it's good to have a
326                 dnl fallback.
327                 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
328               fi
329             fi
330             dnl Assume the include files are nearby.
331             additional_includedir=
332             case "$found_dir" in
333               */lib | */lib/)
334                 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
335                 additional_includedir="$basedir/include"
336                 ;;
337             esac
338             if test "X$additional_includedir" != "X"; then
339               dnl Potentially add $additional_includedir to $INCNAME.
340               dnl But don't add it
341               dnl   1. if it's the standard /usr/include,
342               dnl   2. if it's /usr/local/include and we are using GCC on Linux,
343               dnl   3. if it's already present in $CPPFLAGS or the already
344               dnl      constructed $INCNAME,
345               dnl   4. if it doesn't exist as a directory.
346               if test "X$additional_includedir" != "X/usr/include"; then
347                 haveit=
348                 if test "X$additional_includedir" = "X/usr/local/include"; then
349                   if test -n "$GCC"; then
350                     case $host_os in
351                       linux*) haveit=yes;;
352                     esac
353                   fi
354                 fi
355                 if test -z "$haveit"; then
356                   for x in $CPPFLAGS $INC[]NAME; do
357                     AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
358                     if test "X$x" = "X-I$additional_includedir"; then
359                       haveit=yes
360                       break
361                     fi
362                   done
363                   if test -z "$haveit"; then
364                     if test -d "$additional_includedir"; then
365                       dnl Really add $additional_includedir to $INCNAME.
366                       INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
367                     fi
368                   fi
369                 fi
370               fi
371             fi
372             dnl Look for dependencies.
373             if test -n "$found_la"; then
374               dnl Read the .la file. It defines the variables
375               dnl dlname, library_names, old_library, dependency_libs, current,
376               dnl age, revision, installed, dlopen, dlpreopen, libdir.
377               save_libdir="$libdir"
378               case "$found_la" in
379                 */* | *\\*) . "$found_la" ;;
380                 *) . "./$found_la" ;;
381               esac
382               libdir="$save_libdir"
383               dnl We use only dependency_libs.
384               for dep in $dependency_libs; do
385                 case "$dep" in
386                   -L*)
387                     additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
388                     dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
389                     dnl But don't add it
390                     dnl   1. if it's the standard /usr/lib,
391                     dnl   2. if it's /usr/local/lib and we are using GCC on Linux,
392                     dnl   3. if it's already present in $LDFLAGS or the already
393                     dnl      constructed $LIBNAME,
394                     dnl   4. if it doesn't exist as a directory.
395                     if test "X$additional_libdir" != "X/usr/lib"; then
396                       haveit=
397                       if test "X$additional_libdir" = "X/usr/local/lib"; then
398                         if test -n "$GCC"; then
399                           case $host_os in
400                             linux*) haveit=yes;;
401                           esac
402                         fi
403                       fi
404                       if test -z "$haveit"; then
405                         haveit=
406                         for x in $LDFLAGS $LIB[]NAME; do
407                           AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
408                           if test "X$x" = "X-L$additional_libdir"; then
409                             haveit=yes
410                             break
411                           fi
412                         done
413                         if test -z "$haveit"; then
414                           if test -d "$additional_libdir"; then
415                             dnl Really add $additional_libdir to $LIBNAME.
416                             LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
417                           fi
418                         fi
419                         haveit=
420                         for x in $LDFLAGS $LTLIB[]NAME; do
421                           AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
422                           if test "X$x" = "X-L$additional_libdir"; then
423                             haveit=yes
424                             break
425                           fi
426                         done
427                         if test -z "$haveit"; then
428                           if test -d "$additional_libdir"; then
429                             dnl Really add $additional_libdir to $LTLIBNAME.
430                             LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
431                           fi
432                         fi
433                       fi
434                     fi
435                     ;;
436                   -R*)
437                     dir=`echo "X$dep" | sed -e 's/^X-R//'`
438                     if test "$enable_rpath" != no; then
439                       dnl Potentially add DIR to rpathdirs.
440                       dnl The rpathdirs will be appended to $LIBNAME at the end.
441                       haveit=
442                       for x in $rpathdirs; do
443                         if test "X$x" = "X$dir"; then
444                           haveit=yes
445                           break
446                         fi
447                       done
448                       if test -z "$haveit"; then
449                         rpathdirs="$rpathdirs $dir"
450                       fi
451                       dnl Potentially add DIR to ltrpathdirs.
452                       dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
453                       haveit=
454                       for x in $ltrpathdirs; do
455                         if test "X$x" = "X$dir"; then
456                           haveit=yes
457                           break
458                         fi
459                       done
460                       if test -z "$haveit"; then
461                         ltrpathdirs="$ltrpathdirs $dir"
462                       fi
463                     fi
464                     ;;
465                   -l*)
466                     dnl Handle this in the next round.
467                     names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
468                     ;;
469                   *.la)
470                     dnl Handle this in the next round. Throw away the .la's
471                     dnl directory; it is already contained in a preceding -L
472                     dnl option.
473                     names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
474                     ;;
475                   *)
476                     dnl Most likely an immediate library name.
477                     LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
478                     LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
479                     ;;
480                 esac
481               done
482             fi
483           else
484             dnl Didn't find the library; assume it is in the system directories
485             dnl known to the linker and runtime loader. (All the system
486             dnl directories known to the linker should also be known to the
487             dnl runtime loader, otherwise the system is severely misconfigured.)
488             LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
489             LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
490           fi
491         fi
492       fi
493     done
494   done
495   if test "X$rpathdirs" != "X"; then
496     if test -n "$hardcode_libdir_separator"; then
497       dnl Weird platform: only the last -rpath option counts, the user must
498       dnl pass all path elements in one option. We can arrange that for a
499       dnl single library, but not when more than one $LIBNAMEs are used.
500       alldirs=
501       for found_dir in $rpathdirs; do
502         alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
503       done
504       dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl.
505       acl_save_libdir="$libdir"
506       libdir="$alldirs"
507       eval flag=\"$hardcode_libdir_flag_spec\"
508       libdir="$acl_save_libdir"
509       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
510     else
511       dnl The -rpath options are cumulative.
512       for found_dir in $rpathdirs; do
513         acl_save_libdir="$libdir"
514         libdir="$found_dir"
515         eval flag=\"$hardcode_libdir_flag_spec\"
516         libdir="$acl_save_libdir"
517         LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
518       done
519     fi
520   fi
521   if test "X$ltrpathdirs" != "X"; then
522     dnl When using libtool, the option that works for both libraries and
523     dnl executables is -R. The -R options are cumulative.
524     for found_dir in $ltrpathdirs; do
525       LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
526     done
527   fi
528 ])
529
530 dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
531 dnl unless already present in VAR.
532 dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
533 dnl contains two or three consecutive elements that belong together.
534 AC_DEFUN([AC_LIB_APPENDTOVAR],
535 [
536   for element in [$2]; do
537     haveit=
538     for x in $[$1]; do
539       AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
540       if test "X$x" = "X$element"; then
541         haveit=yes
542         break
543       fi
544     done
545     if test -z "$haveit"; then
546       [$1]="${[$1]}${[$1]:+ }$element"
547     fi
548   done
549 ])