From 5bb18d58a82194189ec8e0855040b0818c5efa1d Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Tue, 31 Mar 2009 18:41:40 -0700 Subject: [PATCH] Build shadow header files if there is no unified kernel header tree Debian's 2.6.29 packages no longer include symlinks from the architecture-specific header tree to the common header tree; instead, they use the kbuild machinery with multiple include paths to overlay the two header files. Adjust both the Autoconf probes to always use kbuild and the script that generates the build tree. For the latter, when we don't have a unified header tree, we need to generate headers in the place where the OpenAFS source expects them that include the linux/* headers. Patch from Aaron M. Ucko. --- src/cf/linux-test3.m4 | 35 ++++++------------ src/libafs/make_kbuild_makefile.pl | 59 +++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/src/cf/linux-test3.m4 b/src/cf/linux-test3.m4 index 8c3b296f9..a02562f13 100644 --- a/src/cf/linux-test3.m4 +++ b/src/cf/linux-test3.m4 @@ -1,12 +1,8 @@ AC_DEFUN([LINUX_KERNEL_LINUX_SYSCALL_H],[ AC_MSG_CHECKING(for linux/syscall.h in kernel) - if test -f "${LINUX_KERNEL_PATH}/include/linux/syscall.h"; then - ac_linux_syscall=yes - AC_MSG_RESULT($ac_linux_syscall) - else - ac_linux_syscall=no - AC_MSG_RESULT($ac_linux_syscall) - fi + AC_TRY_KBUILD([#include ], [], + [ac_linux_syscall=yes], [ac_linux_syscall=no]) + AC_MSG_RESULT($ac_linux_syscall) ]) AC_DEFUN([LINUX_NEED_RHCONFIG],[ @@ -16,17 +12,16 @@ if test "x$enable_redhat_buildsys" = "xyes"; then AC_MSG_WARN(Configured to build from a Red Hat SPEC file) else AC_MSG_CHECKING(for redhat kernel configuration) - if test -f "${LINUX_KERNEL_PATH}/include/linux/rhconfig.h"; then - ac_linux_rhconfig=yes + AC_TRY_KBUILD([#include ], [], + [ac_linux_rhconfig=yes], [ac_linux_rhconfig=no]) + AC_MSG_RESULT($ac_linux_rhconfig) + if test $ac_linux_rhconfig = yes; then RHCONFIG_SP="-D__BOOT_KERNEL_UP=1 -D__BOOT_KERNEL_SMP=0" RHCONFIG_MP="-D__BOOT_KERNEL_UP=0 -D__BOOT_KERNEL_SMP=1" AC_MSG_RESULT($ac_linux_rhconfig) if test ! -f "/boot/kernel.h"; then AC_MSG_WARN([/boot/kernel.h does not exist. build may fail]) fi - else - ac_linux_rhconfig=no - AC_MSG_RESULT($ac_linux_rhconfig) fi fi AC_SUBST(RHCONFIG_SP) @@ -76,11 +71,9 @@ AC_SUBST(MPS) AC_DEFUN([LINUX_KERNEL_SELINUX],[ AC_MSG_CHECKING(for SELinux kernel) -save_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="-I${LINUX_KERNEL_PATH}/include $CPPFLAGS" AC_CACHE_VAL(ac_cv_linux_kernel_is_selinux, [ -AC_TRY_COMPILE( +AC_TRY_KBUILD( [#include ], [#ifndef CONFIG_SECURITY_SELINUX #error not SELINUX @@ -88,15 +81,11 @@ AC_TRY_COMPILE( ac_cv_linux_kernel_is_selinux=yes, ac_cv_linux_kernel_is_selinux=no)]) AC_MSG_RESULT($ac_cv_linux_kernel_is_selinux) -CPPFLAGS="$save_CPPFLAGS"]) +]) AC_DEFUN([LINUX_KERNEL_LINUX_SEQ_FILE_H],[ AC_MSG_CHECKING(for linux/seq_file.h in kernel) - if test -f "${LINUX_KERNEL_PATH}/include/linux/seq_file.h"; then - ac_linux_seq_file=yes - AC_MSG_RESULT($ac_linux_seq_file) - else - ac_linux_seq_file=no - AC_MSG_RESULT($ac_linux_seq_file) - fi + AC_TRY_KBUILD([#include ], [], + [ac_linux_seq_file=yes], [ac_linux_seq_file=no]) + AC_MSG_RESULT($ac_linux_seq_file) ]) diff --git a/src/libafs/make_kbuild_makefile.pl b/src/libafs/make_kbuild_makefile.pl index dd10db1e3..7f73a761d 100755 --- a/src/libafs/make_kbuild_makefile.pl +++ b/src/libafs/make_kbuild_makefile.pl @@ -90,12 +90,61 @@ foreach (@objects) { symlink($deps{$_}, "$KDIR/$src") or die "$KDIR/$src: $!\n"; } -foreach $src (qw(h sys netinet)) { - if (-e "$KDIR/$src" || -l "$KDIR/$src") { - unlink("$KDIR/$src") or die "$KDIR/$src: $!\n"; +%remap = ('h' => 'linux', 'netinet' => 'linux', 'sys' => 'linux'); +if (-f "$vars{LINUX_KERNEL_PATH}/include/linux/types.h") { + foreach $src (keys %remap) { + if (-e "$KDIR/$src" || -l "$KDIR/$src") { + unlink("$KDIR/$src") or die "$KDIR/$src: $!\n"; + } + symlink("$vars{LINUX_KERNEL_PATH}/include/linux", "$KDIR/$src") + or die "$KDIR/$src: $!\n"; + } +} else { + foreach $src (keys %remap) { + system ('rm', '-rf', "$KDIR/$src"); # too crude? + mkdir("$KDIR/$src", 0777) or die "$KDIR/$src: $!\n"; + } + %seen = (); + @q = <$KDIR/*.[Sc]>; + @include_dirs = map { /^\// ? $_ : "$KDIR/$_" } + split /[\s\\]*-I/, $vars{COMMON_INCLUDE}; + push @include_dirs, "$vars{TOP_SRCDIR}/../include/rx", "$vars{TOP_SRCDIR}/rx"; + while (@q) { + $src = shift @q; + $content = new IO::File($src, O_RDONLY) or die "$src: $!\n"; + LINE: + while (<$content>) { + chomp; + if (/^\s*#\s*include\s*[<"](?:\.\.\/)?([^\/>"]*)(.*?)[>"]/) { + $inc = "$1$2"; + if (exists $seen{$inc}) { + next; + } elsif (exists $remap{$1} && $2 !~ /.\//) { + $H = new IO::File("$KDIR/$inc", O_WRONLY|O_CREAT|O_TRUNC, 0666) + or die "$KDIR/$inc: $!\n"; + print $H "#include \n"; + $H->close() or die "$KDIR/$inc: $!\n"; + } else { + for $dir (@include_dirs) { + if (-f "$dir/$inc") { + push @q, "$dir/$inc"; + $seen{$inc} = 1; + next LINE; + } + } + if ($1 =~ /^(arpa|asm|.*fs|i?net|kern|ksys|linux|mach|rpc|scsi|vm)$/ + || !length($2)) { + # Safe to ignore silently. + } else { + warn "Ignoring $_ ($inc not found)\n"; + } + } + $seen{$inc} = 1; + } elsif (/^\s*#\s*include/) { + warn "Ignoring $_ (unrecognized syntax)\n"; + } + } } - symlink("$vars{LINUX_KERNEL_PATH}/include/linux", "$KDIR/$src") - or die "$KDIR/$src: $!\n"; } $cflags = "$vars{CFLAGS} $vars{COMMON_INCLUDE}"; -- 2.39.5