xref: /freebsd/contrib/bmake/mk/options.mk (revision 6a7405f5a6b639682cacf01e35d561411ff556aa)
1c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
2c59c3bf3SSimon J. Gerraty#
3*6a7405f5SSimon J. Gerraty# $Id: options.mk,v 1.22 2024/10/27 17:33:03 sjg Exp $
43cbdda60SSimon J. Gerraty#
53cbdda60SSimon J. Gerraty#	@(#) Copyright (c) 2012, Simon J. Gerraty
63cbdda60SSimon J. Gerraty#
73cbdda60SSimon J. Gerraty#	This file is provided in the hope that it will
83cbdda60SSimon J. Gerraty#	be of use.  There is absolutely NO WARRANTY.
93cbdda60SSimon J. Gerraty#	Permission to copy, redistribute or otherwise
103cbdda60SSimon J. Gerraty#	use this file is hereby granted provided that
113cbdda60SSimon J. Gerraty#	the above copyright notice and this notice are
123cbdda60SSimon J. Gerraty#	left intact.
133cbdda60SSimon J. Gerraty#
143cbdda60SSimon J. Gerraty#	Please send copies of changes and bug-fixes to:
153cbdda60SSimon J. Gerraty#	sjg@crufty.net
163cbdda60SSimon J. Gerraty#
173cbdda60SSimon J. Gerraty
1852d86256SSimon J. Gerraty# Inspired by FreeBSD bsd.own.mk, but intentionally simpler and more flexible.
193cbdda60SSimon J. Gerraty
203cbdda60SSimon J. Gerraty# Options are normally listed in either OPTIONS_DEFAULT_{YES,NO}
213cbdda60SSimon J. Gerraty# We convert these to ${OPTION}/{yes,no} in OPTIONS_DEFAULT_VALUES.
223cbdda60SSimon J. Gerraty# We add the OPTIONS_DEFAULT_NO first so they take precedence.
233cbdda60SSimon J. Gerraty# This allows override of an OPTIONS_DEFAULT_YES by adding it to
243cbdda60SSimon J. Gerraty# OPTIONS_DEFAULT_NO or adding ${OPTION}/no to OPTIONS_DEFAULT_VALUES.
253cbdda60SSimon J. Gerraty# An OPTIONS_DEFAULT_NO option can only be overridden by putting
263cbdda60SSimon J. Gerraty# ${OPTION}/yes in OPTIONS_DEFAULT_VALUES.
273cbdda60SSimon J. Gerraty# A makefile may set NO_* (or NO*) to indicate it cannot do something.
283cbdda60SSimon J. Gerraty# User sets WITH_* and WITHOUT_* to indicate what they want.
2952d86256SSimon J. Gerraty# We set ${OPTION_PREFIX:UMK_}* which is then all we need care about.
303cbdda60SSimon J. GerratyOPTIONS_DEFAULT_VALUES += \
3112904384SSimon J. Gerraty	${OPTIONS_DEFAULT_NO:U:O:u:S,$,/no,} \
3212904384SSimon J. Gerraty	${OPTIONS_DEFAULT_YES:U:O:u:S,$,/yes,}
333cbdda60SSimon J. Gerraty
3452d86256SSimon J. GerratyOPTION_PREFIX ?= MK_
355bcb7424SSimon J. Gerraty
365bcb7424SSimon J. Gerraty# NO_* takes precedence
375bcb7424SSimon J. Gerraty# If both WITH_* and WITHOUT_* are defined, WITHOUT_ wins unless
385bcb7424SSimon J. Gerraty# DOMINANT_* is set to "yes"
395bcb7424SSimon J. Gerraty# Otherwise WITH_* and WITHOUT_* override the default.
403cbdda60SSimon J. Gerraty.for o in ${OPTIONS_DEFAULT_VALUES:M*/*}
4112904384SSimon J. Gerraty.if defined(WITH_${o:H}) && ${WITH_${o:H}} == "no"
4212904384SSimon J. Gerraty# a common miss-use - point out correct usage
4312904384SSimon J. Gerraty.warning use WITHOUT_${o:H}=1 not WITH_${o:H}=no
4412904384SSimon J. Gerraty.endif
455bcb7424SSimon J. Gerraty.if defined(NO_${o:H}) || defined(NO${o:H})
465bcb7424SSimon J. Gerraty# we cannot do it
475bcb7424SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= no
485bcb7424SSimon J. Gerraty.elif defined(WITH_${o:H}) && defined(WITHOUT_${o:H})
495bcb7424SSimon J. Gerraty# normally WITHOUT_ wins
505bcb7424SSimon J. GerratyDOMINANT_${o:H} ?= no
515bcb7424SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= ${DOMINANT_${o:H}}
525bcb7424SSimon J. Gerraty.elif ${o:T:tl} == "no"
535bcb7424SSimon J. Gerraty.if defined(WITH_${o:H})
5452d86256SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= yes
553cbdda60SSimon J. Gerraty.else
5652d86256SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= no
573cbdda60SSimon J. Gerraty.endif
583cbdda60SSimon J. Gerraty.else
595bcb7424SSimon J. Gerraty.if defined(WITHOUT_${o:H})
6052d86256SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= no
613cbdda60SSimon J. Gerraty.else
6252d86256SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= yes
633cbdda60SSimon J. Gerraty.endif
643cbdda60SSimon J. Gerraty.endif
65*6a7405f5SSimon J. Gerraty.if defined(DEBUG_OPTIONS) && ${DEBUG_OPTIONS:@x@${o:H:M$x}@} != ""
66*6a7405f5SSimon J. Gerraty.info ${.INCLUDEDFROMFILE}: ${OPTION_PREFIX}${o:H}=${${OPTION_PREFIX}${o:H}}
67*6a7405f5SSimon J. Gerraty.endif
683cbdda60SSimon J. Gerraty.endfor
693cbdda60SSimon J. Gerraty
703cbdda60SSimon J. Gerraty# OPTIONS_DEFAULT_DEPENDENT += FOO_UTILS/FOO
715bcb7424SSimon J. Gerraty# If neither WITH[OUT]_FOO_UTILS is set, (see rules above)
725bcb7424SSimon J. Gerraty# use the value of ${OPTION_PREFIX}FOO
733cbdda60SSimon J. Gerraty.for o in ${OPTIONS_DEFAULT_DEPENDENT:M*/*:O:u}
745bcb7424SSimon J. Gerraty.if defined(NO_${o:H}) || defined(NO${o:H})
755bcb7424SSimon J. Gerraty# we cannot do it
765bcb7424SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= no
775bcb7424SSimon J. Gerraty.elif defined(WITH_${o:H}) && defined(WITHOUT_${o:H})
785bcb7424SSimon J. Gerraty# normally WITHOUT_ wins
795bcb7424SSimon J. GerratyDOMINANT_${o:H} ?= no
805bcb7424SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= ${DOMINANT_${o:H}}
815bcb7424SSimon J. Gerraty.elif defined(WITH_${o:H})
8252d86256SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= yes
835bcb7424SSimon J. Gerraty.elif defined(WITHOUT_${o:H})
8452d86256SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= no
853cbdda60SSimon J. Gerraty.else
8652d86256SSimon J. Gerraty${OPTION_PREFIX}${o:H} ?= ${${OPTION_PREFIX}${o:T}}
873cbdda60SSimon J. Gerraty.endif
88*6a7405f5SSimon J. Gerraty.if defined(DEBUG_OPTIONS) && ${DEBUG_OPTIONS:@x@${o:H:M$x}@} != ""
89*6a7405f5SSimon J. Gerraty.info ${.INCLUDEDFROMFILE}: ${OPTION_PREFIX}${o:H}=${${OPTION_PREFIX}${o:H}} (${OPTION_PREFIX}${o:T}=${${OPTION_PREFIX}${o:T}})
90*6a7405f5SSimon J. Gerraty.endif
913cbdda60SSimon J. Gerraty.endfor
9212904384SSimon J. Gerraty
9312904384SSimon J. Gerraty# allow displaying/describing set options
9412904384SSimon J. Gerraty.set_options := ${.set_options} \
9512904384SSimon J. Gerraty	${OPTIONS_DEFAULT_VALUES:H:N.} \
9612904384SSimon J. Gerraty	${OPTIONS_DEFAULT_DEPENDENT:U:H:N.} \
9712904384SSimon J. Gerraty
9812904384SSimon J. Gerraty# this can be used in .info as well as target below
9912904384SSimon J. GerratyOPTIONS_SHOW ?= ${.set_options:O:u:@o@${OPTION_PREFIX}$o=${${OPTION_PREFIX}$o}@}
10012904384SSimon J. Gerraty# prefix for variables describing options
10112904384SSimon J. GerratyOPTION_DESCRIPTION_PREFIX ?= DESCRIPTION_
10212904384SSimon J. GerratyOPTION_DESCRIPTION_SEPARATOR ?= ==
10312904384SSimon J. Gerraty
10412904384SSimon J. GerratyOPTIONS_DESCRIBE ?= ${.set_options:O:u:@o@${OPTION_PREFIX}$o=${${OPTION_PREFIX}$o}${${OPTION_DESCRIPTION_PREFIX}$o:S,^, ${OPTION_DESCRIPTION_SEPARATOR} ,1}${.newline}@}
10512904384SSimon J. Gerraty
10612904384SSimon J. Gerraty.if !commands(show-options)
10712904384SSimon J. Gerratyshow-options: .NOTMAIN .PHONY
10812904384SSimon J. Gerraty	@echo; echo "${OPTIONS_SHOW:ts\n}"; echo
10912904384SSimon J. Gerraty.endif
11012904384SSimon J. Gerraty
11112904384SSimon J. Gerraty.if !commands(describe-options)
11212904384SSimon J. Gerratydescribe-options: .NOTMAIN .PHONY
11312904384SSimon J. Gerraty	@echo; echo "${OPTIONS_DESCRIBE}"; echo
11412904384SSimon J. Gerraty.endif
11512904384SSimon J. Gerraty
11612904384SSimon J. Gerraty# we expect to be included more than once
11712904384SSimon J. Gerraty.undef OPTIONS_DEFAULT_DEPENDENT
1182c3632d1SSimon J. Gerraty.undef OPTIONS_DEFAULT_NO
11912904384SSimon J. Gerraty.undef OPTIONS_DEFAULT_VALUES
1202c3632d1SSimon J. Gerraty.undef OPTIONS_DEFAULT_YES
121