1156937Sru#!/bin/sh
2156937Sru#
3156937Sru# This file is in the public domain.
4156937Sru
5221730Sruset -o errexit
6253304SbaptLC_ALL=C
7221730Sru
8156937Sruident='$FreeBSD: stable/10/tools/build/options/makeman 318614 2017-05-22 06:08:20Z ngie $'
9156937Sru
10221730Srut=$(mktemp -d -t makeman)
11221730Srutrap 'test -d $t && rm -rf $t' exit
12221730Sru
13255964Sdessrcdir=$(realpath ../../..)
14255964Sdesmake="make -C $srcdir -m $srcdir/share/mk"
15255964Sdes
16156937Sru#
17221730Sru# usage: no_targets all_targets yes_targets
18156937Sru#
19221730Sruno_targets()
20221730Sru{
21221730Sru	for t1 in $1 ; do
22221730Sru		for t2 in $2 ; do
23221730Sru			if [ "${t1}" = "${t2}" ] ; then
24221730Sru				continue 2
25221730Sru			fi
26221730Sru		done
27221730Sru		echo ${t1}
28221730Sru	done
29221730Sru}
30221730Sru
31221730Srushow_options()
32221730Sru{
33255964Sdes	ALL_TARGETS=$(echo $(${make} targets | tail -n +2))
34221730Sru	rm -f $t/settings
35221730Sru	for target in ${ALL_TARGETS} ; do
36291805Sbdrewery		env -i ${make} showconfig \
37221730Sru		    SRCCONF=/dev/null __MAKE_CONF=/dev/null \
38221730Sru		    TARGET_ARCH=${target#*/} TARGET=${target%/*} |
39221730Sru		while read var _ val ; do
40221730Sru			opt=${var#MK_}
41221730Sru			case ${val} in
42221730Sru			yes)
43221730Sru				echo ${opt} ${target}
44221730Sru				;;
45221730Sru			no)
46221730Sru				echo ${opt}
47221730Sru				;;
48221730Sru			*)
49221730Sru				echo 'make showconfig broken' >&2
50221730Sru				exit 1
51221730Sru				;;
52221730Sru			esac
53221730Sru		done > $t/settings.target
54221730Sru		if [ -r $t/settings ] ; then
55221730Sru			join -t\  $t/settings $t/settings.target > $t/settings.new
56221730Sru			mv $t/settings.new $t/settings
57221730Sru		else
58221730Sru			mv $t/settings.target $t/settings
59221730Sru		fi
60221730Sru	done
61221730Sru
62288396Sbdrewery	while read opt targets ; do
63221730Sru		if [ "${targets}" = "${ALL_TARGETS}" ] ; then
64221730Sru			echo "WITHOUT_${opt}"
65221730Sru		elif [ -z "${targets}" ] ; then
66221730Sru			echo "WITH_${opt}"
67221730Sru		else
68221730Sru			echo "WITHOUT_${opt}" $(no_targets "${ALL_TARGETS}" "${targets}")
69221730Sru			echo "WITH_${opt} ${targets}"
70221730Sru		fi
71288396Sbdrewery	done < $t/settings
72221730Sru}
73221730Sru
74221730Sru#
75221730Sru# usage: show { settings | with | without } ...
76221730Sru#
77156937Srushow()
78156937Sru{
79156937Sru
80221730Sru	mode=$1 ; shift
81156937Sru	case ${mode} in
82156937Sru	settings)
83156937Sru		yes_prefix=WITH
84156937Sru		no_prefix=WITHOUT
85156937Sru		;;
86221730Sru	with)
87221730Sru		yes_prefix=WITH
88156937Sru		no_prefix=WITH
89156937Sru		;;
90221730Sru	without)
91221730Sru		yes_prefix=WITHOUT
92221730Sru		no_prefix=WITHOUT
93221730Sru		;;
94156937Sru	*)
95221730Sru		echo 'internal error' >&2
96156937Sru		exit 1
97156937Sru		;;
98156937Sru	esac
99291805Sbdrewery	env -i ${make} "$@" showconfig __MAKE_CONF=/dev/null |
100221730Sru	while read var _ val ; do
101156937Sru		opt=${var#MK_}
102156937Sru		case ${val} in
103156937Sru		yes)
104156937Sru			echo ${yes_prefix}_${opt}
105156937Sru			;;
106156937Sru		no)
107156937Sru			echo ${no_prefix}_${opt}
108156937Sru			;;
109156937Sru		*)
110221730Sru			echo 'make showconfig broken' >&2
111156937Sru			exit 1
112156937Sru			;;
113156937Sru		esac
114156937Sru	done
115156937Sru}
116156937Sru
117156937Srumain()
118156937Sru{
119156937Sru
120156937Sru	ident=${ident#$}
121156937Sru	ident=${ident% $}
122156939Sru	fbsdid='$'FreeBSD'$'
123156937Sru	cat <<EOF
124156937Sru.\" DO NOT EDIT-- this file is automatically generated.
125156937Sru.\" from ${ident}
126156937Sru.\" ${fbsdid}
127221730Sru.Dd $(echo $(LC_TIME=C date +'%B %e, %Y'))
128156937Sru.Dt SRC.CONF 5
129156937Sru.Os
130156937Sru.Sh NAME
131156937Sru.Nm src.conf
132158660Strhodes.Nd "source build options"
133156937Sru.Sh DESCRIPTION
134156937SruThe
135156937Sru.Nm
136156937Srufile contains settings that will apply to every build involving the
137156937Sru.Fx
138156937Srusource tree; see
139156937Sru.Xr build 7 .
140156937Sru.Pp
141156937SruThe
142156937Sru.Nm
143156937Srufile uses the standard makefile syntax.
144156937SruHowever,
145156937Sru.Nm
146156937Srushould not specify any dependencies to
147156937Sru.Xr make 1 .
148156937SruInstead,
149156937Sru.Nm
150156937Sruis to set
151156937Sru.Xr make 1
152156937Sruvariables that control the aspects of how the system builds.
153156937Sru.Pp
154156937SruThe default location of
155156937Sru.Nm
156156937Sruis
157156937Sru.Pa /etc/src.conf ,
158156937Sruthough an alternative location can be specified in the
159156937Sru.Xr make 1
160156937Sruvariable
161156937Sru.Va SRCCONF .
162156937SruOverriding the location of
163156937Sru.Nm
164173400Sdangermay be necessary if the system-wide settings are not suitable
165156937Srufor a particular build.
166156937SruFor instance, setting
167156937Sru.Va SRCCONF
168156937Sruto
169156937Sru.Pa /dev/null
170156937Srueffectively resets all build controls to their defaults.
171156937Sru.Pp
172156937SruThe only purpose of
173156937Sru.Nm
174156937Sruis to control the compilation of the
175156937Sru.Fx
176158660Strhodessource code, which is usually located in
177156937Sru.Pa /usr/src .
178156937SruAs a rule, the system administrator creates
179156937Sru.Nm
180156937Sruwhen the values of certain control variables need to be changed
181156937Srufrom their defaults.
182156937Sru.Pp
183156937SruIn addition, control variables can be specified
184156937Srufor a particular build via the
185156937Sru.Fl D
186156937Sruoption of
187156937Sru.Xr make 1
188188848Smtmor in its environment; see
189156937Sru.Xr environ 7 .
190156937Sru.Pp
191158758StrhodesThe values of variables are ignored regardless of their setting;
192158660Strhodeseven if they would be set to
193156937Sru.Dq Li FALSE
194156937Sruor
195158660Strhodes.Dq Li NO .
196158660StrhodesJust the existence of an option will cause
197158660Strhodesit to be honoured by
198158660Strhodes.Xr make 1 .
199156937Sru.Pp
200156937SruThe following list provides a name and short description for variables
201156937Sruthat can be used for source builds.
202156937Sru.Bl -tag -width indent
203156937SruEOF
204221730Sru	show settings SRCCONF=/dev/null | sort > $t/config_default
205251601Semaste	# Work around WITH_LDNS_UTILS forcing BIND_UTILS off by parsing the
206251601Semaste	# actual config that results from enabling every WITH_ option.  This
207251601Semaste	# can be reverted if/when we no longer have options that disable
208251601Semaste	# others.
209251601Semaste	show with SRCCONF=/dev/null | sort | sed 's/$/=/' > $t/src.conf
210251601Semaste	show settings SRCCONF=$t/src.conf | sort > $t/config_WITH_ALL
211221730Sru	show without SRCCONF=/dev/null | sort > $t/config_WITHOUT_ALL
212221730Sru
213221730Sru	show_options |
214221730Sru	while read opt targets ; do
215221730Sru		if [ ! -f ${opt} ] ; then
216221730Sru			echo "no description found for ${opt}, skipping" >&2
217221730Sru			continue
218221730Sru		fi
219221730Sru
220221732Sru		echo ".It Va ${opt}"
221221732Sru		sed -e's/\$\(FreeBSD: .*\) \$/from \1/' ${opt}
222221732Sru		if [ -n "${targets}" ] ; then
223221732Sru			echo '.Pp'
224221732Sru			echo 'It is a default setting on'
225221732Sru			echo $(echo ${targets} | sed -e's/ /, /g' -e's/\(.*\), /\1 and /').
226221732Sru		fi
227221732Sru
228221732Sru		if [ "${opt%%_*}" = 'WITHOUT' ] ; then
229221730Sru			sed -n "/^WITH_${opt#WITHOUT_}$/!s/$/=/p" $t/config_WITH_ALL > $t/src.conf
230221730Sru			show settings SRCCONF=$t/src.conf -D${opt} | sort > $t/config_WITH_ALL_${opt}
231221730Sru			comm -13 $t/config_WITH_ALL $t/config_WITH_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
232221732Sru		elif [ "${opt%%_*}" = 'WITH' ] ; then
233221730Sru			sed -n "/^WITHOUT${opt#WITH}$/!s/$/=/p" $t/config_WITHOUT_ALL > $t/src.conf
234221730Sru			show settings SRCCONF=$t/src.conf -D${opt} | sort > $t/config_WITHOUT_ALL_${opt}
235221730Sru			comm -13 $t/config_WITHOUT_ALL $t/config_WITHOUT_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
236156937Sru		else
237221730Sru			echo 'internal error' >&2
238221730Sru			exit 1
239156937Sru		fi
240221730Sru
241251601Semaste		show settings SRCCONF=/dev/null -D${opt} | sort > $t/config_${opt}
242251601Semaste		comm -13 $t/config_default $t/config_${opt} | sed -n "/^${opt}$/!p" |
243251601Semaste		comm -13 $t/deps - > $t/deps2
244251601Semaste
245251601Semaste		# Work around BIND_UTILS=no being the default when every WITH_
246251601Semaste		# option is enabled.
247251685Semaste		if [ "$(cat $t/deps2)" = WITHOUT_BIND_UTILS ]; then
248251601Semaste			sort $t/deps $t/deps2 > $t/_deps
249251601Semaste			mv $t/_deps $t/deps
250251601Semaste			:> $t/deps2
251251601Semaste		fi
252251601Semaste
253288396Sbdrewery		havedeps=0
254221730Sru		if [ -s $t/deps ] ; then
255288396Sbdrewery			havedeps=1
256221730Sru			echo 'When set, it also enforces the following options:'
257221730Sru			echo '.Pp'
258221730Sru			echo '.Bl -item -compact'
259288396Sbdrewery			while read opt2 ; do
260221730Sru				echo '.It'
261221730Sru				echo ".Va ${opt2}"
262288396Sbdrewery			done < $t/deps
263221730Sru			echo '.El'
264156937Sru		fi
265221730Sru
266221730Sru		if [ -s $t/deps2 ] ; then
267288396Sbdrewery			if [ ${havedeps} -eq 1 ] ; then
268221730Sru				echo '.Pp'
269221730Sru			fi
270221730Sru			echo 'When set, the following options are also in effect:'
271221730Sru			echo '.Pp'
272221730Sru			echo '.Bl -inset -compact'
273288396Sbdrewery			while read opt2 ; do
274221730Sru				echo ".It Va ${opt2}"
275221730Sru				noopt=$(echo ${opt2} | sed -e's/WITH_/WITHOUT_/;t' -e's/WITHOUT_/WITH_/')
276221730Sru				echo '(unless'
277221730Sru				echo ".Va ${noopt}"
278221730Sru				echo 'is set explicitly)'
279288396Sbdrewery			done < $t/deps2
280221730Sru			echo '.El'
281221730Sru		fi
282221733Sru		twiddle >&2
283156937Sru	done
284156937Sru	cat <<EOF
285156937Sru.El
286156937Sru.Sh FILES
287236279Sgjb.Bl -tag -compact -width Pa
288156937Sru.It Pa /etc/src.conf
289156937Sru.It Pa /usr/share/mk/bsd.own.mk
290156937Sru.El
291156937Sru.Sh SEE ALSO
292156937Sru.Xr make 1 ,
293156937Sru.Xr make.conf 5 ,
294156937Sru.Xr build 7 ,
295156937Sru.Xr ports 7
296156937Sru.Sh HISTORY
297156937SruThe
298156937Sru.Nm
299156937Srufile appeared in
300156937Sru.Fx 7.0 .
301156937Sru.Sh AUTHORS
302318614SngieThis manual page was autogenerated by
303318614Sngie.An tools/build/options/makeman .
304156937SruEOF
305156937Sru}
306156937Sru
307221733Srutwiddle_pos=0
308221733Srutwiddle()
309221733Sru{
310221733Sru	local c0='|' c1='/' c2='-' c3='\'
311221733Sru
312221733Sru	eval printf '%c\\b' '$c'${twiddle_pos}
313221733Sru	twiddle_pos=$(((twiddle_pos+1)%4))
314221733Sru}
315221733Sru
316156937Srumain
317