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