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