mkopt.sh revision 321964
1272850Shrs: 2272850Shrs# $Id: mkopt.sh,v 1.11 2017/03/18 21:36:42 sjg Exp $ 326206Swpaul# 4272850Shrs# @(#) Copyright (c) 2014, Simon J. Gerraty 5272850Shrs# 6272850Shrs# This file is provided in the hope that it will 726206Swpaul# be of use. There is absolutely NO WARRANTY. 8272850Shrs# Permission to copy, redistribute or otherwise 9272850Shrs# use this file is hereby granted provided that 10272850Shrs# the above copyright notice and this notice are 11272850Shrs# left intact. 12272850Shrs# 13272850Shrs# Please send copies of changes and bug-fixes to: 14272850Shrs# sjg@crufty.net 15272850Shrs# 16272850Shrs 1726206Swpaul# handle WITH[OUT]_* options in a manner compatible with 18272850Shrs# options.mk and bsd.mkopt.mk in recent FreeBSD 19272850Shrs 20272850Shrs# no need to be included more than once 21272850Shrs_MKOPT_SH=: 22272850Shrs_MKOPT_PREFIX=${_MKOPT_PREFIX:-MK_} 23272850Shrs 24272850Shrs# 25272850Shrs# _mk_opt default OPT 26272850Shrs# 27272850Shrs# Set MK_$OPT 28272850Shrs# 29272850Shrs# The semantics are simple, if MK_$OPT has no value 3026206Swpaul# WITHOUT_$OPT results in MK_$OPT=no 3126206Swpaul# otherwise WITH_$OPT results in MK_$OPT=yes. 3226206Swpaul# Note WITHOUT_$OPT overrides WITH_$OPT. 3326206Swpaul# 3426206Swpaul# For backwards compatability reasons we treat WITH_$OPT=no 3526206Swpaul# the same as WITHOUT_$OPT. 3626206Swpaul# 3726206Swpaul_mk_opt() { 3826206Swpaul _d=$1 39272850Shrs _mo=${_MKOPT_PREFIX}$2 _wo=WITHOUT_$2 _wi=WITH_$2 4026206Swpaul eval "_mov=\$$_mo _wov=\$$_wo _wiv=\$$_wi" 4126206Swpaul 4226206Swpaul case "$_wiv" in 4326206Swpaul [Nn][Oo]) _wov=no;; 4426206Swpaul esac 4526206Swpaul _v=${_mov:-${_wov:+no}} 4626206Swpaul _v=${_v:-${_wiv:+yes}} 4726206Swpaul _v=${_v:-$_d} 4826206Swpaul _opt_list="$_opt_list $_mo" 4926206Swpaul case "$_v" in 5026206Swpaul yes|no) ;; # sane 5126206Swpaul 0|[NnFf]*) _v=no;; # they mean no 5226206Swpaul 1|[YyTt]*) _v=yes;; # they mean yes 5326206Swpaul *) _v=$_d;; # ignore bogus value 5426206Swpaul esac 5526206Swpaul eval "$_mo=$_v" 5626206Swpaul} 5726206Swpaul 5826206Swpaul# 5926206Swpaul# _mk_opts default opt ... [default [opt] ...] 6026206Swpaul# 6126206Swpaul# see _mk_opts_defaults for example 6226206Swpaul# 6326206Swpaul_mk_opts() { 6426206Swpaul _d=no 6526206Swpaul for _o in "$@" 6626206Swpaul do 6726206Swpaul case "$_o" in 6826206Swpaul */*) # option is dirname default comes from basename 6926206Swpaul eval "_d=\$${_MKOPT_PREFIX}${_o#*/}" 7026206Swpaul _o=${_o%/*} 7126206Swpaul ;; 7226206Swpaul yes|no) _d=$_o; continue;; 7326206Swpaul esac 7426206Swpaul _mk_opt $_d $_o 7526206Swpaul done 7626206Swpaul} 7726206Swpaul 7826206Swpaul# handle either options.mk style OPTIONS_DEFAULT_* 7926206Swpaul# or FreeBSD's new bsd.mkopt.mk style __DEFAULT_*_OPTIONS 8026206Swpaul_mk_opts_defaults() { 8126206Swpaul _mk_opts no $OPTIONS_DEFAULT_NO $__DEFAULT_NO_OPTIONS \ 8226206Swpaul yes $OPTIONS_DEFAULT_YES $__DEFAULT_YES_OPTIONS \ 8326206Swpaul $OPTIONS_DEFAULT_DEPENDENT $__DEFAULT_DEPENDENT_OPTIONS 8426206Swpaul} 8526206Swpaul 8626206Swpaulcase "/$0" in 8726206Swpaul*/mkopt*) 8826206Swpaul _list=no 8926206Swpaul while : 9026206Swpaul do 9126206Swpaul case "$1" in 9226206Swpaul *=*) eval "$1"; shift;; 9326206Swpaul --no|no) _list="$_list no"; shift;; 9426206Swpaul --yes|yes) _list="$_list yes"; shift;; 9526206Swpaul -DWITH*) eval "${1#-D}=1"; shift;; 9626206Swpaul [A-Z]*) _list="$_list $1"; shift;; 9726206Swpaul *) break;; 9826206Swpaul esac 9926206Swpaul done 10026206Swpaul _mk_opts $_list 10126206Swpaul ;; 10226206Swpaulesac 10326206Swpaul 10426206Swpaul