Subject: Major oops in PKG_OPTIONS_LEGACY_VARS
To: None <tech-pkg@netbsd.org>
From: Todd Vierling <tv@duh.org>
List: tech-pkg
Date: 11/02/2005 10:27:33
It seems that setting USE_INET6=NO does not actually remove "inet6" from the
default options, and thus it does not do what the user expects.  This is
rather bad.  The reason is the block doing the mapping:

=====
.for _m_ in ${PKG_OPTIONS_LEGACY_VARS}
_var_:=	${_m_:C/:.*//}
_opt_:=	${_m_:C/.*://}
_popt_:=${_opt_:C/^-//}
.  if !empty(PKG_SUPPORTED_OPTIONS:M${_popt_})
.    if defined(${_var_})
.      if empty(${_var_}:M[nN][oO])
PKG_LEGACY_OPTIONS:=${PKG_LEGACY_OPTIONS} ${_opt_}
PKG_OPTIONS_DEPRECATED_WARNINGS:=${PKG_OPTIONS_DEPRECATED_WARNINGS} "Deprecated variable "${_var_:Q}" set to "${${_var_}:Q}", use PKG_DEFAULT_OPTIONS+="${_opt_:Q}" instead."
.      elif empty(_opt_:M-*)
PKG_LEGACY_OPTIONS:=${PKG_LEGACY_OPTIONS} -${_popt_}
PKG_OPTIONS_DEPRECATED_WARNINGS:=${PKG_OPTIONS_DEPRECATED_WARNINGS} "Deprecated variable "${_var_:Q}" set to "${${_var_}:Q}", use PKG_DEFAULT_OPTIONS+=-"${_popt_:Q}" instead."
.      else
PKG_LEGACY_OPTIONS:=${PKG_LEGACY_OPTIONS} ${_popt_}
PKG_OPTIONS_DEPRECATED_WARNINGS:=${PKG_OPTIONS_DEPRECATED_WARNINGS} "Deprecated variable "${_var_:Q}" set to "${${_var_}:Q}", use PKG_DEFAULT_OPTIONS+="${_popt_:Q}" instead."
.      endif
.    endif
.  endif
.endfor
.undef _var_
.undef _opt_
.undef _popt_
=====

Now, obsolete.mk sets USE_INET6:inet6.  In the USE_INET6=NO case, where
"-inet6" is not in the list of options set by the user, we fall through to
the third setting block.

If you look carefully, you'll see that "_popt_" simply removes any leading
"-" from the option name -- but does not add one if one did not exist in the
first place.  So, in a case like USE_INET6:inet6, the third setting block is
identical to the first one, turning the option *on* rather than off.

The direct fix for this problem is to change the definition of _popt_ to:

_popt_:=${_opt_:C/^/-/:C/^--//}

which will add a hyphen; then if there was a hyphen to begin with, remove
both to make a hyphenless option.

However, it may be necessary to check carefully and see if this will affect
any packages where the legacy option is ON by default, and thus require a
PKGREVISION bump.  USE_INET6 is not a problem, as platforms without inet6
support cannot build those packages right now anyway.  But there may be
isolated cases in packages or other mappings in obsolete.mk.

-- 
-- Todd Vierling <tv@duh.org> <tv@pobox.com> <todd@vierling.name>