freebsd-src/mk/mkopt.sh

105 lines
2.3 KiB
Bash
Raw Normal View History

#!/bin/sh
# $Id: mkopt.sh,v 1.13 2020/08/19 17:51:53 sjg Exp $
2015-04-20 03:45:54 +00:00
#
# @(#) Copyright (c) 2014, 2020, Simon J. Gerraty
2015-04-20 03:45:54 +00:00
#
# 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
2015-04-20 03:45:54 +00:00
# the above copyright notice and this notice are
# left intact.
#
2015-04-20 03:45:54 +00:00
# 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
_MKOPT_SH=:
2015-06-10 20:10:48 +00:00
_MKOPT_PREFIX=${_MKOPT_PREFIX:-MK_}
2015-04-20 03:45:54 +00:00
#
2015-06-10 20:10:48 +00:00
# _mk_opt default OPT
2015-04-20 03:45:54 +00:00
#
# 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.
#
_mk_opt() {
_d=$1
2015-06-10 20:10:48 +00:00
_mo=${_MKOPT_PREFIX}$2 _wo=WITHOUT_$2 _wi=WITH_$2
2015-04-20 03:45:54 +00:00
eval "_mov=\$$_mo _wov=\$$_wo _wiv=\$$_wi"
case "$_wiv" in
2017-04-15 00:51:18 +00:00
[Nn][Oo]) _wov=no;;
2015-04-20 03:45:54 +00:00
esac
_v=${_mov:-${_wov:+no}}
_v=${_v:-${_wiv:+yes}}
_v=${_v:-$_d}
_opt_list="$_opt_list $_mo"
case "$_v" in
yes|no) ;; # sane
0|[NnFf]*) _v=no;; # they mean no
1|[YyTt]*) _v=yes;; # they mean yes
*) _v=$_d;; # ignore bogus value
esac
eval "$_mo=$_v"
}
#
# _mk_opts default opt ... [default [opt] ...]
#
# see _mk_opts_defaults for example
#
_mk_opts() {
_d=no
for _o in "$@"
do
2015-06-10 20:10:48 +00:00
case "$_o" in
*/*) # option is dirname default comes from basename
eval "_d=\$${_MKOPT_PREFIX}${_o#*/}"
_o=${_o%/*}
;;
2015-04-20 03:45:54 +00:00
yes|no) _d=$_o; continue;;
esac
_mk_opt $_d $_o
done
}
2015-06-10 20:10:48 +00:00
# handle either options.mk style OPTIONS_DEFAULT_*
# or FreeBSD's new bsd.mkopt.mk style __DEFAULT_*_OPTIONS
2015-04-20 03:45:54 +00:00
_mk_opts_defaults() {
2015-06-10 20:10:48 +00:00
_mk_opts no $OPTIONS_DEFAULT_NO $__DEFAULT_NO_OPTIONS \
yes $OPTIONS_DEFAULT_YES $__DEFAULT_YES_OPTIONS \
$OPTIONS_DEFAULT_DEPENDENT $__DEFAULT_DEPENDENT_OPTIONS
2015-04-20 03:45:54 +00:00
}
case "/$0" in
*/mkopt*)
_list=no
while :
do
case "$1" in
*=*) eval "$1"; shift;;
--no|no) _list="$_list no"; shift;;
--yes|yes) _list="$_list yes"; shift;;
-DWITH*) eval "${1#-D}=1"; shift;;
[A-Z]*) _list="$_list $1"; shift;;
*) break;;
esac
done
_mk_opts $_list
;;
esac