#!/bin/bash

set -e

stem=${DEBIAN_STEM:-kernel}
version=${DEBIAN_UPSTREAM_VERSION}
pkg=$stem-headers-$version$debnum

arch=$DEB_HOST_ARCH
case $arch in
amd64)
	arch=x86_64
	;;
hppa)
	arch=parisc
	;;
esac

cd "$DEBIAN_SRCTOP"
home="$OLDPWD"
{
  find . -path './Documentation/*' -prune -o -path './debian/*' -prune -o \
    -path './scripts/*' -o -type f \( -name 'Makefile*' -o -name 'Kconfig*' \) -print
  echo arch/$arch/kernel/asm-offsets.s
} | cpio -pd --preserve-modification-time "$home"

cp -a ubuntu/include "$home/ubuntu"

cd "$home"

if [ "$arch" = "powerpc" ]; then
	rm -f arch/powerpc/include/asm
        ln -s ../../../include/asm-ppc arch/powerpc/include/asm
fi

cd "$DEBIAN_SRCTOP"
dh_strip --package=$pkg --tmpdir=$home
dh_fixperms --package=$pkg --tmpdir=$home
