]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/build/options/makeman
Upgrade Unbound to 1.6.8. More to follow.
[FreeBSD/FreeBSD.git] / tools / build / options / makeman
1 #!/bin/sh
2 #
3 # This file is in the public domain.
4 # $FreeBSD$
5 #
6 # This script creates the src.conf.5 man page using template text contained
7 # herein and the contents of the WITH_* and WITHOUT_* files in the same
8 # directory. Each WITH_* and WITHOUT_* file documents the effect of the
9 # /etc/src.conf knob with the same name.
10 #
11 # For each supported architecture, "make showconfig" is invoked to determine
12 # the default setting of every option: always WITH_, always WITHOUT_, or
13 # architecture-dependent WITH_/WITHOUT_.  It also determines and describes
14 # dependencies between options.
15 #
16 # Usage:
17 #
18 #     cd tools/build/options
19 #     sh makeman > ../../../share/man/man5/src.conf.5
20
21 set -o errexit
22 export LC_ALL=C
23
24 t=$(mktemp -d -t makeman)
25 trap 'test -d $t && rm -rf $t' exit
26
27 srcdir=$(realpath ../../..)
28 make="make -C $srcdir -m $srcdir/share/mk"
29
30 #
31 # usage: no_targets all_targets yes_targets
32 #
33 no_targets()
34 {
35         for t1 in $1 ; do
36                 for t2 in $2 ; do
37                         if [ "${t1}" = "${t2}" ] ; then
38                                 continue 2
39                         fi
40                 done
41                 echo ${t1}
42         done
43 }
44
45 show_options()
46 {
47         ALL_TARGETS=$(echo $(${make} targets MK_AUTO_OBJ=no | tail -n +2))
48         rm -f $t/settings
49         for target in ${ALL_TARGETS} ; do
50                 prev_opt=
51                 env -i ${make} showconfig \
52                     SRC_ENV_CONF=/dev/null SRCCONF=/dev/null \
53                     __MAKE_CONF=/dev/null \
54                     TARGET_ARCH=${target#*/} TARGET=${target%/*} |
55                 while read var _ val ; do
56                         opt=${var#MK_}
57                         if [ $opt = "$prev_opt" ]; then
58                                 echo "$target: ignoring duplicate option $opt" >&2
59                                 continue
60                         fi
61                         prev_opt=$opt
62                         case ${val} in
63                         yes)
64                                 echo ${opt} ${target}
65                                 ;;
66                         no)
67                                 echo ${opt}
68                                 ;;
69                         *)
70                                 echo "make showconfig broken: ${var} ${_} ${val} (not yes or no)" >&2
71                                 exit 1
72                                 ;;
73                         esac
74                 done > $t/settings.target
75                 if [ -r $t/settings ] ; then
76                         join -t\  $t/settings $t/settings.target > $t/settings.new
77                         mv $t/settings.new $t/settings
78                 else
79                         mv $t/settings.target $t/settings
80                 fi
81         done
82
83         while read opt targets ; do
84                 if [ "${targets}" = "${ALL_TARGETS}" ] ; then
85                         echo "WITHOUT_${opt}"
86                 elif [ -z "${targets}" ] ; then
87                         echo "WITH_${opt}"
88                 else
89                         echo "WITHOUT_${opt}" $(no_targets "${ALL_TARGETS}" "${targets}")
90                         echo "WITH_${opt} ${targets}"
91                 fi
92         done < $t/settings
93 }
94
95 #
96 # usage: show { settings | with | without } ...
97 #
98 show()
99 {
100
101         mode=$1 ; shift
102         case ${mode} in
103         settings)
104                 yes_prefix=WITH
105                 no_prefix=WITHOUT
106                 ;;
107         with)
108                 yes_prefix=WITH
109                 no_prefix=WITH
110                 ;;
111         without)
112                 yes_prefix=WITHOUT
113                 no_prefix=WITHOUT
114                 ;;
115         *)
116                 echo 'internal error' >&2
117                 exit 1
118                 ;;
119         esac
120         env -i ${make} .MAKE.MODE=normal "$@" showconfig __MAKE_CONF=/dev/null \
121             SRCCONF=/dev/null |
122         while read var _ val ; do
123                 opt=${var#MK_}
124                 case ${val} in
125                 yes)
126                         echo ${yes_prefix}_${opt}
127                         ;;
128                 no)
129                         echo ${no_prefix}_${opt}
130                         ;;
131                 *)
132                         echo "make showconfig broken: ${var} ${_} ${val} (not yes or no)" >&2
133                         exit 1
134                         ;;
135                 esac
136         done
137 }
138
139 main()
140 {
141         echo "building src.conf.5 man page from files in ${PWD}" >&2
142
143         fbsdid='$'FreeBSD'$'
144         cat <<EOF
145 .\" DO NOT EDIT-- this file is generated by tools/build/options/makeman.
146 .\" ${fbsdid}
147 .Dd $(echo $(LC_TIME=C date +'%B %e, %Y'))
148 .Dt SRC.CONF 5
149 .Os
150 .Sh NAME
151 .Nm src.conf
152 .Nd "source build options"
153 .Sh DESCRIPTION
154 The
155 .Nm
156 file contains settings that will apply to every build involving the
157 .Fx
158 source tree; see
159 .Xr build 7 .
160 .Pp
161 The
162 .Nm
163 file uses the standard makefile syntax.
164 However,
165 .Nm
166 should not specify any dependencies to
167 .Xr make 1 .
168 Instead,
169 .Nm
170 is to set
171 .Xr make 1
172 variables that control the aspects of how the system builds.
173 .Pp
174 The default location of
175 .Nm
176 is
177 .Pa /etc/src.conf ,
178 though an alternative location can be specified in the
179 .Xr make 1
180 variable
181 .Va SRCCONF .
182 Overriding the location of
183 .Nm
184 may be necessary if the system-wide settings are not suitable
185 for a particular build.
186 For instance, setting
187 .Va SRCCONF
188 to
189 .Pa /dev/null
190 effectively resets all build controls to their defaults.
191 .Pp
192 The only purpose of
193 .Nm
194 is to control the compilation of the
195 .Fx
196 source code, which is usually located in
197 .Pa /usr/src .
198 As a rule, the system administrator creates
199 .Nm
200 when the values of certain control variables need to be changed
201 from their defaults.
202 .Pp
203 In addition, control variables can be specified
204 for a particular build via the
205 .Fl D
206 option of
207 .Xr make 1
208 or in its environment; see
209 .Xr environ 7 .
210 .Pp
211 The environment of
212 .Xr make 1
213 for the build can be controlled via the
214 .Va SRC_ENV_CONF
215 variable, which defaults to
216 .Pa /etc/src-env.conf .
217 Some examples that may only be set in this file are
218 .Va WITH_DIRDEPS_BUILD ,
219 and
220 .Va WITH_META_MODE ,
221 and
222 .Va MAKEOBJDIRPREFIX
223 as they are environment-only variables.
224 .Pp
225 The values of variables are ignored regardless of their setting;
226 even if they would be set to
227 .Dq Li FALSE
228 or
229 .Dq Li NO .
230 The presence of an option causes
231 it to be honored by
232 .Xr make 1 .
233 .Pp
234 This list provides a name and short description for variables
235 that can be used for source builds.
236 .Bl -tag -width indent
237 EOF
238         show settings SRC_ENV_CONF=/dev/null | sort > $t/config_default
239         # Work around WITH_LDNS_UTILS forcing BIND_UTILS off by parsing the
240         # actual config that results from enabling every WITH_ option.  This
241         # can be reverted if/when we no longer have options that disable
242         # others.
243         show with SRC_ENV_CONF=/dev/null | sort | sed 's/$/=/' > $t/src.conf
244         show settings SRC_ENV_CONF=$t/src.conf | sort > $t/config_WITH_ALL
245         show without SRC_ENV_CONF=/dev/null | sort > $t/config_WITHOUT_ALL
246         env_only_options="$(${make} MK_AUTO_OBJ=no -V __ENV_ONLY_OPTIONS)"
247
248         show_options |
249         while read opt targets ; do
250                 if [ ! -f ${opt} ] ; then
251                         echo "no description found for ${opt}, skipping" >&2
252                         continue
253                 fi
254
255                 echo ".It Va ${opt}"
256                 sed -e'/\$FreeBSD.*\$/d' ${opt}
257                 if [ -n "${targets}" ] ; then
258                         echo '.Pp'
259                         echo 'This is a default setting on'
260                         echo $(echo ${targets} | sed -e's/ /, /g' -e's/\(.*\), /\1 and /').
261                 fi
262
263                 if [ "${opt%%_*}" = 'WITHOUT' ] ; then
264                         sed -n "/^WITH_${opt#WITHOUT_}$/!s/$/=/p" $t/config_WITH_ALL > $t/src.conf
265                         show settings SRC_ENV_CONF=$t/src.conf -D${opt} | sort > $t/config_WITH_ALL_${opt}
266                         comm -13 $t/config_WITH_ALL $t/config_WITH_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
267                 elif [ "${opt%%_*}" = 'WITH' ] ; then
268                         sed -n "/^WITHOUT${opt#WITH}$/!s/$/=/p" $t/config_WITHOUT_ALL > $t/src.conf
269                         show settings SRC_ENV_CONF=$t/src.conf -D${opt} | sort > $t/config_WITHOUT_ALL_${opt}
270                         comm -13 $t/config_WITHOUT_ALL $t/config_WITHOUT_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
271                 else
272                         echo 'internal error' >&2
273                         exit 1
274                 fi
275
276                 show settings SRC_ENV_CONF=/dev/null -D${opt} | sort > $t/config_${opt}
277                 comm -13 $t/config_default $t/config_${opt} | sed -n "/^${opt}$/!p" |
278                 comm -13 $t/deps - > $t/deps2
279
280                 havedeps=0
281                 if [ -s $t/deps ] ; then
282                         havedeps=1
283                         echo 'When set, it enforces these options:'
284                         echo '.Pp'
285                         echo '.Bl -item -compact'
286                         while read opt2 ; do
287                                 echo '.It'
288                                 echo ".Va ${opt2}"
289                         done < $t/deps
290                         echo '.El'
291                 fi
292
293                 if [ -s $t/deps2 ] ; then
294                         if [ ${havedeps} -eq 1 ] ; then
295                                 echo '.Pp'
296                         fi
297                         echo 'When set, these options are also in effect:'
298                         echo '.Pp'
299                         echo '.Bl -inset -compact'
300                         while read opt2 ; do
301                                 echo ".It Va ${opt2}"
302                                 noopt=$(echo ${opt2} | sed -e's/WITH_/WITHOUT_/;t' -e's/WITHOUT_/WITH_/')
303                                 echo '(unless'
304                                 echo ".Va ${noopt}"
305                                 echo 'is set explicitly)'
306                         done < $t/deps2
307                         echo '.El'
308                 fi
309
310                 case " ${env_only_options} " in
311                         *\ ${opt#*_}\ *)
312                                 echo ".Pp"
313                                 echo "This must be set in the environment, make command line, or"
314                                 echo ".Pa /etc/src-env.conf ,"
315                                 echo "not"
316                                 echo ".Pa /etc/src.conf ."
317                                 ;;
318                 esac
319
320                 twiddle >&2
321         done
322         cat <<EOF
323 .El
324 .Sh FILES
325 .Bl -tag -compact -width Pa
326 .It Pa /etc/src.conf
327 .It Pa /etc/src-env.conf
328 .It Pa /usr/share/mk/bsd.own.mk
329 .El
330 .Sh SEE ALSO
331 .Xr make 1 ,
332 .Xr make.conf 5 ,
333 .Xr build 7 ,
334 .Xr ports 7
335 .Sh HISTORY
336 The
337 .Nm
338 file appeared in
339 .Fx 7.0 .
340 .Sh AUTHORS
341 This manual page was autogenerated by
342 .An tools/build/options/makeman .
343 EOF
344 }
345
346 twiddle_pos=0
347 twiddle()
348 {
349         local c0='|' c1='/' c2='-' c3='\'
350
351         eval printf '%c\\b' '$c'${twiddle_pos}
352         twiddle_pos=$(((twiddle_pos+1)%4))
353 }
354
355 main