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