aboutsummaryrefslogtreecommitdiffstats
path: root/tools/build/options/makeman
blob: c59c7179a856311cca03247d87a6fdbdd0042dd5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/bin/sh
#
# This file is in the public domain.
# $FreeBSD$
#
# This script creates the src.conf.5 man page using template text contained
# herein and the contents of the WITH_* and WITHOUT_* files in the same
# directory. Each WITH_* and WITHOUT_* file documents the effect of the
# /etc/src.conf knob with the same name.
#
# For each supported architecture, "make showconfig" is invoked to determine
# the default setting of every option: always WITH_, always WITHOUT_, or
# architecture-dependent WITH_/WITHOUT_.  It also determines and describes
# dependencies between options.
#
# Usage:
#
#     cd tools/build/options
#     sh makeman > ../../../share/man/man5/src.conf.5

set -o errexit
export LC_ALL=C

t=$(mktemp -d -t makeman)
trap 'test -d $t && rm -rf $t' exit

srcdir=$(realpath ../../..)
make="make -C $srcdir -m $srcdir/share/mk"

#
# usage: no_targets all_targets yes_targets
#
no_targets()
{
	for t1 in $1 ; do
		for t2 in $2 ; do
			if [ "${t1}" = "${t2}" ] ; then
				continue 2
			fi
		done
		echo ${t1}
	done
}

show_options()
{
	ALL_TARGETS=$(echo $(${make} targets MK_AUTO_OBJ=no | tail -n +2))
	rm -f $t/settings
	for target in ${ALL_TARGETS} ; do
		prev_opt=
		env -i ${make} showconfig \
		    SRC_ENV_CONF=/dev/null SRCCONF=/dev/null \
		    __MAKE_CONF=/dev/null \
		    TARGET_ARCH=${target#*/} TARGET=${target%/*} |
		while read var _ val ; do
			opt=${var#MK_}
			if [ $opt = "$prev_opt" ]; then
				echo "$target: ignoring duplicate option $opt" >&2
				continue
			fi
			prev_opt=$opt
			case ${val} in
			yes)
				echo ${opt} ${target}
				;;
			no)
				echo ${opt}
				;;
			*)
				echo "make showconfig broken: ${var} ${_} ${val} (not yes or no)" >&2
				exit 1
				;;
			esac
		done > $t/settings.target
		if [ -r $t/settings ] ; then
			join -t\  $t/settings $t/settings.target > $t/settings.new
			mv $t/settings.new $t/settings
		else
			mv $t/settings.target $t/settings
		fi
	done

	while read opt targets ; do
		if [ "${targets}" = "${ALL_TARGETS}" ] ; then
			echo "WITHOUT_${opt}"
		elif [ -z "${targets}" ] ; then
			echo "WITH_${opt}"
		else
			echo "WITHOUT_${opt}" $(no_targets "${ALL_TARGETS}" "${targets}")
			echo "WITH_${opt} ${targets}"
		fi
	done < $t/settings
}

#
# usage: show { settings | with | without } ...
#
show()
{

	mode=$1 ; shift
	case ${mode} in
	settings)
		yes_prefix=WITH
		no_prefix=WITHOUT
		;;
	with)
		yes_prefix=WITH
		no_prefix=WITH
		;;
	without)
		yes_prefix=WITHOUT
		no_prefix=WITHOUT
		;;
	*)
		echo 'internal error' >&2
		exit 1
		;;
	esac
	env -i ${make} .MAKE.MODE=normal "$@" showconfig __MAKE_CONF=/dev/null \
	    SRCCONF=/dev/null |
	while read var _ val ; do
		opt=${var#MK_}
		case ${val} in
		yes)
			echo ${yes_prefix}_${opt}
			;;
		no)
			echo ${no_prefix}_${opt}
			;;
		*)
			echo "make showconfig broken: ${var} ${_} ${val} (not yes or no)" >&2
			exit 1
			;;
		esac
	done
}

