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