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