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