Debian Codegraph @

am/config_paths.m4

raw
1 dnl
2 dnl Copyright (C) 1996-2026 Free Software Foundation, Inc.
3 dnl
4 dnl This file is part of GNU Inetutils.
5 dnl
6 dnl GNU Inetutils is free software: you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation, either version 3 of the License, or (at
9 dnl your option) any later version.
10 dnl
11 dnl GNU Inetutils is distributed in the hope that it will be useful, but
12 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 dnl General Public License for more details.
15 dnl
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program. If not, see `http://www.gnu.org/licenses/'.
18
19 dnl Written by Miles Bader.
20
21 dnl IU_CONFIG_PATHS -- Configure system paths for use by programs
22 dnl $1 - PATHS -- The file to read containing the paths
23 dnl $2 - MAKEDEFS -- The file to generate containing make `PATHDEF_' vars
24 dnl $3 - HDRDEFS -- The file to generate containing c header stuff
25 dnl
26 dnl From the paths listed in the file PATHS, generate a file of make input
27 dnl (MAKEDEFS) containing a make variable for each PATH_FOO, called
28 dnl PATHDEF_FOO, which is set to a cpp option to define that path, unless it
29 dnl is to be defined using a system define, in which case the
30 dnl corresponding make variable is empty. A file called HDRDEFS will also be
31 dnl generated containing cpp statements. For each PATH_FOO which is found
32 dnl to be available as a system define, a statement will be generated which
33 dnl defines it to be that system define, unless it is already defined (which
34 dnl will be case if overridden by make).
35 dnl
36 AC_DEFUN([IU_CONFIG_PATHS], [
37 dnl We need to know if we're cross compiling.
38 AC_REQUIRE([AC_PROG_CC])
39
40 AC_CHECK_HEADER(paths.h, AC_DEFINE([HAVE_PATHS_H], 1,
41 [Define if you have the <paths.h> header file]) iu_paths_h="<paths.h>")
42
43 dnl A slightly bogus use of AC_ARG_WITH; we never actually use
44 dnl $with_PATHVAR, we just want to get this entry put into the help list.
45 dnl We actually look for `with_' variables corresponding to each path
46 dnl configured.
47 AC_ARG_WITH([PATHVAR],
48 AS_HELP_STRING([--with-PATHVAR=PATH],
49 [Set the value of PATHVAR to PATH
50 PATHVAR is the name of a \`PATH_FOO' variable,
51 downcased, with \`_' changed to \`-']))
52
53 # For case-conversion with sed
54 IU_UCASE=ABCDEFGHIJKLMNOPQRSTUVWXYZ
55 iu_lcase=abcdefghijklmnopqrstuvwxyz
56
57 tmpdir="$TMPDIR"
58 test x"$tmpdir" = x && tmpdir="/tmp"
59 iu_cache_file="$tmpdir/,iu-path-cache.$$"
60 iu_tmp_file="$tmpdir/,iu-tmp.$$"
61 ac_clean_files="$ac_clean_files $iu_cache_file $iu_tmp_file"
62 while read iu_path iu_search; do
63 test "$iu_path" = "#" || test -z "$iu_path" && continue
64
65 iu_pathvar="`echo $iu_path | sed y/${IU_UCASE}/${iu_lcase}/`"
66 AC_MSG_CHECKING(for value of $iu_path)
67
68 iu_val='' iu_hdr='' iu_sym=''
69 iu_cached='' iu_defaulted=''
70 iu_cross_conflict=''
71 if test "`eval echo '$'{with_$iu_pathvar+set}`" = set; then
72 # User-supplied value
73 eval iu_val=\"'$'with_$iu_pathvar\"
74 elif test "`eval echo '$'{inetutils_cv_$iu_pathvar+set}`" = set; then
75 # Cached value
76 eval iu_val=\"'$'inetutils_cv_$iu_pathvar\"
77 # invert escaped $(...) notation used in autoconf cache
78 eval iu_val=\"\`echo \'"$iu_val"\' \| sed \''s/@(/$\(/g'\'\`\"
79 iu_cached="(cached) "
80 elif test "`eval echo '$'{inetutils_cv_hdr_$iu_pathvar+set}`" = set; then
81 # Cached non-value
82 eval iu_hdr=\"'$'inetutils_cv_hdr_$iu_pathvar\"
83 eval iu_sym=\"'$'inetutils_cv_hdr_sym_$iu_pathvar\"
84 iu_cached="(cached) "
85 else
86 # search for a reasonable value
87
88 iu_test_type=e # `exists'
89 iu_default='' iu_prev_cross_test=''
90 for iu_try in $iu_paths_h $iu_search; do
91 iu_cross_test=''
92 case "$iu_try" in
93 "<"*">"*)
94 # <HEADER.h> and <HEADER.h>:SYMBOL -- look for SYMBOL in <HEADER.h>
95 # SYMBOL defaults to _$iu_path (e.g., _PATH_FOO)
96 changequote(,) dnl Avoid problems with [ ] in regexps
97 eval iu_hdr=\'`echo "$iu_try" |sed 's/:.*$//'`\'
98 eval iu_sym=\'`echo "$iu_try" |sed -n 's/^<[^>]*>:\(.*\)$/\1/p'`\'
99 changequote([,])
100 test "$iu_sym" || iu_sym="_$iu_path"
101 AC_EGREP_CPP(HAVE_$iu_sym,
102 [#include ]$iu_hdr[
103 #ifdef $iu_sym
104 HAVE_$iu_sym
105 #endif],
106 :, iu_hdr='' iu_sym='')
107 ;;
108
109 search:*)
110 # Do a path search. The syntax here is: search:NAME[:PATH]...
111
112 # Path searches always generate potential conflicts
113 test "$cross_compiling" = yes && { iu_cross_conflict=yes; continue; }
114
115 changequote(,) dnl Avoid problems with [ ] in regexps
116 iu_name="`echo $iu_try | sed 's/^search:\([^:]*\).*$/\1/'`"
117 iu_spath="`echo $iu_try | sed 's/^search:\([^:]*\)//'`"
118 changequote([,])
119
120 test "$iu_spath" || iu_spath="$PATH"
121
122 for iu_dir in `echo "$iu_spath" | sed 'y/:/ /'`; do
123 test -z "$iu_dir" && iu_dir=.
124 if test -$iu_test_type "$iu_dir/$iu_name"; then
125 iu_val="$iu_dir/$iu_name"
126 break
127 fi
128 done
129 ;;
130
131 no) iu_default=no;;
132 x|d|f|c|b) iu_test_type=$iu_try;;
133
134 *)
135 # Just try the given name, with make-var substitution. Besides
136 # yielding a value if found, this also sets the default.
137
138 case "$iu_try" in "\""*"\"")
139 # strip off quotes
140 iu_try="`echo $iu_try | sed -e 's/^.//' -e 's/.$//'`"
141 esac
142
143 test -z "$iu_default" && iu_default="$iu_try"
144 test "$cross_compiling" = yes && { iu_cross_test=yes; continue; }
145
146 # See if the value begins with a $(FOO)/${FOO} make variable
147 # corresponding to a shell variable, and if so set try_exp to the
148 # value thereof. Recurse.
149 iu_try_exp="$iu_try"
150 changequote(,)
151 iu_try_var="`echo "$iu_try_exp" |sed -n 's;^\$[({]\([-_a-zA-Z]*\)[)}].*;\1;p'`"
152 while eval test \"$iu_try_var\" && eval test '${'$iu_try_var'+set}'; do
153 # yes, and there's a corresponding shell variable, which substitute
154 if eval test \"'$'"$iu_try_var"\" = NONE; then
155 # Not filled in by configure yet
156 case "$iu_try_var" in
157 prefix | exec_prefix)
158 iu_try_exp="$ac_default_prefix`echo "$iu_try_exp" |sed 's;^\$[({][-_a-zA-Z]*[)}];;'`";;
159 esac
160 iu_try_var='' # Stop expansion here
161 else
162 # Use the actual value of the shell variable
163 eval iu_try_exp=\"`echo "$iu_try_exp" |sed 's;^\$[({]\([-_a-zA-Z]*\)[)}];\$\1;'`\"
164 iu_try_var="`echo "$iu_try_exp" |sed -n 's;^\$[({]\([-_a-zA-Z]*\)[)}].*;\1;p'`"
165 fi
166 done
167 changequote([,])
168
169 test -$iu_test_type "$iu_try_exp" && iu_val="$iu_try"
170 ;;
171
172 esac
173
174 test "$iu_val" || test "$iu_hdr" && break
175 test "$iu_cross_test" && test "$iu_prev_cross_test" && iu_cross_conflict=yes
176 iu_prev_cross_test=$iu_cross_test
177 done
178
179 if test -z "$iu_val" && test -z "$iu_hdr"; then
180 if test -z "$iu_default"; then
181 iu_val=no
182 else
183 iu_val="$iu_default"
184 iu_defaulted="(default) "
185 fi
186 fi
187 fi
188
189 if test "$iu_val"; then
190 AC_MSG_RESULT(${iu_cached}${iu_defaulted}$iu_val)
191 test "$iu_cross_conflict" && test "$iu_defaulted" \
192 && AC_MSG_WARN(may be incorrect because of cross-compilation)
193 # Put the value in the autoconf cache. We replace $( with @( to avoid
194 # variable evaluation problems when autoconf reads the cache later.
195 echo inetutils_cv_$iu_pathvar=\'"`echo "$iu_val" | sed 's/\$(/@(/g'`"\'
196 elif test "$iu_hdr"; then
197 AC_MSG_RESULT(${iu_cached}from $iu_sym in $iu_hdr)
198 echo inetutils_cv_hdr_$iu_pathvar=\'"$iu_hdr"\'
199 echo inetutils_cv_hdr_sym_$iu_pathvar=\'"$iu_sym"\'
200 fi
201 done <[$1] >$iu_cache_file
202
203 # Read the cache values constructed by the previous loop,
204 . $iu_cache_file
205
206 # Construct the pathdefs file -- a file of make variable definitions, of
207 # the form PATHDEF_FOO, that contain cc -D switches to define the cpp macro
208 # PATH_FOO.
209 grep -v '^inetutils_cv_hdr_' < $iu_cache_file | \
210 while read iu_cache_set; do
211 iu_var="`echo $iu_cache_set | sed 's/=.*$//'`"
212 eval iu_val=\"'$'"$iu_var"\"
213 # invert escaped $(...) notation used in autoconf cache
214 eval iu_val=\"\`echo \'"$iu_val"\' \| sed \''s/@(/$\(/g'\'\`\"
215 if test "$iu_val" != no; then
216 iu_path="`echo $iu_var | sed -e 's/^inetutils_cv_//' -e y/${iu_lcase}/${IU_UCASE}/`"
217 iu_pathdef="`echo $iu_path | sed 's/^PATH_/PATHDEF_/'`"
218 echo $iu_pathdef = -D$iu_path='\"'"$iu_val"'\"'
219 AC_DEFINE_UNQUOTED($iu_path, "$iu_val")
220 fi
221 done >$[$2]
222 AC_SUBST_FILE([$2])
223
224 # Generate a file of #ifdefs that defaults PATH_FOO macros to _PATH_FOO (or
225 # some other symbol) (excluding any who's value is set to `no').
226 grep '^inetutils_cv_hdr_sym_' < $iu_cache_file | \
227 while read iu_cache_set; do
228 iu_sym_var="`echo "$iu_cache_set" | sed 's/=.*$//'`"
229 eval iu_sym=\"'$'"$iu_sym_var"\"
230 iu_path="`echo $iu_sym_var | sed -e 's/^inetutils_cv_hdr_sym_//' -e y/${iu_lcase}/${IU_UCASE}/`"
231 cat <<EOF
232 #ifndef $iu_path
233 #define $iu_path $iu_sym
234 #endif
235 EOF
236 done >$[$3]
237 AC_SUBST_FILE([$3])])