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