From ec45ce6222366e69adf1fad1b33ec8598229c8c0 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 20 Aug 2018 10:39:37 +0000 Subject: [PATCH] Make mkioctls script work on Linux and MacOS Using find -s will not work with the Linux or MacOS find command. We pipe to sort instead since the only real requirement here is that the order stays the same. While I am touching this file I also fixed a `==` construct which is not supported by POSIX sh but appears to work on FreeBSD. Reviewed By: imp Approved By: jhb (mentor) Differential Revision: https://reviews.freebsd.org/D14246 --- lib/libsysdecode/mkioctls | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/libsysdecode/mkioctls b/lib/libsysdecode/mkioctls index 03f53ead642e..05ae930888a1 100644 --- a/lib/libsysdecode/mkioctls +++ b/lib/libsysdecode/mkioctls @@ -17,19 +17,30 @@ LC_ALL=C; export LC_ALL # XXX should we use an ANSI cpp? ioctl_includes=$( cd $includedir - - filter='tee' - if [ "${MK_PF}" == "no" ]; then - filter='egrep -v (net/pfvar|net/if_pfsync)\.h' + set -e + # if /bin/sh is bash this will avoid further errors due to missing commands + if set -o | grep -q pipefail; then + set -o pipefail fi - find -H -s * -name '*.h' | \ + filter='tee' + if [ "${MK_PF}" = "no" ]; then + filter='egrep -v (net/pfvar|net/if_pfsync)\.h' + fi + # find -s would avoid the need to invoke sort but it is non-portable + find -L ./* -type f -name '*.h' | \ + LC_ALL=C sort | \ $filter | \ xargs egrep -l \ '^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | awk '{printf("#include <%s>\\n", $1)}' ) +if [ -z "$ioctl_includes" ]; then + echo "Failed to build list of ioctl headers" + exit 1 +fi + awk -v x="$ioctl_includes" 'BEGIN {print x}' | $CPP -nostdinc -I$includedir -dM -DCOMPAT_43TTY - | awk -v ioctl_includes="$ioctl_includes" '