: # $Id: mkopt.sh,v 1.11 2017/03/18 21:36:42 sjg Exp $ # # @(#) Copyright (c) 2014, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to copy, redistribute or otherwise # use this file is hereby granted provided that # the above copyright notice and this notice are # left intact. # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # # handle WITH[OUT]_* options in a manner compatible with # options.mk and bsd.mkopt.mk in recent FreeBSD # no need to be included more than once setglobal _MKOPT_SH = ':' setglobal _MKOPT_PREFIX = $(_MKOPT_PREFIX:-MK_) # # _mk_opt default OPT # # Set MK_$OPT # # The semantics are simple, if MK_$OPT has no value # WITHOUT_$OPT results in MK_$OPT=no # otherwise WITH_$OPT results in MK_$OPT=yes. # Note WITHOUT_$OPT overrides WITH_$OPT. # # For backwards compatability reasons we treat WITH_$OPT=no # the same as WITHOUT_$OPT. # proc _mk_opt { setglobal _d = $1 setglobal _mo = "$(_MKOPT_PREFIX)$2", _wo = "WITHOUT_$2", _wi = "WITH_$2" eval "_mov=\$$_mo _wov=\$$_wo _wiv=\$$_wi" match $_wiv { with [Nn][Oo] setglobal _wov = 'no' } setglobal _v = $(_mov:-${_wov:+no}) setglobal _v = $(_v:-${_wiv:+yes}) setglobal _v = $(_v:-$_d) setglobal _opt_list = ""$_opt_list $_mo"" match $_v { with yes|no # sane with 0|[NnFf]* setglobal _v = 'no' # they mean no with 1|[YyTt]* setglobal _v = 'yes' # they mean yes with * setglobal _v = $_d # ignore bogus value } eval "$_mo=$_v" } # # _mk_opts default opt ... [default [opt] ...] # # see _mk_opts_defaults for example # proc _mk_opts { setglobal _d = 'no' for _o in [@Argv] { match $_o { with */* # option is dirname default comes from basename eval "_d=\$$(_MKOPT_PREFIX)$(_o#*/)" setglobal _o = $(_o%/*) with yes|no setglobal _d = $_o; continue } _mk_opt $_d $_o } } # handle either options.mk style OPTIONS_DEFAULT_* # or FreeBSD's new bsd.mkopt.mk style __DEFAULT_*_OPTIONS proc _mk_opts_defaults { _mk_opts no $OPTIONS_DEFAULT_NO $__DEFAULT_NO_OPTIONS \ yes $OPTIONS_DEFAULT_YES $__DEFAULT_YES_OPTIONS \ $OPTIONS_DEFAULT_DEPENDENT $__DEFAULT_DEPENDENT_OPTIONS } match "/$0" { with */mkopt* setglobal _list = 'no' while : { match $1 { with *=* eval $1; shift with --no|no setglobal _list = ""$_list no""; shift with --yes|yes setglobal _list = ""$_list yes""; shift with -DWITH* eval "$(1#-D)=1"; shift with [A-Z]* setglobal _list = ""$_list $1""; shift with * break } } _mk_opts $_list }