xref: /freebsd/tools/build/options/makeman (revision 983e409609885c24fb6cb2652ee37044fe05b05e)
1c5922fbfSRuslan Ermilov#!/bin/sh
2c5922fbfSRuslan Ermilov#
3c5922fbfSRuslan Ermilov# This file is in the public domain.
4*983e4096SEd Maste#
5*983e4096SEd Maste# $FreeBSD$
6c5922fbfSRuslan Ermilov
72701a1b7SRuslan Ermilovset -o errexit
8f1f871e1SHajimu UMEMOTOexport LC_ALL=C
92701a1b7SRuslan Ermilov
102701a1b7SRuslan Ermilovt=$(mktemp -d -t makeman)
114af17bf5SWarren Blocktrap '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
36b7f38e69SEd Maste		prev_opt=
373dfad7c7SBryan Drewery		env -i ${make} showconfig \
38317c99b7SBryan Drewery		    SRC_ENV_CONF=/dev/null SRCCONF=/dev/null \
39317c99b7SBryan Drewery		    __MAKE_CONF=/dev/null \
402701a1b7SRuslan Ermilov		    TARGET_ARCH=${target#*/} TARGET=${target%/*} |
412701a1b7SRuslan Ermilov		while read var _ val ; do
422701a1b7SRuslan Ermilov			opt=${var#MK_}
43b7f38e69SEd Maste			if [ $opt = "$prev_opt" ]; then
44b7f38e69SEd Maste				echo "$target: ignoring duplicate option $opt" >&2
45b7f38e69SEd Maste				continue
46b7f38e69SEd Maste			fi
47b7f38e69SEd Maste			prev_opt=$opt
482701a1b7SRuslan Ermilov			case ${val} in
492701a1b7SRuslan Ermilov			yes)
502701a1b7SRuslan Ermilov				echo ${opt} ${target}
512701a1b7SRuslan Ermilov				;;
522701a1b7SRuslan Ermilov			no)
532701a1b7SRuslan Ermilov				echo ${opt}
542701a1b7SRuslan Ermilov				;;
552701a1b7SRuslan Ermilov			*)
56cc2520d2SSimon J. Gerraty				echo "make showconfig broken: ${var} ${_} ${val} (not yes or no)" >&2
572701a1b7SRuslan Ermilov				exit 1
582701a1b7SRuslan Ermilov				;;
592701a1b7SRuslan Ermilov			esac
602701a1b7SRuslan Ermilov		done > $t/settings.target
612701a1b7SRuslan Ermilov		if [ -r $t/settings ] ; then
622701a1b7SRuslan Ermilov			join -t\  $t/settings $t/settings.target > $t/settings.new
632701a1b7SRuslan Ermilov			mv $t/settings.new $t/settings
642701a1b7SRuslan Ermilov		else
652701a1b7SRuslan Ermilov			mv $t/settings.target $t/settings
662701a1b7SRuslan Ermilov		fi
672701a1b7SRuslan Ermilov	done
682701a1b7SRuslan Ermilov
694078537cSBryan Drewery	while read opt targets ; do
702701a1b7SRuslan Ermilov		if [ "${targets}" = "${ALL_TARGETS}" ] ; then
712701a1b7SRuslan Ermilov			echo "WITHOUT_${opt}"
722701a1b7SRuslan Ermilov		elif [ -z "${targets}" ] ; then
732701a1b7SRuslan Ermilov			echo "WITH_${opt}"
742701a1b7SRuslan Ermilov		else
752701a1b7SRuslan Ermilov			echo "WITHOUT_${opt}" $(no_targets "${ALL_TARGETS}" "${targets}")
762701a1b7SRuslan Ermilov			echo "WITH_${opt} ${targets}"
772701a1b7SRuslan Ermilov		fi
784078537cSBryan Drewery	done < $t/settings
792701a1b7SRuslan Ermilov}
802701a1b7SRuslan Ermilov
812701a1b7SRuslan Ermilov#
822701a1b7SRuslan Ermilov# usage: show { settings | with | without } ...
83c5922fbfSRuslan Ermilov#
84c5922fbfSRuslan Ermilovshow()
85c5922fbfSRuslan Ermilov{
86c5922fbfSRuslan Ermilov
87c5922fbfSRuslan Ermilov	mode=$1 ; shift
88c5922fbfSRuslan Ermilov	case ${mode} in
89c5922fbfSRuslan Ermilov	settings)
90c5922fbfSRuslan Ermilov		yes_prefix=WITH
91c5922fbfSRuslan Ermilov		no_prefix=WITHOUT
92c5922fbfSRuslan Ermilov		;;
932701a1b7SRuslan Ermilov	with)
942701a1b7SRuslan Ermilov		yes_prefix=WITH
95c5922fbfSRuslan Ermilov		no_prefix=WITH
96c5922fbfSRuslan Ermilov		;;
972701a1b7SRuslan Ermilov	without)
982701a1b7SRuslan Ermilov		yes_prefix=WITHOUT
992701a1b7SRuslan Ermilov		no_prefix=WITHOUT
1002701a1b7SRuslan Ermilov		;;
101c5922fbfSRuslan Ermilov	*)
1022701a1b7SRuslan Ermilov		echo 'internal error' >&2
103c5922fbfSRuslan Ermilov		exit 1
104c5922fbfSRuslan Ermilov		;;
105c5922fbfSRuslan Ermilov	esac
1063dfad7c7SBryan Drewery	env -i ${make} .MAKE.MODE=normal "$@" showconfig __MAKE_CONF=/dev/null \
107317c99b7SBryan Drewery	    SRCCONF=/dev/null |
108c5922fbfSRuslan Ermilov	while read var _ val ; do
109c5922fbfSRuslan Ermilov		opt=${var#MK_}
110c5922fbfSRuslan Ermilov		case ${val} in
111c5922fbfSRuslan Ermilov		yes)
112c5922fbfSRuslan Ermilov			echo ${yes_prefix}_${opt}
113c5922fbfSRuslan Ermilov			;;
114c5922fbfSRuslan Ermilov		no)
115c5922fbfSRuslan Ermilov			echo ${no_prefix}_${opt}
116c5922fbfSRuslan Ermilov			;;
117c5922fbfSRuslan Ermilov		*)
118cc2520d2SSimon J. Gerraty			echo "make showconfig broken: ${var} ${_} ${val} (not yes or no)" >&2
119c5922fbfSRuslan Ermilov			exit 1
120c5922fbfSRuslan Ermilov			;;
121c5922fbfSRuslan Ermilov		esac
122c5922fbfSRuslan Ermilov	done
123c5922fbfSRuslan Ermilov}
124c5922fbfSRuslan Ermilov
125c5922fbfSRuslan Ermilovmain()
126c5922fbfSRuslan Ermilov{
1277a206c31SWarren Block	echo "building src.conf.5 man page from files in ${PWD}" >&2
128c5922fbfSRuslan Ermilov
12941c8ddc3SRuslan Ermilov	fbsdid='$'FreeBSD'$'
130c5922fbfSRuslan Ermilov	cat <<EOF
131c5922fbfSRuslan Ermilov.\" DO NOT EDIT-- this file is automatically generated.
132c5922fbfSRuslan Ermilov.\" ${fbsdid}
1332701a1b7SRuslan Ermilov.Dd $(echo $(LC_TIME=C date +'%B %e, %Y'))
134c5922fbfSRuslan Ermilov.Dt SRC.CONF 5
135c5922fbfSRuslan Ermilov.Os
136c5922fbfSRuslan Ermilov.Sh NAME
137c5922fbfSRuslan Ermilov.Nm src.conf
13857caf3d6STom Rhodes.Nd "source build options"
139c5922fbfSRuslan Ermilov.Sh DESCRIPTION
140c5922fbfSRuslan ErmilovThe
141c5922fbfSRuslan Ermilov.Nm
142c5922fbfSRuslan Ermilovfile contains settings that will apply to every build involving the
143c5922fbfSRuslan Ermilov.Fx
144c5922fbfSRuslan Ermilovsource tree; see
145c5922fbfSRuslan Ermilov.Xr build 7 .
146c5922fbfSRuslan Ermilov.Pp
147c5922fbfSRuslan ErmilovThe
148c5922fbfSRuslan Ermilov.Nm
149c5922fbfSRuslan Ermilovfile uses the standard makefile syntax.
150c5922fbfSRuslan ErmilovHowever,
151c5922fbfSRuslan Ermilov.Nm
152c5922fbfSRuslan Ermilovshould not specify any dependencies to
153c5922fbfSRuslan Ermilov.Xr make 1 .
154c5922fbfSRuslan ErmilovInstead,
155c5922fbfSRuslan Ermilov.Nm
156c5922fbfSRuslan Ermilovis to set
157c5922fbfSRuslan Ermilov.Xr make 1
158c5922fbfSRuslan Ermilovvariables that control the aspects of how the system builds.
159c5922fbfSRuslan Ermilov.Pp
160c5922fbfSRuslan ErmilovThe default location of
161c5922fbfSRuslan Ermilov.Nm
162c5922fbfSRuslan Ermilovis
163c5922fbfSRuslan Ermilov.Pa /etc/src.conf ,
164c5922fbfSRuslan Ermilovthough an alternative location can be specified in the
165c5922fbfSRuslan Ermilov.Xr make 1
166c5922fbfSRuslan Ermilovvariable
167c5922fbfSRuslan Ermilov.Va SRCCONF .
168c5922fbfSRuslan ErmilovOverriding the location of
169c5922fbfSRuslan Ermilov.Nm
170c5922fbfSRuslan Ermilovmay be necessary if the system-wide settings are not suitable
171c5922fbfSRuslan Ermilovfor a particular build.
172c5922fbfSRuslan ErmilovFor instance, setting
173c5922fbfSRuslan Ermilov.Va SRCCONF
174c5922fbfSRuslan Ermilovto
175c5922fbfSRuslan Ermilov.Pa /dev/null
176c5922fbfSRuslan Ermiloveffectively resets all build controls to their defaults.
177c5922fbfSRuslan Ermilov.Pp
178c5922fbfSRuslan ErmilovThe only purpose of
179c5922fbfSRuslan Ermilov.Nm
180c5922fbfSRuslan Ermilovis to control the compilation of the
181c5922fbfSRuslan Ermilov.Fx
18257caf3d6STom Rhodessource code, which is usually located in
183c5922fbfSRuslan Ermilov.Pa /usr/src .
184c5922fbfSRuslan ErmilovAs a rule, the system administrator creates
185c5922fbfSRuslan Ermilov.Nm
186c5922fbfSRuslan Ermilovwhen the values of certain control variables need to be changed
187c5922fbfSRuslan Ermilovfrom their defaults.
188c5922fbfSRuslan Ermilov.Pp
189c5922fbfSRuslan ErmilovIn addition, control variables can be specified
190c5922fbfSRuslan Ermilovfor a particular build via the
191c5922fbfSRuslan Ermilov.Fl D
192c5922fbfSRuslan Ermilovoption of
193c5922fbfSRuslan Ermilov.Xr make 1
1943d919b75SMike Makonnenor in its environment; see
195c5922fbfSRuslan Ermilov.Xr environ 7 .
196c5922fbfSRuslan Ermilov.Pp
197ca045714SBryan DreweryThe environment of
198ca045714SBryan Drewery.Xr make 1
199ca045714SBryan Dreweryfor the build can be controlled via the
200ca045714SBryan Drewery.Va SRC_ENV_CONF
201ca045714SBryan Dreweryvariable, which defaults to
202ca045714SBryan Drewery.Pa /etc/src-env.conf .
203ca045714SBryan DrewerySome examples that may only be set in this file are
20432b5dc9aSSimon J. Gerraty.Va WITH_DIRDEPS_BUILD ,
205ca045714SBryan Dreweryand
206ca045714SBryan Drewery.Va WITH_META_MODE
207ca045714SBryan Dreweryas they are environment-only variables.
2085d111a97SBryan DreweryNote that
2095d111a97SBryan Drewery.Va MAKEOBJDIRPREFIX
2105d111a97SBryan Drewerymay be set here only when using
2115d111a97SBryan Drewery.Va WITH_DIRDEPS_BUILD .
212ca045714SBryan Drewery.Pp
21307b7d7fbSTom RhodesThe values of variables are ignored regardless of their setting;
21457caf3d6STom Rhodeseven if they would be set to
215c5922fbfSRuslan Ermilov.Dq Li FALSE
216c5922fbfSRuslan Ermilovor
21757caf3d6STom Rhodes.Dq Li NO .
2187a206c31SWarren BlockThe presence of an option causes
2197a206c31SWarren Blockit to be honored by
22057caf3d6STom Rhodes.Xr make 1 .
221c5922fbfSRuslan Ermilov.Pp
2227a206c31SWarren BlockThis list provides a name and short description for variables
223c5922fbfSRuslan Ermilovthat can be used for source builds.
224c5922fbfSRuslan Ermilov.Bl -tag -width indent
225c5922fbfSRuslan ErmilovEOF
226317c99b7SBryan Drewery	show settings SRC_ENV_CONF=/dev/null | sort > $t/config_default
227f506e293SEd Maste	# Work around WITH_LDNS_UTILS forcing BIND_UTILS off by parsing the
228f506e293SEd Maste	# actual config that results from enabling every WITH_ option.  This
229f506e293SEd Maste	# can be reverted if/when we no longer have options that disable
230f506e293SEd Maste	# others.
231317c99b7SBryan Drewery	show with SRC_ENV_CONF=/dev/null | sort | sed 's/$/=/' > $t/src.conf
232317c99b7SBryan Drewery	show settings SRC_ENV_CONF=$t/src.conf | sort > $t/config_WITH_ALL
233317c99b7SBryan Drewery	show without SRC_ENV_CONF=/dev/null | sort > $t/config_WITHOUT_ALL
234da6e996dSBryan Drewery	env_only_options="$(${make} -V __ENV_ONLY_OPTIONS)"
2352701a1b7SRuslan Ermilov
2362701a1b7SRuslan Ermilov	show_options |
2372701a1b7SRuslan Ermilov	while read opt targets ; do
2382701a1b7SRuslan Ermilov		if [ ! -f ${opt} ] ; then
2392701a1b7SRuslan Ermilov			echo "no description found for ${opt}, skipping" >&2
240c3b08cc6SYaroslav Tykhiy			continue
241cae68befSRuslan Ermilov		fi
242cae68befSRuslan Ermilov
2432701a1b7SRuslan Ermilov		echo ".It Va ${opt}"
244*983e4096SEd Maste		sed -e'/\$FreeBSD.*\$/d' ${opt}
2452701a1b7SRuslan Ermilov		if [ -n "${targets}" ] ; then
2462701a1b7SRuslan Ermilov			echo '.Pp'
2477a206c31SWarren Block			echo 'This is a default setting on'
2482701a1b7SRuslan Ermilov			echo $(echo ${targets} | sed -e's/ /, /g' -e's/\(.*\), /\1 and /').
249c5922fbfSRuslan Ermilov		fi
2502701a1b7SRuslan Ermilov
251cae68befSRuslan Ermilov		if [ "${opt%%_*}" = 'WITHOUT' ] ; then
2522701a1b7SRuslan Ermilov			sed -n "/^WITH_${opt#WITHOUT_}$/!s/$/=/p" $t/config_WITH_ALL > $t/src.conf
253317c99b7SBryan Drewery			show settings SRC_ENV_CONF=$t/src.conf -D${opt} | sort > $t/config_WITH_ALL_${opt}
2542701a1b7SRuslan Ermilov			comm -13 $t/config_WITH_ALL $t/config_WITH_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
255cae68befSRuslan Ermilov		elif [ "${opt%%_*}" = 'WITH' ] ; then
2562701a1b7SRuslan Ermilov			sed -n "/^WITHOUT${opt#WITH}$/!s/$/=/p" $t/config_WITHOUT_ALL > $t/src.conf
257317c99b7SBryan Drewery			show settings SRC_ENV_CONF=$t/src.conf -D${opt} | sort > $t/config_WITHOUT_ALL_${opt}
2582701a1b7SRuslan Ermilov			comm -13 $t/config_WITHOUT_ALL $t/config_WITHOUT_ALL_${opt} | sed -n "/^${opt}$/!p" > $t/deps
2592701a1b7SRuslan Ermilov		else
2602701a1b7SRuslan Ermilov			echo 'internal error' >&2
2612701a1b7SRuslan Ermilov			exit 1
2622701a1b7SRuslan Ermilov		fi
2632701a1b7SRuslan Ermilov
264317c99b7SBryan Drewery		show settings SRC_ENV_CONF=/dev/null -D${opt} | sort > $t/config_${opt}
265f506e293SEd Maste		comm -13 $t/config_default $t/config_${opt} | sed -n "/^${opt}$/!p" |
266f506e293SEd Maste		comm -13 $t/deps - > $t/deps2
267f506e293SEd Maste
268f506e293SEd Maste		# Work around BIND_UTILS=no being the default when every WITH_
269f506e293SEd Maste		# option is enabled.
270e60c420fSEd Maste		if [ "$(cat $t/deps2)" = WITHOUT_BIND_UTILS ]; then
271f506e293SEd Maste			sort $t/deps $t/deps2 > $t/_deps
272f506e293SEd Maste			mv $t/_deps $t/deps
273f506e293SEd Maste			:> $t/deps2
274f506e293SEd Maste		fi
275f506e293SEd Maste
2764078537cSBryan Drewery		havedeps=0
2772701a1b7SRuslan Ermilov		if [ -s $t/deps ] ; then
2784078537cSBryan Drewery			havedeps=1
2797a206c31SWarren Block			echo 'When set, it enforces these options:'
2802701a1b7SRuslan Ermilov			echo '.Pp'
2812701a1b7SRuslan Ermilov			echo '.Bl -item -compact'
2824078537cSBryan Drewery			while read opt2 ; do
2832701a1b7SRuslan Ermilov				echo '.It'
2842701a1b7SRuslan Ermilov				echo ".Va ${opt2}"
2854078537cSBryan Drewery			done < $t/deps
2862701a1b7SRuslan Ermilov			echo '.El'
2872701a1b7SRuslan Ermilov		fi
2882701a1b7SRuslan Ermilov
2892701a1b7SRuslan Ermilov		if [ -s $t/deps2 ] ; then
2904078537cSBryan Drewery			if [ ${havedeps} -eq 1 ] ; then
2912701a1b7SRuslan Ermilov				echo '.Pp'
2922701a1b7SRuslan Ermilov			fi
2937a206c31SWarren Block			echo 'When set, these options are also in effect:'
2942701a1b7SRuslan Ermilov			echo '.Pp'
2952701a1b7SRuslan Ermilov			echo '.Bl -inset -compact'
2964078537cSBryan Drewery			while read opt2 ; do
2972701a1b7SRuslan Ermilov				echo ".It Va ${opt2}"
2982701a1b7SRuslan Ermilov				noopt=$(echo ${opt2} | sed -e's/WITH_/WITHOUT_/;t' -e's/WITHOUT_/WITH_/')
2992701a1b7SRuslan Ermilov				echo '(unless'
3002701a1b7SRuslan Ermilov				echo ".Va ${noopt}"
3012701a1b7SRuslan Ermilov				echo 'is set explicitly)'
3024078537cSBryan Drewery			done < $t/deps2
3032701a1b7SRuslan Ermilov			echo '.El'
304c5922fbfSRuslan Ermilov		fi
305da6e996dSBryan Drewery
306da6e996dSBryan Drewery		case " ${env_only_options} " in
307da6e996dSBryan Drewery			*\ ${opt#*_}\ *)
308da6e996dSBryan Drewery				echo ".Pp"
309317c99b7SBryan Drewery				echo "This must be set in the environment, make command line, or"
310da6e996dSBryan Drewery				echo ".Pa /etc/src-env.conf ,"
311da6e996dSBryan Drewery				echo "not"
312da6e996dSBryan Drewery				echo ".Pa /etc/src.conf ."
313da6e996dSBryan Drewery				;;
314da6e996dSBryan Drewery		esac
315da6e996dSBryan Drewery
316e6a714e7SRuslan Ermilov		twiddle >&2
317c5922fbfSRuslan Ermilov	done
318c5922fbfSRuslan Ermilov	cat <<EOF
319c5922fbfSRuslan Ermilov.El
320c5922fbfSRuslan Ermilov.Sh FILES
321691b39b5SGlen Barber.Bl -tag -compact -width Pa
322c5922fbfSRuslan Ermilov.It Pa /etc/src.conf
323ca045714SBryan Drewery.It Pa /etc/src-env.conf
324c5922fbfSRuslan Ermilov.It Pa /usr/share/mk/bsd.own.mk
325c5922fbfSRuslan Ermilov.El
326c5922fbfSRuslan Ermilov.Sh SEE ALSO
327c5922fbfSRuslan Ermilov.Xr make 1 ,
328c5922fbfSRuslan Ermilov.Xr make.conf 5 ,
329c5922fbfSRuslan Ermilov.Xr build 7 ,
330c5922fbfSRuslan Ermilov.Xr ports 7
331c5922fbfSRuslan Ermilov.Sh HISTORY
332c5922fbfSRuslan ErmilovThe
333c5922fbfSRuslan Ermilov.Nm
334c5922fbfSRuslan Ermilovfile appeared in
335c5922fbfSRuslan Ermilov.Fx 7.0 .
336c5922fbfSRuslan Ermilov.Sh AUTHORS
337fd4f2cd5SEnji CooperThis manual page was autogenerated by
338cbc5a508SEnji Cooper.An tools/build/options/makeman .
339c5922fbfSRuslan ErmilovEOF
340c5922fbfSRuslan Ermilov}
341c5922fbfSRuslan Ermilov
342e6a714e7SRuslan Ermilovtwiddle_pos=0
343e6a714e7SRuslan Ermilovtwiddle()
344e6a714e7SRuslan Ermilov{
345e6a714e7SRuslan Ermilov	local c0='|' c1='/' c2='-' c3='\'
346e6a714e7SRuslan Ermilov
347e6a714e7SRuslan Ermilov	eval printf '%c\\b' '$c'${twiddle_pos}
348e6a714e7SRuslan Ermilov	twiddle_pos=$(((twiddle_pos+1)%4))
349e6a714e7SRuslan Ermilov}
350e6a714e7SRuslan Ermilov
351c5922fbfSRuslan Ermilovmain
352