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