3 # $Id: mkopt.sh,v 1.12 2020/06/23 04:16:35 sjg Exp $
5 # @(#) Copyright (c) 2014, 2020, Simon J. Gerraty
7 # This file is provided in the hope that it will
8 # be of use. There is absolutely NO WARRANTY.
9 # Permission to copy, redistribute or otherwise
10 # use this file is hereby granted provided that
11 # the above copyright notice and this notice are
14 # Please send copies of changes and bug-fixes to:
18 # handle WITH[OUT]_* options in a manner compatible with
19 # options.mk and bsd.mkopt.mk in recent FreeBSD
21 # no need to be included more than once
23 _MKOPT_PREFIX=${_MKOPT_PREFIX:-MK_}
30 # The semantics are simple, if MK_$OPT has no value
31 # WITHOUT_$OPT results in MK_$OPT=no
32 # otherwise WITH_$OPT results in MK_$OPT=yes.
33 # Note WITHOUT_$OPT overrides WITH_$OPT.
35 # For backwards compatability reasons we treat WITH_$OPT=no
36 # the same as WITHOUT_$OPT.
40 _mo=${_MKOPT_PREFIX}$2 _wo=WITHOUT_$2 _wi=WITH_$2
41 eval "_mov=\$$_mo _wov=\$$_wo _wiv=\$$_wi"
46 _v=${_mov:-${_wov:+no}}
47 _v=${_v:-${_wiv:+yes}}
49 _opt_list="$_opt_list $_mo"
52 0|[NnFf]*) _v=no;; # they mean no
53 1|[YyTt]*) _v=yes;; # they mean yes
54 *) _v=$_d;; # ignore bogus value
60 # _mk_opts default opt ... [default [opt] ...]
62 # see _mk_opts_defaults for example
69 */*) # option is dirname default comes from basename
70 eval "_d=\$${_MKOPT_PREFIX}${_o#*/}"
73 yes|no) _d=$_o; continue;;
79 # handle either options.mk style OPTIONS_DEFAULT_*
80 # or FreeBSD's new bsd.mkopt.mk style __DEFAULT_*_OPTIONS
82 _mk_opts no $OPTIONS_DEFAULT_NO $__DEFAULT_NO_OPTIONS \
83 yes $OPTIONS_DEFAULT_YES $__DEFAULT_YES_OPTIONS \
84 $OPTIONS_DEFAULT_DEPENDENT $__DEFAULT_DEPENDENT_OPTIONS
93 *=*) eval "$1"; shift;;
94 --no|no) _list="$_list no"; shift;;
95 --yes|yes) _list="$_list yes"; shift;;
96 -DWITH*) eval "${1#-D}=1"; shift;;
97 [A-Z]*) _list="$_list $1"; shift;;