#!/bin/sh

# wander through an Libreswan ng-patch directory,
# creating a patch file (to stdout)
# that will apply the code to a kernel source directory.
#
#

KERN=$1
shift

. packaging/utils/kernelpatching.sh

patch20=false
patch22=false
patch24=false
patch26=false

case $KERN in
    2.4) echo "SAref only supporte for 2.6+ kernels, not $KERN"; exit 1;;
    2.6) patchname=os2_6; patch26=true;;
    *) echo "Invalid kernel patch target: $KERN"; exit 1;;
esac

# make sure that sort gets the right locale.
LANG=C export LANG
LC_ALL=C export LC_ALL

find ng-patch -type f -print | grep -v CVS | egrep -v 'linux/Makefile' | sort | while read file 
do 
  base=`basename $file`
  pname=`echo $file | sed -e 's,\.fs._.$,,' -e 's,\.os._.$,,'`

  case $base in 
    TAGS) ;;
    tags) ;;
    .cvsignore) ;;
    .*.o.flags) ;;
    .\#*);;
    *.o) ;;
    *~) ;;
    tagsfile.mak) ;;
    *.$patchname.patch) cat $file;;
    *.$altname.patch) cat $file;;
    *.os2_0) fakeallpatch $patch20 $file $pname ;;
    *.os2_2) fakeallpatch $patch22 $file $pname ;;
    *.os2_4) fakeallpatch $patch24 $file $pname ;;
    *.os2_6) fakeallpatch $patch26 $file $pname ;;
    *.patch) ;;
    *) diff -u /dev/null $file;;
  esac
done

exit 0