#! /bin/sh -e

# DP: Use ucontext_t instead of struct ucontext on i386/amd64.

dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p0 < $0
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

--- gcc/config/i386/linux64.h.orig	2018-02-04 15:09:50.527970610 +0100
+++ gcc/config/i386/linux64.h	2018-02-04 15:10:04.611929680 +0100
@@ -112,7 +112,7 @@
     if (*(unsigned char *)(pc_+0) == 0x48				\
 	&& *(unsigned long *)(pc_+1) == 0x050f0000000fc0c7)		\
       {									\
-	struct ucontext *uc_ = (CONTEXT)->cfa;				\
+	ucontext_t *uc_ = (CONTEXT)->cfa;				\
 	sc_ = (struct sigcontext *) &uc_->uc_mcontext;			\
       }									\
     else								\
@@ -182,7 +182,7 @@
 	  struct siginfo *pinfo;					\
 	  void *puc;							\
 	  struct siginfo info;						\
-	  struct ucontext uc;						\
+	  ucontext_t uc;						\
 	} *rt_ = (CONTEXT)->cfa;					\
 	sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext;		\
       }									\
--- gcc/config/i386/linux.h.orig	2018-02-04 15:08:47.356154428 +0100
+++ gcc/config/i386/linux.h	2018-02-04 15:10:39.683827835 +0100
@@ -260,7 +260,7 @@
 	  siginfo_t *pinfo;					\
 	  void *puc;							\
 	  siginfo_t info;						\
-	  struct ucontext uc;						\
+	  ucontext_t uc;						\
 	} *rt_ = (CONTEXT)->cfa;					\
 	sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext;		\
       }									\
