diff --git a/bin/sh/mkinit.sh b/bin/sh/mkinit.sh index 57e6ef388d6e..62d5b2c2923a 100755 --- a/bin/sh/mkinit.sh +++ b/bin/sh/mkinit.sh @@ -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=