]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/build/options/makeman
MFC r334072, r334247 (eadler): Add the text '@generated' to src.conf.5
[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 | 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   generated='@'generated
145         cat <<EOF
146 .\" DO NOT EDIT-- this file is $generated by tools/build/options/makeman.
147 .\" ${fbsdid}
148 .Dd $(echo $(LC_TIME=C date +'%B %e, %Y'))
149 .Dt SRC.CONF 5
150 .Os
151 .Sh NAME
152 .Nm src.conf
153 .Nd "source build options"
154 .Sh DESCRIPTION
155 The
156 .Nm
157 file contains settings that will apply to every build involving the
158 .Fx
159 source tree; see
160 .Xr build 7 .
161 .Pp
162 The
163 .Nm
164 file uses the standard makefile syntax.
165 However,
166 .Nm
167 should not specify any dependencies to
168 .Xr make 1 .
169 Instead,
170 .Nm
171 is to set
172 .Xr make 1
173 variables that control the aspects of how the system builds.
174 .Pp
175 The default location of
176 .Nm
177 is
178 .Pa /etc/src.conf ,
179 though an alternative location can be specified in the
180 .Xr make 1
181 variable
182 .Va SRCCONF .
183 Overriding the location of
184 .Nm
185 may be necessary if the system-wide settings are not suitable
186 for a particular build.
187 For instance, setting
188 .Va SRCCONF
189 to
190 .Pa /dev/null
191 effectively resets all build controls to their defaults.
192 .Pp
193 The only purpose of
194 .Nm
195 is to control the compilation of the
196 .Fx
197 source code, which is usually located in
198 .Pa /usr/src .
199 As a rule, the system administrator creates
200 .Nm
201 when the values of certain control variables need to be changed
202 from their defaults.
203 .Pp
204 In addition, control variables can be specified
205 for a particular build via the
206 .Fl D
207 option of
208 .Xr make 1
209 or in its environment; see
210 .Xr environ 7 .
211 .Pp
212 The environment of
213 .Xr make 1
214 for the build can be controlled via the
215 .Va SRC_ENV_CONF
216 variable, which defaults to
217 .Pa /etc/src-env.conf .
218 Some examples that may only be set in this file are
219 .Va WITH_DIRDEPS_BUILD ,
220 and
221 .Va WITH_META_MODE
222 as they are environment-only variables.
223 Note that
224 .Va MAKEOBJDIRPREFIX
225 may be set here only when using
226 .Va WITH_DIRDEPS_BUILD .
227 .Pp
228 The values of variables are ignored regardless of their setting;
229 even if they would be set to
230 .Dq Li FALSE
231 or
232 .Dq Li NO .
233 The presence of an option causes
234 it to be honored by
235 .Xr make 1 .
236 .Pp
237 This list provides a name and short description for variables
238 that can be used for source builds.
239 .Bl -tag -width indent
240 EOF
241         show settings SRC_ENV_CONF=/dev/null | sort > $t/config_default
242         # Work around WITH_LDNS_UTILS forcing BIND_UTILS off by parsing the
243         # actual config that results from enabling every WITH_ option.  This
244         # can be reverted if/when we no longer have options that disable
245         # others.
246         show with SRC_ENV_CONF=/dev/null | sort | sed 's/$/=/' > $t/src.conf
247         show settings SRC_ENV_CONF=$t/src.conf | sort > $t/config_WITH_ALL
248         show without SRC_ENV_CONF=/dev/null | sort > $t/config_WITHOUT_ALL
249         env_only_options="$(${make} -V __ENV_ONLY_OPTIONS)"
250
251         show_options |
252         while read opt targets ; do
253                 if [ ! -f ${opt} ] ; then
254                         echo "no description found for ${opt}, skipping" >&2
255                         continue
256                 fi
257
258                 echo ".It Va ${opt}"
259                 sed -e'/\$FreeBSD.*\$/d' ${opt}
260                 if [ -n "${targets}" ] ; then
261                         echo '.Pp'
262                         echo 'This is a default setting on'
263                         echo $(echo ${targets} | sed -e's/ /, /g' -e's/\(.*\), /\1 and /').
264                 fi
265
266                 if [ "${opt%%_*}" = 'WITHOUT' ] ; then
267                         sed -n "/^WITH_${opt#WITHOUT_}$/!s/$/=/p" $t/config_WITH_ALL > $t/src.conf
268                         show settings SRC_ENV_CONF=$t/src.conf -D${opt} | sort > $t/config_WITH_ALL_${opt}
269                         comm -13 $t/config_WITH_ALL $t/config_WITH_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
270                 elif [ "${opt%%_*}" = 'WITH' ] ; then
271                         sed -n "/^WITHOUT${opt#WITH}$/!s/$/=/p" $t/config_WITHOUT_ALL > $t/src.conf
272                         show settings SRC_ENV_CONF=$t/src.conf -D${opt} | sort > $t/config_WITHOUT_ALL_${opt}
273                         comm -13 $t/config_WITHOUT_ALL $t/config_WITHOUT_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
274                 else
275                         echo 'internal error' >&2
276                         exit 1
277                 fi
278
279                 show settings SRC_ENV_CONF=/dev/null -D${opt} | sort > $t/config_${opt}
280                 comm -13 $t/config_default $t/config_${opt} | sed -n "/^${opt}$/!p" |
281                 comm -13 $t/deps - > $t/deps2
282
283                 # Work around BIND_UTILS=no being the default when every WITH_
284                 # option is enabled.
285                 if [ "$(cat $t/deps2)" = WITHOUT_BIND_UTILS ]; then
286                         sort $t/deps $t/deps2 > $t/_deps
287                         mv $t/_deps $t/deps
288                         :> $t/deps2
289                 fi
290
291                 havedeps=0
292                 if [ -s $t/deps ] ; then
293                         havedeps=1
294                         echo 'When set, it enforces these options:'
295                         echo '.Pp'
296                         echo '.Bl -item -compact'
297                         while read opt2 ; do
298                                 echo '.It'
299                                 echo ".Va ${opt2}"
300                         done < $t/deps
301                         echo '.El'
302                 fi
303
304                 if [ -s $t/deps2 ] ; then
305                         if [ ${havedeps} -eq 1 ] ; then
306                                 echo '.Pp'
307                         fi
308                         echo 'When set, these options are also in effect:'
309                         echo '.Pp'
310                         echo '.Bl -inset -compact'
311                         while read opt2 ; do
312                                 echo ".It Va ${opt2}"
313                                 noopt=$(echo ${opt2} | sed -e's/WITH_/WITHOUT_/;t' -e's/WITHOUT_/WITH_/')
314                                 echo '(unless'
315                                 echo ".Va ${noopt}"
316                                 echo 'is set explicitly)'
317                         done < $t/deps2
318                         echo '.El'
319                 fi
320
321                 case " ${env_only_options} " in
322                         *\ ${opt#*_}\ *)
323                                 echo ".Pp"
324                                 echo "This must be set in the environment, make command line, or"
325                                 echo ".Pa /etc/src-env.conf ,"
326                                 echo "not"
327                                 echo ".Pa /etc/src.conf ."
328                                 ;;
329                 esac
330
331                 twiddle >&2
332         done
333         cat <<EOF
334 .El
335 .Sh FILES
336 .Bl -tag -compact -width Pa
337 .It Pa /etc/src.conf
338 .It Pa /etc/src-env.conf
339 .It Pa /usr/share/mk/bsd.own.mk
340 .El
341 .Sh SEE ALSO
342 .Xr make 1 ,
343 .Xr make.conf 5 ,
344 .Xr build 7 ,
345 .Xr ports 7
346 .Sh HISTORY
347 The
348 .Nm
349 file appeared in
350 .Fx 7.0 .
351 .Sh AUTHORS
352 This manual page was autogenerated by
353 .An tools/build/options/makeman .
354 EOF
355 }
356
357 twiddle_pos=0
358 twiddle()
359 {
360         local c0='|' c1='/' c2='-' c3='\'
361
362         eval printf '%c\\b' '$c'${twiddle_pos}
363         twiddle_pos=$(((twiddle_pos+1)%4))
364 }
365
366 main