1# 2# 3# Generic mechanism to deal with WITH and WITHOUT options and turn 4# them into MK_ options. Also turn group options into OPT_ options. 5# 6# For each option FOO in __DEFAULT_YES_OPTIONS, MK_FOO is set to 7# "yes", unless WITHOUT_FOO is defined, in which case it is set to 8# "no". 9# 10# For each option FOO in __REQUIRED_OPTIONS, MK_FOO is set to "yes". 11# 12# For each option FOO in __DEFAULT_NO_OPTIONS, MK_FOO is set to "no", 13# unless WITH_FOO is defined, in which case it is set to "yes". 14# 15# For each entry FOO/BAR in __DEFAULT_DEPENDENT_OPTIONS, 16# MK_FOO is set to "no" if WITHOUT_FOO is defined, 17# "yes" if WITH_FOO is defined, otherwise the value of MK_BAR. 18# 19# If both WITH_FOO and WITHOUT_FOO are defined, WITHOUT_FOO wins and 20# MK_FOO is set to "no" regardless of which list it was in. 21# 22# Users should generally define WITH_FOO or WITHOUT_FOO, but the build 23# system should use MK_FOO={yes,no} when it needs to override the 24# user's desires or default behavior. 25# 26# For each option in __SINGLE_OPTIONS, OPT_FOO is set to FOO if 27# defined and __FOO_DEFAULT if not. Valid values for FOO are specified 28# by __FOO_OPTIONS. 29# 30# All of __REQUIRED_OPTIONS, __DEFAULT_DEPENDENT_OPTIONS, 31# __DEFAULT_YES_OPTIONS, __DEFAULT_NO_OPTIONS, and __SINGLE_OPTIONS 32# are undef'd after all this processing, allowing this file to be 33# included multiple times with different lists. However, we keep 34# deduplicated lists of these options in similarly-named variables 35# without the leading underscores (i.e. FOO_OPTIONS is the complete 36# deduplicated list of all values of __FOO_OPTIONS across all 37# invokations of this file). 38# 39# Other parts of the build system will set BROKEN_OPTIONS to a list 40# of options that are broken on this platform. This will not be unset 41# before returning. Clients are expected to always += this variable. 42# 43# Other parts of the build system will set BROKEN_SINGLE_OPTIONS to a 44# list of 3-tuples of the form: "OPTION broken_value replacment_value". 45# This will not be unset before returning. Clients are expected to 46# always += this variable. 47# 48 49# 50# These variables accumulate all the options from our possibly 51# multiple callers so they're available to build tools such as 52# tools/build/options/makeman. 53# 54DEFAULT_NO_OPTIONS+=${__DEFAULT_NO_OPTIONS} 55DEFAULT_NO_OPTIONS:=${DEFAULT_NO_OPTIONS:O:u} 56DEFAULT_YES_OPTIONS+=${__DEFAULT_YES_OPTIONS} 57DEFAULT_YES_OPTIONS:=${DEFAULT_YES_OPTIONS:O:u} 58DEFAULT_DEPENDENT_OPTIONS+=${__DEFAULT_DEPENDENT_OPTIONS} 59DEFAULT_DEPENDENT_OPTIONS:=${DEFAULT_DEPENDENT_OPTIONS:O:u} 60REQUIRED_OPTIONS+=${__REQUIRED_OPTIONS} 61REQUIRED_OPTIONS:=${REQUIRED_OPTIONS:O:u} 62SINGLE_OPTIONS+=${__SINGLE_OPTIONS} 63SINGLE_OPTIONS:=${SINGLE_OPTIONS:O:u} 64 65# 66# All options defined by our caller; we will undef this before 67# returning. 68# 69__ALL_OPTIONS:= \ 70 ${__DEFAULT_NO_OPTIONS} \ 71 ${__DEFAULT_YES_OPTIONS} \ 72 ${__REQUIRED_OPTIONS} \ 73 ${__DEFAULT_DEPENDENT_OPTIONS:H} \ 74 ${__SINGLE_OPTIONS} 75 76# 77# MK_* options which default to "yes". 78# 79.for var in ${__DEFAULT_YES_OPTIONS} 80.if !defined(MK_${var}) 81.if defined(WITH_${var}) && ${WITH_${var}} == "no" 82.warning Use WITHOUT_${var}=1 instead of WITH_${var}=no 83.endif 84.if defined(WITHOUT_${var}) # WITHOUT always wins 85MK_${var}:= no 86.else 87MK_${var}:= yes 88.endif 89.else 90.if ${MK_${var}} != "yes" && ${MK_${var}} != "no" 91.error Illegal value for MK_${var}: ${MK_${var}} 92.endif 93.endif # !defined(MK_${var}) 94.endfor 95.undef __DEFAULT_YES_OPTIONS 96 97# 98# MK_* options which are always yes, typically as a transitional 99# step towards removing the options entirely. 100# 101.for var in ${__REQUIRED_OPTIONS} 102.if defined(WITHOUT_${var}) && !make(showconfig) 103.warning WITHOUT_${var} option ignored: it is no longer supported 104.endif 105MK_${var}:= yes 106.endfor 107.undef __REQUIRED_OPTIONS 108 109# 110# MK_* options which default to "no". 111# 112.for var in ${__DEFAULT_NO_OPTIONS} 113.if !defined(MK_${var}) 114.if defined(WITH_${var}) && ${WITH_${var}} == "no" 115.warning Use WITHOUT_${var}=1 instead of WITH_${var}=no 116.endif 117.if defined(WITH_${var}) && !defined(WITHOUT_${var}) # WITHOUT always wins 118MK_${var}:= yes 119.else 120MK_${var}:= no 121.endif 122.else 123.if ${MK_${var}} != "yes" && ${MK_${var}} != "no" 124.error Illegal value for MK_${var}: ${MK_${var}} 125.endif 126.endif # !defined(MK_${var}) 127.endfor 128.undef __DEFAULT_NO_OPTIONS 129 130# 131# MK_* options which are always no, usually because they are 132# unsupported/badly broken on this architecture. 133# 134.for var in ${BROKEN_OPTIONS} 135MK_${var}:= no 136.endfor 137 138# 139# Group options set an OPT_FOO variable for each option. 140# 141.for opt in ${__SINGLE_OPTIONS} 142.if !defined(__${opt}_OPTIONS) || empty(__${opt}_OPTIONS) 143.error __${opt}_OPTIONS undefined or empty 144.endif 145.if !defined(__${opt}_DEFAULT) || empty(__${opt}_DEFAULT) 146.error __${opt}_DEFAULT undefined or empty 147.endif 148.if defined(${opt}) 149OPT_${opt}:= ${${opt}} 150.else 151OPT_${opt}:= ${__${opt}_DEFAULT} 152.endif 153.if empty(OPT_${opt}) || ${__${opt}_OPTIONS:M${OPT_${opt}}} != ${OPT_${opt}} 154.error Invalid option OPT_${opt} (${OPT_${opt}}), must be one of: ${__${opt}_OPTIONS} 155.endif 156.endfor 157.undef __SINGLE_OPTIONS 158 159.for opt val rep in ${BROKEN_SINGLE_OPTIONS} 160.if ${OPT_${opt}} == ${val} 161OPT_${opt}:= ${rep} 162.endif 163.endfor 164 165.for vv in ${__DEFAULT_DEPENDENT_OPTIONS} 166.if defined(WITH_${vv:H}) && defined(WITHOUT_${vv:H}) 167MK_${vv:H}?= no 168.elif defined(WITH_${vv:H}) 169MK_${vv:H}?= yes 170.elif defined(WITHOUT_${vv:H}) 171MK_${vv:H}?= no 172.else 173MK_${vv:H}?= ${MK_${vv:T}} 174.endif 175MK_${vv:H}:= ${MK_${vv:H}} 176.endfor 177.undef __DEFAULT_DEPENDENT_OPTIONS 178 179# 180# Define SRC_OPT_DEFS and SRC_OPT_LIST 181# 182SRC_OPT_DEFS?=-D__${MACHINE_ARCH}__ 183SRC_OPT_LIST?=TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH} 184.for option in ${__ALL_OPTIONS:O:u} 185.if defined(OPT_${option}) 186SRC_OPT_DEFS+=-D${option}=${OPT_${option}:Q} 187SRC_OPT_LIST+=${option}=${OPT_${option}:Q} 188.elif ${MK_${option}} == yes 189SRC_OPT_DEFS+=-D${option} 190SRC_OPT_LIST+=WITH_${option}=1 191.elif ${MK_${option}} == no 192SRC_OPT_DEFS+=-U${option} 193SRC_OPT_LIST+=WITHOUT_${option}=1 194.endif 195.endfor 196.undef __ALL_OPTIONS 197