xref: /freebsd/tools/build/options/makeman (revision f1f871e17de8d1adb9d36f53176b422b1faa6f14)
1c5922fbfSRuslan Ermilov#!/bin/sh
2c5922fbfSRuslan Ermilov#
3c5922fbfSRuslan Ermilov# This file is in the public domain.
4c5922fbfSRuslan Ermilov
52701a1b7SRuslan Ermilovset -o errexit
6*f1f871e1SHajimu UMEMOTOexport LC_ALL=C
72701a1b7SRuslan Ermilov
8c5922fbfSRuslan Ermilovident='$FreeBSD$'
9c5922fbfSRuslan Ermilov
102701a1b7SRuslan Ermilovt=$(mktemp -d -t makeman)
112701a1b7SRuslan Ermilovtrap 'test -d $t && rm -rf $t' exit
122701a1b7SRuslan Ermilov
1369c469c9SDag-Erling Smørgravsrcdir=$(realpath ../../..)
1469c469c9SDag-Erling Smørgravmake="make -C $srcdir -m $srcdir/share/mk"
1569c469c9SDag-Erling Smørgrav
16c5922fbfSRuslan Ermilov#
172701a1b7SRuslan Ermilov# usage: no_targets all_targets yes_targets
182701a1b7SRuslan Ermilov#
192701a1b7SRuslan Ermilovno_targets()
202701a1b7SRuslan Ermilov{
212701a1b7SRuslan Ermilov	for t1 in $1 ; do
222701a1b7SRuslan Ermilov		for t2 in $2 ; do
232701a1b7SRuslan Ermilov			if [ "${t1}" = "${t2}" ] ; then
242701a1b7SRuslan Ermilov				continue 2
252701a1b7SRuslan Ermilov			fi
262701a1b7SRuslan Ermilov		done
272701a1b7SRuslan Ermilov		echo ${t1}
282701a1b7SRuslan Ermilov	done
292701a1b7SRuslan Ermilov}
302701a1b7SRuslan Ermilov
312701a1b7SRuslan Ermilovshow_options()
322701a1b7SRuslan Ermilov{
3369c469c9SDag-Erling Smørgrav	ALL_TARGETS=$(echo $(${make} targets | tail -n +2))
342701a1b7SRuslan Ermilov	rm -f $t/settings
352701a1b7SRuslan Ermilov	for target in ${ALL_TARGETS} ; do
363dfad7c7SBryan Drewery		env -i ${make} showconfig \
37317c99b7SBryan Drewery		    SRC_ENV_CONF=/dev/null SRCCONF=/dev/null \
38317c99b7SBryan Drewery		    __MAKE_CONF=/dev/null \
392701a1b7SRuslan Ermilov		    TARGET_ARCH=${target#*/} TARGET=${target%/*} |
402701a1b7SRuslan Ermilov		while read var _ val ; do
412701a1b7SRuslan Ermilov			opt=${var#MK_}
422701a1b7SRuslan Ermilov			case ${val} in
432701a1b7SRuslan Ermilov			yes)
442701a1b7SRuslan Ermilov				echo ${opt} ${target}
452701a1b7SRuslan Ermilov				;;
462701a1b7SRuslan Ermilov			no)
472701a1b7SRuslan Ermilov				echo ${opt}
482701a1b7SRuslan Ermilov				;;
492701a1b7SRuslan Ermilov			*)
50cc2520d2SSimon J. Gerraty				echo "make showconfig broken: ${var} ${_} ${val} (not yes or no)" >&2
512701a1b7SRuslan Ermilov				exit 1
522701a1b7SRuslan Ermilov				;;
532701a1b7SRuslan Ermilov			esac
542701a1b7SRuslan Ermilov		done > $t/settings.target
552701a1b7SRuslan Ermilov		if [ -r $t/settings ] ; then
562701a1b7SRuslan Ermilov			join -t\  $t/settings $t/settings.target > $t/settings.new
572701a1b7SRuslan Ermilov			mv $t/settings.new $t/settings
582701a1b7SRuslan Ermilov		else
592701a1b7SRuslan Ermilov			mv $t/settings.target $t/settings
602701a1b7SRuslan Ermilov		fi
612701a1b7SRuslan Ermilov	done
622701a1b7SRuslan Ermilov
634078537cSBryan Drewery	while read opt targets ; do
642701a1b7SRuslan Ermilov		if [ "${targets}" = "${ALL_TARGETS}" ] ; then
652701a1b7SRuslan Ermilov			echo "WITHOUT_${opt}"
662701a1b7SRuslan Ermilov		elif [ -z "${targets}" ] ; then
672701a1b7SRuslan Ermilov			echo "WITH_${opt}"
682701a1b7SRuslan Ermilov		else
692701a1b7SRuslan Ermilov			echo "WITHOUT_${opt}" $(no_targets "${ALL_TARGETS}" "${targets}")
702701a1b7SRuslan Ermilov			echo "WITH_${opt} ${targets}"
712701a1b7SRuslan Ermilov		fi
724078537cSBryan Drewery	done < $t/settings
732701a1b7SRuslan Ermilov}
742701a1b7SRuslan Ermilov
752701a1b7SRuslan Ermilov#
762701a1b7SRuslan Ermilov# usage: show { settings | with | without } ...
77c5922fbfSRuslan Ermilov#
78c5922fbfSRuslan Ermilovshow()
79c5922fbfSRuslan Ermilov{
80c5922fbfSRuslan Ermilov
81c5922fbfSRuslan Ermilov	mode=$1 ; shift
82c5922fbfSRuslan Ermilov	case ${mode} in
83c5922fbfSRuslan Ermilov	settings)
84c5922fbfSRuslan Ermilov		yes_prefix=WITH
85c5922fbfSRuslan Ermilov		no_prefix=WITHOUT
86c5922fbfSRuslan Ermilov		;;
872701a1b7SRuslan Ermilov	with)
882701a1b7SRuslan Ermilov		yes_prefix=WITH
89c5922fbfSRuslan Ermilov		no_prefix=WITH
90c5922fbfSRuslan Ermilov		;;
912701a1b7SRuslan Ermilov	without)
922701a1b7SRuslan Ermilov		yes_prefix=WITHOUT
932701a1b7SRuslan Ermilov		no_prefix=WITHOUT
942701a1b7SRuslan Ermilov		;;
95c5922fbfSRuslan Ermilov	*)
962701a1b7SRuslan Ermilov		echo 'internal error' >&2
97c5922fbfSRuslan Ermilov		exit 1
98c5922fbfSRuslan Ermilov		;;
99c5922fbfSRuslan Ermilov	esac
1003dfad7c7SBryan Drewery	env -i ${make} .MAKE.MODE=normal "$@" showconfig __MAKE_CONF=/dev/null \
101317c99b7SBryan Drewery	    SRCCONF=/dev/null |
102c5922fbfSRuslan Ermilov	while read var _ val ; do
103c5922fbfSRuslan Ermilov		opt=${var#MK_}
104c5922fbfSRuslan Ermilov		case ${val} in
105c5922fbfSRuslan Ermilov		yes)
106c5922fbfSRuslan Ermilov			echo ${yes_prefix}_${opt}
107c5922fbfSRuslan Ermilov			;;
108c5922fbfSRuslan Ermilov		no)
109c5922fbfSRuslan Ermilov			echo ${no_prefix}_${opt}
110c5922fbfSRuslan Ermilov			;;
111c5922fbfSRuslan Ermilov		*)
112cc2520d2SSimon J. Gerraty			echo "make showconfig broken: ${var} ${_} ${val} (not yes or no)" >&2
113c5922fbfSRuslan Ermilov			exit 1
114c5922fbfSRuslan Ermilov			;;
115c5922fbfSRuslan Ermilov		esac
116c5922fbfSRuslan Ermilov	done
117c5922fbfSRuslan Ermilov}
118c5922fbfSRuslan Ermilov
119c5922fbfSRuslan Ermilovmain()
120c5922fbfSRuslan Ermilov{
121c5922fbfSRuslan Ermilov
122c5922fbfSRuslan Ermilov	ident=${ident#$}
123c5922fbfSRuslan Ermilov	ident=${ident% $}
12441c8ddc3SRuslan Ermilov	fbsdid='$'FreeBSD'$'
125c5922fbfSRuslan Ermilov	cat <<EOF
126c5922fbfSRuslan Ermilov.\" DO NOT EDIT-- this file is automatically generated.
127c5922fbfSRuslan Ermilov.\" from ${ident}
128c5922fbfSRuslan Ermilov.\" ${fbsdid}
1292701a1b7SRuslan Ermilov.Dd $(echo $(LC_TIME=C date +'%B %e, %Y'))
130c5922fbfSRuslan Ermilov.Dt SRC.CONF 5
131c5922fbfSRuslan Ermilov.Os
132c5922fbfSRuslan Ermilov.Sh NAME
133c5922fbfSRuslan Ermilov.Nm src.conf
13457caf3d6STom Rhodes.Nd "source build options"
135c5922fbfSRuslan Ermilov.Sh DESCRIPTION
136c5922fbfSRuslan ErmilovThe
137c5922fbfSRuslan Ermilov.Nm
138c5922fbfSRuslan Ermilovfile contains settings that will apply to every build involving the
139c5922fbfSRuslan Ermilov.Fx
140c5922fbfSRuslan Ermilovsource tree; see
141c5922fbfSRuslan Ermilov.Xr build 7 .
142c5922fbfSRuslan Ermilov.Pp
143c5922fbfSRuslan ErmilovThe
144c5922fbfSRuslan Ermilov.Nm
145c5922fbfSRuslan Ermilovfile uses the standard makefile syntax.
146c5922fbfSRuslan ErmilovHowever,
147c5922fbfSRuslan Ermilov.Nm
148c5922fbfSRuslan Ermilovshould not specify any dependencies to
149c5922fbfSRuslan Ermilov.Xr make 1 .
150c5922fbfSRuslan ErmilovInstead,
151c5922fbfSRuslan Ermilov.Nm
152c5922fbfSRuslan Ermilovis to set
153c5922fbfSRuslan Ermilov.Xr make 1
154c5922fbfSRuslan Ermilovvariables that control the aspects of how the system builds.
155c5922fbfSRuslan Ermilov.Pp
156c5922fbfSRuslan ErmilovThe default location of
157c5922fbfSRuslan Ermilov.Nm
158c5922fbfSRuslan Ermilovis
159c5922fbfSRuslan Ermilov.Pa /etc/src.conf ,
160c5922fbfSRuslan Ermilovthough an alternative location can be specified in the
161c5922fbfSRuslan Ermilov.Xr make 1
162c5922fbfSRuslan Ermilovvariable
163c5922fbfSRuslan Ermilov.Va SRCCONF .
164c5922fbfSRuslan ErmilovOverriding the location of
165c5922fbfSRuslan Ermilov.Nm
166c5922fbfSRuslan Ermilovmay be necessary if the system-wide settings are not suitable
167c5922fbfSRuslan Ermilovfor a particular build.
168c5922fbfSRuslan ErmilovFor instance, setting
169c5922fbfSRuslan Ermilov.Va SRCCONF
170c5922fbfSRuslan Ermilovto
171c5922fbfSRuslan Ermilov.Pa /dev/null
172c5922fbfSRuslan Ermiloveffectively resets all build controls to their defaults.
173c5922fbfSRuslan Ermilov.Pp
174c5922fbfSRuslan ErmilovThe only purpose of
175c5922fbfSRuslan Ermilov.Nm
176c5922fbfSRuslan Ermilovis to control the compilation of the
177c5922fbfSRuslan Ermilov.Fx
17857caf3d6STom Rhodessource code, which is usually located in
179c5922fbfSRuslan Ermilov.Pa /usr/src .
180c5922fbfSRuslan ErmilovAs a rule, the system administrator creates
181c5922fbfSRuslan Ermilov.Nm
182c5922fbfSRuslan Ermilovwhen the values of certain control variables need to be changed
183c5922fbfSRuslan Ermilovfrom their defaults.
184c5922fbfSRuslan Ermilov.Pp
185c5922fbfSRuslan ErmilovIn addition, control variables can be specified
186c5922fbfSRuslan Ermilovfor a particular build via the
187c5922fbfSRuslan Ermilov.Fl D
188c5922fbfSRuslan Ermilovoption of
189c5922fbfSRuslan Ermilov.Xr make 1
1903d919b75SMike Makonnenor in its environment; see
191c5922fbfSRuslan Ermilov.Xr environ 7 .
192c5922fbfSRuslan Ermilov.Pp
193ca045714SBryan DreweryThe environment of
194ca045714SBryan Drewery.Xr make 1
195ca045714SBryan Dreweryfor the build can be controlled via the
196ca045714SBryan Drewery.Va SRC_ENV_CONF
197ca045714SBryan Dreweryvariable, which defaults to
198ca045714SBryan Drewery.Pa /etc/src-env.conf .
199ca045714SBryan DrewerySome examples that may only be set in this file are
200ca045714SBryan Drewery.Va MAKEOBJDIRPREFIX ,
20132b5dc9aSSimon J. Gerraty.Va WITH_DIRDEPS_BUILD ,
202ca045714SBryan Dreweryand
203ca045714SBryan Drewery.Va WITH_META_MODE
204ca045714SBryan Dreweryas they are environment-only variables.
205ca045714SBryan Drewery.Pp
20607b7d7fbSTom RhodesThe values of variables are ignored regardless of their setting;
20757caf3d6STom Rhodeseven if they would be set to
208c5922fbfSRuslan Ermilov.Dq Li FALSE
209c5922fbfSRuslan Ermilovor
21057caf3d6STom Rhodes.Dq Li NO .
21157caf3d6STom RhodesJust the existence of an option will cause
21257caf3d6STom Rhodesit to be honoured by
21357caf3d6STom Rhodes.Xr make 1 .
214c5922fbfSRuslan Ermilov.Pp
215c5922fbfSRuslan ErmilovThe following list provides a name and short description for variables
216c5922fbfSRuslan Ermilovthat can be used for source builds.
217c5922fbfSRuslan Ermilov.Bl -tag -width indent
218c5922fbfSRuslan ErmilovEOF
219317c99b7SBryan Drewery	show settings SRC_ENV_CONF=/dev/null | sort > $t/config_default
220f506e293SEd Maste	# Work around WITH_LDNS_UTILS forcing BIND_UTILS off by parsing the
221f506e293SEd Maste	# actual config that results from enabling every WITH_ option.  This
222f506e293SEd Maste	# can be reverted if/when we no longer have options that disable
223f506e293SEd Maste	# others.
224317c99b7SBryan Drewery	show with SRC_ENV_CONF=/dev/null | sort | sed 's/$/=/' > $t/src.conf
225317c99b7SBryan Drewery	show settings SRC_ENV_CONF=$t/src.conf | sort > $t/config_WITH_ALL
226317c99b7SBryan Drewery	show without SRC_ENV_CONF=/dev/null | sort > $t/config_WITHOUT_ALL
227da6e996dSBryan Drewery	env_only_options="$(${make} -V __ENV_ONLY_OPTIONS)"
2282701a1b7SRuslan Ermilov
2292701a1b7SRuslan Ermilov	show_options |
2302701a1b7SRuslan Ermilov	while read opt targets ; do
2312701a1b7SRuslan Ermilov		if [ ! -f ${opt} ] ; then
2322701a1b7SRuslan Ermilov			echo "no description found for ${opt}, skipping" >&2
233c3b08cc6SYaroslav Tykhiy			continue
234cae68befSRuslan Ermilov		fi
235cae68befSRuslan Ermilov
2362701a1b7SRuslan Ermilov		echo ".It Va ${opt}"
2372701a1b7SRuslan Ermilov		sed -e's/\$\(FreeBSD: .*\) \$/from \1/' ${opt}
2382701a1b7SRuslan Ermilov		if [ -n "${targets}" ] ; then
2392701a1b7SRuslan Ermilov			echo '.Pp'
2402701a1b7SRuslan Ermilov			echo 'It is a default setting on'
2412701a1b7SRuslan Ermilov			echo $(echo ${targets} | sed -e's/ /, /g' -e's/\(.*\), /\1 and /').
242c5922fbfSRuslan Ermilov		fi
2432701a1b7SRuslan Ermilov
244cae68befSRuslan Ermilov		if [ "${opt%%_*}" = 'WITHOUT' ] ; then
2452701a1b7SRuslan Ermilov			sed -n "/^WITH_${opt#WITHOUT_}$/!s/$/=/p" $t/config_WITH_ALL > $t/src.conf
246317c99b7SBryan Drewery			show settings SRC_ENV_CONF=$t/src.conf -D${opt} | sort > $t/config_WITH_ALL_${opt}
2472701a1b7SRuslan Ermilov			comm -13 $t/config_WITH_ALL $t/config_WITH_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
248cae68befSRuslan Ermilov		elif [ "${opt%%_*}" = 'WITH' ] ; then
2492701a1b7SRuslan Ermilov			sed -n "/^WITHOUT${opt#WITH}$/!s/$/=/p" $t/config_WITHOUT_ALL > $t/src.conf
250317c99b7SBryan Drewery			show settings SRC_ENV_CONF=$t/src.conf -D${opt} | sort > $t/config_WITHOUT_ALL_${opt}
2512701a1b7SRuslan Ermilov			comm -13 $t/config_WITHOUT_ALL $t/config_WITHOUT_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
2522701a1b7SRuslan Ermilov		else
2532701a1b7SRuslan Ermilov			echo 'internal error' >&2
2542701a1b7SRuslan Ermilov			exit 1
2552701a1b7SRuslan Ermilov		fi
2562701a1b7SRuslan Ermilov
257317c99b7SBryan Drewery		show settings SRC_ENV_CONF=/dev/null -D${opt} | sort > $t/config_${opt}
258f506e293SEd Maste		comm -13 $t/config_default $t/config_${opt} | sed -n "/^${opt}$/!p" |
259f506e293SEd Maste		comm -13 $t/deps - > $t/deps2
260f506e293SEd Maste
261f506e293SEd Maste		# Work around BIND_UTILS=no being the default when every WITH_
262f506e293SEd Maste		# option is enabled.
263e60c420fSEd Maste		if [ "$(cat $t/deps2)" = WITHOUT_BIND_UTILS ]; then
264f506e293SEd Maste			sort $t/deps $t/deps2 > $t/_deps
265f506e293SEd Maste			mv $t/_deps $t/deps
266f506e293SEd Maste			:> $t/deps2
267f506e293SEd Maste		fi
268f506e293SEd Maste
2694078537cSBryan Drewery		havedeps=0
2702701a1b7SRuslan Ermilov		if [ -s $t/deps ] ; then
2714078537cSBryan Drewery			havedeps=1
2722701a1b7SRuslan Ermilov			echo 'When set, it also enforces the following options:'
2732701a1b7SRuslan Ermilov			echo '.Pp'
2742701a1b7SRuslan Ermilov			echo '.Bl -item -compact'
2754078537cSBryan Drewery			while read opt2 ; do
2762701a1b7SRuslan Ermilov				echo '.It'
2772701a1b7SRuslan Ermilov				echo ".Va ${opt2}"
2784078537cSBryan Drewery			done < $t/deps
2792701a1b7SRuslan Ermilov			echo '.El'
2802701a1b7SRuslan Ermilov		fi
2812701a1b7SRuslan Ermilov
2822701a1b7SRuslan Ermilov		if [ -s $t/deps2 ] ; then
2834078537cSBryan Drewery			if [ ${havedeps} -eq 1 ] ; then
2842701a1b7SRuslan Ermilov				echo '.Pp'
2852701a1b7SRuslan Ermilov			fi
2862701a1b7SRuslan Ermilov			echo 'When set, the following options are also in effect:'
2872701a1b7SRuslan Ermilov			echo '.Pp'
2882701a1b7SRuslan Ermilov			echo '.Bl -inset -compact'
2894078537cSBryan Drewery			while read opt2 ; do
2902701a1b7SRuslan Ermilov				echo ".It Va ${opt2}"
2912701a1b7SRuslan Ermilov				noopt=$(echo ${opt2} | sed -e's/WITH_/WITHOUT_/;t' -e's/WITHOUT_/WITH_/')
2922701a1b7SRuslan Ermilov				echo '(unless'
2932701a1b7SRuslan Ermilov				echo ".Va ${noopt}"
2942701a1b7SRuslan Ermilov				echo 'is set explicitly)'
2954078537cSBryan Drewery			done < $t/deps2
2962701a1b7SRuslan Ermilov			echo '.El'
297c5922fbfSRuslan Ermilov		fi
298da6e996dSBryan Drewery
299da6e996dSBryan Drewery		case " ${env_only_options} " in
300da6e996dSBryan Drewery			*\ ${opt#*_}\ *)
301da6e996dSBryan Drewery				echo ".Pp"
302317c99b7SBryan Drewery				echo "This must be set in the environment, make command line, or"
303da6e996dSBryan Drewery				echo ".Pa /etc/src-env.conf ,"
304da6e996dSBryan Drewery				echo "not"
305da6e996dSBryan Drewery				echo ".Pa /etc/src.conf ."
306da6e996dSBryan Drewery				;;
307da6e996dSBryan Drewery		esac
308da6e996dSBryan Drewery
309e6a714e7SRuslan Ermilov		twiddle >&2
310c5922fbfSRuslan Ermilov	done
311c5922fbfSRuslan Ermilov	cat <<EOF
312c5922fbfSRuslan Ermilov.El
313c5922fbfSRuslan Ermilov.Sh FILES
314691b39b5SGlen Barber.Bl -tag -compact -width Pa
315c5922fbfSRuslan Ermilov.It Pa /etc/src.conf
316ca045714SBryan Drewery.It Pa /etc/src-env.conf
317c5922fbfSRuslan Ermilov.It Pa /usr/share/mk/bsd.own.mk
318c5922fbfSRuslan Ermilov.El
319c5922fbfSRuslan Ermilov.Sh SEE ALSO
320c5922fbfSRuslan Ermilov.Xr make 1 ,
321c5922fbfSRuslan Ermilov.Xr make.conf 5 ,
322c5922fbfSRuslan Ermilov.Xr build 7 ,
323c5922fbfSRuslan Ermilov.Xr ports 7
324c5922fbfSRuslan Ermilov.Sh HISTORY
325c5922fbfSRuslan ErmilovThe
326c5922fbfSRuslan Ermilov.Nm
327c5922fbfSRuslan Ermilovfile appeared in
328c5922fbfSRuslan Ermilov.Fx 7.0 .
329c5922fbfSRuslan Ermilov.Sh AUTHORS
330c5922fbfSRuslan ErmilovThis manual page was autogenerated.
331c5922fbfSRuslan ErmilovEOF
332c5922fbfSRuslan Ermilov}
333c5922fbfSRuslan Ermilov
334e6a714e7SRuslan Ermilovtwiddle_pos=0
335e6a714e7SRuslan Ermilovtwiddle()
336e6a714e7SRuslan Ermilov{
337e6a714e7SRuslan Ermilov	local c0='|' c1='/' c2='-' c3='\'
338e6a714e7SRuslan Ermilov
339e6a714e7SRuslan Ermilov	eval printf '%c\\b' '$c'${twiddle_pos}
340e6a714e7SRuslan Ermilov	twiddle_pos=$(((twiddle_pos+1)%4))
341e6a714e7SRuslan Ermilov}
342e6a714e7SRuslan Ermilov
343c5922fbfSRuslan Ermilovmain
344