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