Dynamically detect the way the shell matches \ in a pattern,
and use whatever works for the sh running this script. Previously we were using the (broken, and incorrect) method that worked in old broken NetBSD sh's (and some others) and not the method that works with the current (fixed) /bin/sh and other correct shells (like bash). (For an exotic reason, in the particular use case, both methods work with ksh93, but it is also generally correct). This hasn't really mattered, as the difference is only significant (only causes actual issues - the build fails) when compiling with DEBUG enabled, which is something that most sane humans would never do, if they want to retain that sanity. The problem was detected by Patrick Welche when looking for an unrelated problem, which was once considered to be a possible sh problem, but turned out to be something entirely different. XXX pullup -8
This commit is contained in:
parent
9910e74525
commit
e5830c7775
|
@ -1,5 +1,5 @@
|
|||
#! /bin/sh
|
||||
# $NetBSD: mkinit.sh,v 1.8 2018/09/16 22:31:30 kre Exp $
|
||||
# $NetBSD: mkinit.sh,v 1.9 2018/10/18 04:24:43 kre Exp $
|
||||
|
||||
# Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
# All rights reserved.
|
||||
|
@ -33,7 +33,37 @@ srcs="$*"
|
|||
nl='
|
||||
'
|
||||
openparen='('
|
||||
backslash='\'
|
||||
|
||||
# shells have bugs (including older NetBSD sh) in how \ is
|
||||
# used in pattern matching. So work out what the shell
|
||||
# running this script expects. We could also just use a
|
||||
# literal \ in the pattern, which would need to be quoted
|
||||
# of course, but then we'd run into a whole host of potential
|
||||
# other shell bugs (both with the quoting in the pattern, and
|
||||
# with the matching that follows if that works as inended).
|
||||
# Far easier, and more reliable, is to just work out what works,
|
||||
# and then use it, which more or less mandates using a variable...
|
||||
backslash='\\'
|
||||
var='abc\' # dummy test case.
|
||||
if [ "$var" = "${var%$backslash}" ]
|
||||
then
|
||||
# buggy sh, try the broken way
|
||||
backslash='\'
|
||||
if [ "$var" = "${var%$backslash}" ]
|
||||
then
|
||||
printf >&2 "$0: %s\n" 'No pattern match with \ (broken shell)'
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
# We know we can detect the presence of a trailing \, which is all we need.
|
||||
# Now to confirm we will not generate false matches.
|
||||
var='abc'
|
||||
if [ "$var" != "${var%$backslash}" ]
|
||||
then
|
||||
printf >&2 "$0: %s\n" 'Bogus pattern match with \ (broken shell)'
|
||||
exit 1
|
||||
fi
|
||||
unset var
|
||||
|
||||
includes=' "shell.h" "mystring.h" "init.h" '
|
||||
defines=
|
||||
|
|
Loading…
Reference in New Issue