xref: /freebsd/contrib/bmake/mk/options.mk (revision 193d9e768ba63fcfb187cfd17f461f7d41345048)
1# $Id: options.mk,v 1.10 2014/02/11 18:34:48 sjg Exp $
2#
3#	@(#) Copyright (c) 2012, Simon J. Gerraty
4#
5#	This file is provided in the hope that it will
6#	be of use.  There is absolutely NO WARRANTY.
7#	Permission to copy, redistribute or otherwise
8#	use this file is hereby granted provided that
9#	the above copyright notice and this notice are
10#	left intact.
11#
12#	Please send copies of changes and bug-fixes to:
13#	sjg@crufty.net
14#
15
16# Inspired by FreeBSD bsd.own.mk, but intentionally simpler and more flexible.
17
18# Options are normally listed in either OPTIONS_DEFAULT_{YES,NO}
19# We convert these to ${OPTION}/{yes,no} in OPTIONS_DEFAULT_VALUES.
20# We add the OPTIONS_DEFAULT_NO first so they take precedence.
21# This allows override of an OPTIONS_DEFAULT_YES by adding it to
22# OPTIONS_DEFAULT_NO or adding ${OPTION}/no to OPTIONS_DEFAULT_VALUES.
23# An OPTIONS_DEFAULT_NO option can only be overridden by putting
24# ${OPTION}/yes in OPTIONS_DEFAULT_VALUES.
25# A makefile may set NO_* (or NO*) to indicate it cannot do something.
26# User sets WITH_* and WITHOUT_* to indicate what they want.
27# We set ${OPTION_PREFIX:UMK_}* which is then all we need care about.
28OPTIONS_DEFAULT_VALUES += \
29	${OPTIONS_DEFAULT_NO:O:u:S,$,/no,} \
30	${OPTIONS_DEFAULT_YES:O:u:S,$,/yes,}
31
32OPTION_PREFIX ?= MK_
33
34# NO_* takes precedence
35# If both WITH_* and WITHOUT_* are defined, WITHOUT_ wins unless
36# DOMINANT_* is set to "yes"
37# Otherwise WITH_* and WITHOUT_* override the default.
38.for o in ${OPTIONS_DEFAULT_VALUES:M*/*}
39.if defined(NO_${o:H}) || defined(NO${o:H})
40# we cannot do it
41${OPTION_PREFIX}${o:H} ?= no
42.elif defined(WITH_${o:H}) && defined(WITHOUT_${o:H})
43# normally WITHOUT_ wins
44DOMINANT_${o:H} ?= no
45${OPTION_PREFIX}${o:H} ?= ${DOMINANT_${o:H}}
46.elif ${o:T:tl} == "no"
47.if defined(WITH_${o:H})
48${OPTION_PREFIX}${o:H} ?= yes
49.else
50${OPTION_PREFIX}${o:H} ?= no
51.endif
52.else
53.if defined(WITHOUT_${o:H})
54${OPTION_PREFIX}${o:H} ?= no
55.else
56${OPTION_PREFIX}${o:H} ?= yes
57.endif
58.endif
59.endfor
60
61# OPTIONS_DEFAULT_DEPENDENT += FOO_UTILS/FOO
62# If neither WITH[OUT]_FOO_UTILS is set, (see rules above)
63# use the value of ${OPTION_PREFIX}FOO
64.for o in ${OPTIONS_DEFAULT_DEPENDENT:M*/*:O:u}
65.if defined(NO_${o:H}) || defined(NO${o:H})
66# we cannot do it
67${OPTION_PREFIX}${o:H} ?= no
68.elif defined(WITH_${o:H}) && defined(WITHOUT_${o:H})
69# normally WITHOUT_ wins
70DOMINANT_${o:H} ?= no
71${OPTION_PREFIX}${o:H} ?= ${DOMINANT_${o:H}}
72.elif defined(WITH_${o:H})
73${OPTION_PREFIX}${o:H} ?= yes
74.elif defined(WITHOUT_${o:H})
75${OPTION_PREFIX}${o:H} ?= no
76.else
77${OPTION_PREFIX}${o:H} ?= ${${OPTION_PREFIX}${o:T}}
78.endif
79.endfor
80