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