xref: /freebsd/share/mk/bsd.mkopt.mk (revision 2008043f386721d58158e37e0d7e50df8095942d)
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# All of __DEFAULT_YES_OPTIONS, __DEFAULT_NO_OPTIONS and
23# __DEFAULT_DEPENDENT_OPTIONS are undef'd after all this processing,
24# allowing this file to be included multiple times with different lists.
25#
26# Other parts of the build system will set BROKEN_OPTIONS to a list
27# of options that are broken on this platform. This will not be unset
28# before returning. Clients are expected to always += this variable.
29#
30# Users should generally define WITH_FOO or WITHOUT_FOO, but the build
31# system should use MK_FOO={yes,no} when it needs to override the
32# user's desires or default behavior.
33#
34# For each option in __SINGLE_OPTIONS, OPT_FOO is set to FOO if
35# defined and __FOO_DEFAULT if not.  Valid values for FOO are specified
36# by __FOO_OPTIONS.
37#
38# Other parts of the build system will set BROKEN_SINGLE_OPTIONS to a
39# list of 3-tuples of the form: "OPTION broken_value replacment_value".
40# This will not be unset before returning. Clients are expected to
41# always += this variable.
42#
43
44#
45# MK_* options which default to "yes".
46#
47.for var in ${__DEFAULT_YES_OPTIONS}
48.if !defined(MK_${var})
49.if defined(WITH_${var}) && ${WITH_${var}} == "no"
50.warning Use WITHOUT_${var}=1 instead of WITH_${var}=no
51.endif
52.if defined(WITHOUT_${var})			# WITHOUT always wins
53MK_${var}:=	no
54.else
55MK_${var}:=	yes
56.endif
57.else
58.if ${MK_${var}} != "yes" && ${MK_${var}} != "no"
59.error Illegal value for MK_${var}: ${MK_${var}}
60.endif
61.endif # !defined(MK_${var})
62.endfor
63.undef __DEFAULT_YES_OPTIONS
64
65#
66# MK_* options which are always yes, typically as a transitional
67# step towards removing the options entirely.
68#
69.for var in ${__REQUIRED_OPTIONS}
70.if defined(WITHOUT_${var})
71.warning WITHOUT_${var} option ignored: it is no longer supported
72.endif
73MK_${var}:=	yes
74.endfor
75
76#
77# MK_* options which default to "no".
78#
79.for var in ${__DEFAULT_NO_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(WITH_${var}) && !defined(WITHOUT_${var}) # WITHOUT always wins
85MK_${var}:=	yes
86.else
87MK_${var}:=	no
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_NO_OPTIONS
96
97#
98# MK_* options which are always no, usually because they are
99# unsupported/badly broken on this architecture.
100#
101.for var in ${BROKEN_OPTIONS}
102MK_${var}:=	no
103.endfor
104
105#
106# Group options set an OPT_FOO variable for each option.
107#
108.for opt in ${__SINGLE_OPTIONS}
109.if !defined(__${opt}_OPTIONS) || empty(__${opt}_OPTIONS)
110.error __${opt}_OPTIONS undefined or empty
111.endif
112.if !defined(__${opt}_DEFAULT) || empty(__${opt}_DEFAULT)
113.error __${opt}_DEFAULT undefined or empty
114.endif
115.if defined(${opt})
116OPT_${opt}:=	${${opt}}
117.else
118OPT_${opt}:=	${__${opt}_DEFAULT}
119.endif
120.if empty(OPT_${opt}) || ${__${opt}_OPTIONS:M${OPT_${opt}}} != ${OPT_${opt}}
121.error Invalid option OPT_${opt} (${OPT_${opt}}), must be one of: ${__${opt}_OPTIONS}
122.endif
123.endfor
124.undef __SINGLE_OPTIONS
125
126.for opt val rep in ${BROKEN_SINGLE_OPTIONS}
127.if ${OPT_${opt}} == ${val}
128OPT_${opt}:=    ${rep}
129.endif
130.endfor
131
132.for vv in ${__DEFAULT_DEPENDENT_OPTIONS}
133.if defined(WITH_${vv:H}) && defined(WITHOUT_${vv:H})
134MK_${vv:H}?= no
135.elif defined(WITH_${vv:H})
136MK_${vv:H}?= yes
137.elif defined(WITHOUT_${vv:H})
138MK_${vv:H}?= no
139.else
140MK_${vv:H}?= ${MK_${vv:T}}
141.endif
142MK_${vv:H}:= ${MK_${vv:H}}
143.endfor
144.undef __DEFAULT_DEPENDENT_OPTIONS
145