main()
{
	echo "building src.conf.5 man page from files in ${PWD}" >&2

	fbsdid='$'FreeBSD'$'
	cat <<EOF
.\" DO NOT EDIT-- this file is generated by tools/build/options/makeman.
.\" ${fbsdid}
.Dd $(echo $(LC_TIME=C date +'%B %e, %Y'))
.Dt SRC.CONF 5
.Os
.Sh NAME
.Nm src.conf
.Nd "source build options"
.Sh DESCRIPTION
The
.Nm
file contains settings that will apply to every build involving the
.Fx
source tree; see
.Xr build 7 .
.Pp
The
.Nm
file uses the standard makefile syntax.
However,
.Nm
should not specify any dependencies to
.Xr make 1 .
Instead,
.Nm
is to set
.Xr make 1
variables that control the aspects of how the system builds.
.Pp
The default location of
.Nm
is
.Pa /etc/src.conf ,
though an alternative location can be specified in the
.Xr make 1
variable
.Va SRCCONF .
Overriding the location of
.Nm
may be necessary if the system-wide settings are not suitable
for a particular build.
For instance, setting
.Va SRCCONF
to
.Pa /dev/null
effectively resets all build controls to their defaults.
.Pp
The only purpose of
.Nm
is to control the compilation of the
.Fx
source code, which is usually located in
.Pa /usr/src .
As a rule, the system administrator creates
.Nm
when the values of certain control variables need to be changed
from their defaults.
.Pp
In addition, control variables can be specified
for a particular build via the
.Fl D
option of
.Xr make 1
or in its environment; see
.Xr environ 7 .
.Pp
The environment of
.Xr make 1
for the build can be controlled via the
.Va SRC_ENV_CONF
variable, which defaults to
.Pa /etc/src-env.conf .
Some examples that may only be set in this file are
.Va WITH_DIRDEPS_BUILD ,
and
.Va WITH_META_MODE ,
and
.Va MAKEOBJDIRPREFIX
as they are environment-only variables.
.Pp
The values of variables are ignored regardless of their setting;
even if they would be set to
.Dq Li FALSE
or
.Dq Li NO .
The presence of an option causes
it to be honored by
.Xr make 1 .
.Pp
This list provides a name and short description for variables
that can be used for source builds.
.Bl -tag -width indent
EOF
	show settings SRC_ENV_CONF=/dev/null | sort > $t/config_default
	# Work around WITH_LDNS_UTILS forcing BIND_UTILS off by parsing the
	# actual config that results from enabling every WITH_ option.  This
	# can be reverted if/when we no longer have options that disable
	# others.
	show with SRC_ENV_CONF=/dev/null | sort | sed 's/$/=/' > $t/src.conf
	show settings SRC_ENV_CONF=$t/src.conf | sort > $t/config_WITH_ALL
	show without SRC_ENV_CONF=/dev/null | sort > $t/config_WITHOUT_ALL
	env_only_options="$(${make} MK_AUTO_OBJ=no -V __ENV_ONLY_OPTIONS)"

	show_options |
	while read opt targets ; do
		if [ ! -f ${opt} ] ; then
			echo "no description found for ${opt}, skipping" >&2
			continue
		fi

		echo ".It Va ${opt}"
		sed -e'/\$FreeBSD.*\$/d' ${opt}
		if [ -n "${targets}" ] ; then
			echo '.Pp'
			echo 'This is a default setting on'
			echo $(echo ${targets} | sed -e's/ /, /g' -e's/\(.*\), /\1 and /').
		fi

		if [ "${opt%%_*}" = 'WITHOUT' ] ; then
			sed -n "/^WITH_${opt#WITHOUT_}$/!s/$/=/p" $t/config_WITH_ALL > $t/src.conf
			show settings SRC_ENV_CONF=$t/src.conf -D${opt} | sort > $t/config_WITH_ALL_${opt}
			comm -13 $t/config_WITH_ALL $t/config_WITH_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
		elif [ "${opt%%_*}" = 'WITH' ] ; then
			sed -n "/^WITHOUT${opt#WITH}$/!s/$/=/p" $t/config_WITHOUT_ALL > $t/src.conf
			show settings SRC_ENV_CONF=$t/src.conf -D${opt} | sort > $t/config_WITHOUT_ALL_${opt}
			comm -13 $t/config_WITHOUT_ALL $t/config_WITHOUT_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
		else
			echo 'internal error' >&2
			exit 1
		fi

		show settings SRC_ENV_CONF=/dev/null -D${opt} | sort > $t/config_${opt}
		comm -13 $t/config_default $t/config_${opt} | sed -n "/^${opt}$/!p" |
		comm -13 $t/deps - > $t/deps2

		havedeps=0
		if [ -s $t/deps ] ; then
			havedeps=1
			echo 'When set, it enforces these options:'
			echo '.Pp'
			echo '.Bl -item -compact'
			while read opt2 ; do
				echo '.It'
				echo ".Va ${opt2}"
			done < $t/deps
			echo '.El'
		fi

		if [ -s $t/deps2 ] ; then
			if [ ${havedeps} -eq 1 ] ; then
				echo '.Pp'
			fi
			echo 'When set, these options are also in effect:'
			echo '.Pp'
			echo '.Bl -inset -compact'
			while read opt2 ; do
				echo ".It Va ${opt2}"
				noopt=$(echo ${opt2} | sed -e's/WITH_/WITHOUT_/;t' -e's/WITHOUT_/WITH_/')
				echo '(unless'
				echo ".Va ${noopt}"
				echo 'is set explicitly)'
			done < $t/deps2
			echo '.El'
		fi

		case " ${env_only_options} " in
			*\ ${opt#*_}\ *)
				echo ".Pp"
				echo "This must be set in the environment, make command line, or"
				echo ".Pa /etc/src-env.conf ,"
				echo "not"
				echo ".Pa /etc/src.conf ."
				;;
		esac

		twiddle >&2
	done
	cat <<EOF
.El
.Sh FILES
.Bl -tag -compact -width Pa
.It Pa /etc/src.conf
.It Pa /etc/src-env.conf
.It Pa /usr/share/mk/bsd.own.mk
.El
.Sh SEE ALSO
.Xr make 1 ,
.Xr make.conf 5 ,
.Xr build 7 ,
.Xr ports 7
.Sh HISTORY
The
.Nm
file appeared in
.Fx 7.0 .
.Sh AUTHORS
This manual page was autogenerated by
.An tools/build/options/makeman .
EOF
}

twiddle_pos=0
twiddle()
{
	local c0='|' c1='/' c2='-' c3='\'

	eval printf '%c\\b' '$c'${twiddle_pos}
	twiddle_pos=$(((twiddle_pos+1)%4))
}

main