1276305Sngie# $Id: options.mk,v 1.10 2014/02/11 18:34:48 sjg Exp $
2246149Ssjg#
3246149Ssjg#	@(#) Copyright (c) 2012, Simon J. Gerraty
4246149Ssjg#
5246149Ssjg#	This file is provided in the hope that it will
6246149Ssjg#	be of use.  There is absolutely NO WARRANTY.
7246149Ssjg#	Permission to copy, redistribute or otherwise
8246149Ssjg#	use this file is hereby granted provided that 
9246149Ssjg#	the above copyright notice and this notice are
10246149Ssjg#	left intact. 
11246149Ssjg#      
12246149Ssjg#	Please send copies of changes and bug-fixes to:
13246149Ssjg#	sjg@crufty.net
14246149Ssjg#
15246149Ssjg
16250837Ssjg# Inspired by FreeBSD bsd.own.mk, but intentionally simpler and more flexible.
17246149Ssjg
18246149Ssjg# Options are normally listed in either OPTIONS_DEFAULT_{YES,NO}
19246149Ssjg# We convert these to ${OPTION}/{yes,no} in OPTIONS_DEFAULT_VALUES.
20246149Ssjg# We add the OPTIONS_DEFAULT_NO first so they take precedence.
21246149Ssjg# This allows override of an OPTIONS_DEFAULT_YES by adding it to
22246149Ssjg# OPTIONS_DEFAULT_NO or adding ${OPTION}/no to OPTIONS_DEFAULT_VALUES.
23246149Ssjg# An OPTIONS_DEFAULT_NO option can only be overridden by putting
24246149Ssjg# ${OPTION}/yes in OPTIONS_DEFAULT_VALUES.
25246149Ssjg# A makefile may set NO_* (or NO*) to indicate it cannot do something.
26246149Ssjg# User sets WITH_* and WITHOUT_* to indicate what they want.
27250837Ssjg# We set ${OPTION_PREFIX:UMK_}* which is then all we need care about.
28246149SsjgOPTIONS_DEFAULT_VALUES += \
29246149Ssjg	${OPTIONS_DEFAULT_NO:O:u:S,$,/no,} \
30246149Ssjg	${OPTIONS_DEFAULT_YES:O:u:S,$,/yes,}
31246149Ssjg
32250837SsjgOPTION_PREFIX ?= MK_
33276305Sngie
34276305Sngie# NO_* takes precedence
35276305Sngie# If both WITH_* and WITHOUT_* are defined, WITHOUT_ wins unless
36276305Sngie# DOMINANT_* is set to "yes"
37276305Sngie# Otherwise WITH_* and WITHOUT_* override the default.
38246149Ssjg.for o in ${OPTIONS_DEFAULT_VALUES:M*/*}
39276305Sngie.if defined(NO_${o:H}) || defined(NO${o:H})
40276305Sngie# we cannot do it
41276305Sngie${OPTION_PREFIX}${o:H} ?= no
42276305Sngie.elif defined(WITH_${o:H}) && defined(WITHOUT_${o:H})
43276305Sngie# normally WITHOUT_ wins
44276305SngieDOMINANT_${o:H} ?= no
45276305Sngie${OPTION_PREFIX}${o:H} ?= ${DOMINANT_${o:H}}
46276305Sngie.elif ${o:T:tl} == "no"
47276305Sngie.if defined(WITH_${o:H})
48250837Ssjg${OPTION_PREFIX}${o:H} ?= yes
49246149Ssjg.else
50250837Ssjg${OPTION_PREFIX}${o:H} ?= no
51246149Ssjg.endif
52246149Ssjg.else
53276305Sngie.if defined(WITHOUT_${o:H})
54250837Ssjg${OPTION_PREFIX}${o:H} ?= no
55246149Ssjg.else
56250837Ssjg${OPTION_PREFIX}${o:H} ?= yes
57246149Ssjg.endif
58246149Ssjg.endif
59246149Ssjg.endfor
60246149Ssjg
61246149Ssjg# OPTIONS_DEFAULT_DEPENDENT += FOO_UTILS/FOO
62276305Sngie# If neither WITH[OUT]_FOO_UTILS is set, (see rules above)
63276305Sngie# use the value of ${OPTION_PREFIX}FOO
64246149Ssjg.for o in ${OPTIONS_DEFAULT_DEPENDENT:M*/*:O:u}
65276305Sngie.if defined(NO_${o:H}) || defined(NO${o:H})
66276305Sngie# we cannot do it
67276305Sngie${OPTION_PREFIX}${o:H} ?= no
68276305Sngie.elif defined(WITH_${o:H}) && defined(WITHOUT_${o:H})
69276305Sngie# normally WITHOUT_ wins
70276305SngieDOMINANT_${o:H} ?= no
71276305Sngie${OPTION_PREFIX}${o:H} ?= ${DOMINANT_${o:H}}
72276305Sngie.elif defined(WITH_${o:H})
73250837Ssjg${OPTION_PREFIX}${o:H} ?= yes
74276305Sngie.elif defined(WITHOUT_${o:H})
75250837Ssjg${OPTION_PREFIX}${o:H} ?= no
76246149Ssjg.else
77250837Ssjg${OPTION_PREFIX}${o:H} ?= ${${OPTION_PREFIX}${o:T}}
78246149Ssjg.endif
79246149Ssjg.endfor
80