#!/bin/sh -e
# 
# This script generates headers required by
# /usr/include/linux/{autoconf,modversions,version}.h
#
# Copyright (C) 2001,2002  Dmitry V. Levin <ldv@altlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

[ -n "$VAR_RUN_KERNEL" ] || VAR_RUN_KERNEL=/var/run/kernel
cd "$VAR_RUN_KERNEL"

[ -n "$KERNEL_VERSION" ] || KERNEL_VERSION="$(uname -r)"

for USR_LIB_KERNEL in $USR_LIB_KERNEL /usr/lib/kernel /var/lib/kernel; do
	[ ! -d "$USR_LIB_KERNEL/$KERNEL_VERSION" ] || break
done

[ -d "$USR_LIB_KERNEL/$KERNEL_VERSION" ]

for n in autoconf modversions version; do
	fgrep -qs "#include <$USR_LIB_KERNEL/$KERNEL_VERSION/$n.h>" "$n.h" ||
	cat >"$n.h" << EOF
/*
 * Autogenerated by $0 at $(LANG=C date '+%a %b %d %Y %T')
*/

#ifndef	__boot_kernel_${n}__
#define	__boot_kernel_${n}__

#include <$USR_LIB_KERNEL/$KERNEL_VERSION/$n.h>

#endif	/* __boot_kernel_${n}__ */
EOF
done

H2PH=/usr/bin/h2ph
if [ -x "$H2PH" ]; then
	"$H2PH" -l -Q -d "$VAR_RUN_KERNEL" {autoconf,modversions,version}.h
fi
