]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/mk/mkopt.sh
MFV r282150
[FreeBSD/FreeBSD.git] / contrib / bmake / mk / mkopt.sh
1 :
2 # $Id: mkopt.sh,v 1.8 2014/11/15 07:07:18 sjg Exp $
3 #
4 #       @(#) Copyright (c) 2014, Simon J. Gerraty
5 #
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
11 #       left intact. 
12 #      
13 #       Please send copies of changes and bug-fixes to:
14 #       sjg@crufty.net
15 #
16
17 # handle WITH[OUT]_* options in a manner compatible with
18 # options.mk and bsd.mkopt.mk in recent FreeBSD
19
20 # no need to be included more than once
21 _MKOPT_SH=:
22
23 #
24 # _mk_opt OPT default
25 #
26 # Set MK_$OPT
27 #
28 # The semantics are simple, if MK_$OPT has no value
29 # WITHOUT_$OPT results in MK_$OPT=no
30 # otherwise WITH_$OPT results in MK_$OPT=yes.
31 # Note WITHOUT_$OPT overrides WITH_$OPT.
32 #
33 # For backwards compatability reasons we treat WITH_$OPT=no
34 # the same as WITHOUT_$OPT.
35 #
36 _mk_opt() {
37     _d=$1
38     _mo=MK_$2 _wo=WITHOUT_$2 _wi=WITH_$2
39     eval "_mov=\$$_mo _wov=\$$_wo _wiv=\$$_wi"
40
41     case "$_wiv" in
42     no) _wov=no;;
43     esac
44     _v=${_mov:-${_wov:+no}}
45     _v=${_v:-${_wiv:+yes}}
46     _v=${_v:-$_d}
47     _opt_list="$_opt_list $_mo"
48     case "$_v" in
49     yes|no) ;;                  # sane
50     0|[NnFf]*) _v=no;;          # they mean no
51     1|[YyTt]*) _v=yes;;         # they mean yes
52     *) _v=$_d;;                 # ignore bogus value
53     esac
54     eval "$_mo=$_v"
55 }
56
57 #
58 # _mk_opts default opt ... [default [opt] ...]
59 #
60 # see _mk_opts_defaults for example
61 #
62 _mk_opts() {
63     _d=no
64     for _o in "$@"
65     do
66         case "$_o" in
67         yes|no) _d=$_o; continue;;
68         esac
69         _mk_opt $_d $_o
70     done
71 }
72
73 _mk_opts_defaults() {
74     _mk_opts no $__DEFAULT_NO_OPTIONS yes $__DEFAULT_YES_OPTIONS
75 }
76
77 case "/$0" in
78 */mkopt*)
79     _list=no
80     while :
81     do
82         case "$1" in
83         *=*) eval "$1"; shift;;
84         --no|no) _list="$_list no"; shift;;
85         --yes|yes) _list="$_list yes"; shift;;
86         -DWITH*) eval "${1#-D}=1"; shift;;
87         [A-Z]*) _list="$_list $1"; shift;;
88         *) break;;
89         esac
90     done
91     _mk_opts $_list
92     ;;
93 esac
94