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