Fixed kernel sources path for 'smp' kernels.
[lufs.git] / kernel / Linux / prepmod.in
index b4bed7c..8acdf0f 100755 (executable)
@@ -118,7 +118,7 @@ my $modules=_readfile "/proc/modules";      # 'lufs' may be already loaded
 _pass if $modules=~/^lufs\b/m;
 _pass if !_system "/sbin/modprobe lufs 2>/dev/null";
 
-print STDERR "Preparing LUFS kernel module - this may take several minutes...\n";      # if !$quiet;
+print STDERR "Preparing LUFS kernel module... Run $basedir/prepmod if problems occur.\n";      # if !$quiet;
 
 my $proc_version=_readfile "/proc/version";
 my $uname_r=($proc_version=~/^Linux version (\S+)/)[0] || _readfile "uname -r|";
@@ -134,7 +134,7 @@ my $moduledir="/lib/modules/$uname_r$uname_smp/kernel/fs/lufs";
 print STDERR "Destination module directory: $moduledir\n" if !$quiet;
 
 my @kernel_paths=(
-                               "/lib/modules/$uname_r/build",
+                               "/lib/modules/$uname_r$uname_smp/build",
                                "/usr/src/kernel-headers-$uname_r",
                                "/usr/src/linux-$uname_r",
                                "/usr/src/linux-$uname_r_base",
@@ -156,6 +156,12 @@ else {
                if (build($kernel,$uname_r,$_)) {
                        do { cluck "Failed to symlink $_"; next; }
                                        if _system "/bin/rm -rf $moduledir; /bin/mkdir -p $moduledir; /bin/ln -s $_ $moduledir/$lufs_o";
+                       # Check if the compiled module matches the currently running kernel.
+                       # We may found some unspecific sources ('/usr/src/linux/'?) not matching the current kernel.
+                       # It still may be worth to try precompiled modules and/or give suggestive error messages.
+                       # Do not: /sbin/insmod -o lufs -p $_ 2>/dev/null
+                       # as 2.6 insmod has no options at all.
+                       next if _system "/sbin/rmmod lufs 2>/dev/null; /sbin/insmod $moduledir/$lufs_o 2>/dev/null";
                        _pass 1;
                        }
                }
@@ -176,7 +182,7 @@ confess "Failed to prepare $lufs_o module for your Linux kernel $uname_r.\n"
                .($kernel ? "Detected Linux kernel sources \"$kernel\" do not appear to be valid.\n"
                                : "No Linux kernel sources for your running kernel were found.\n")
                ."Please install kernel-source-x.y.z.i386.rpm or kernel-headers_x.y.z_i386.deb.\n"
-               ."The following directory paths were search (first existing directory used):\n"
+               ."The following directory paths were searched (first existing directory used):\n"
                .join("",map("\t\t$_\n",@kernel_paths));
 
 
@@ -253,8 +259,13 @@ my($kernel,$uname_r,$destmodule,%args)=@_;
        return $r if $r;
        # Rebuild existing '$kernel/tmp_include_depends' or '$kernel/.depend'
        # as it may contain non-existing pathnames:
-       _system "find $kernel -name .depend|xargs rm -f; make -C $kernel dep"
-                               .($quiet ? ' &>/dev/null' : '');
+       _system "find $kernel -name .depend|xargs rm -f;"
+                       # Red Hat 2.4.18-14 contains precompiled .so-dependent 'mkdep'
+                       ." rm -f $kernel/scripts/mkdep;"
+                       # SuSE 2.4.21-144 contains precompiled .so-dependent 'split-include'
+                       ." rm -f $kernel/scripts/split-include;"
+                       ." make -C $kernel dep"
+                                   .($quiet ? ' &>/dev/null' : '');
        return !_system $cmdline;
 }
 
@@ -300,7 +311,8 @@ sub prebuild_rpm
 my($rpm)=@_;
 
        my $vendor=_readfile "rpm 2>/dev/null --qf '%{VENDOR}' -qp '$rpm' |";
-       $vendor=~s/,.*//;
+       $vendor="unknown" if $vendor eq "(none)";       # TurboLinux 2.4.18-14
+       $vendor=~s/[,<].*//;
        $vendor=~tr/ //d;
        my $uname_r;
        $uname_r||=($rpm=~m#/kernel-source-([^-]+-[^-]+)[.][^.]+[.]rpm$#)[0];
@@ -321,15 +333,42 @@ my($rpm)=@_;
        _system "chmod -R u+w $dir" and confess "Make kernel source writable in $dir";
        _system "cp -p $dir/include/linux/rhconfig.h $dir/include/linux/rhconfig.h-orig"
                                if -f "$dir/include/linux/rhconfig.h";
+       my $built_total=0;
        if (-d "$dir/default" && -d "$dir/smp") {
                # new SuSE kernels
                for my $arch_d (glob "$dir/*") {
                        (my $arch=$arch_d)=~s#^.*/##;
                        prebuild_kernel $arch_d,$vendor,$uname_r.".".$arch;
+                       $built_total++;
+                       }
+               }
+       elsif (-e "$dir/SetupKernelSource.sh") {
+               # TurboLinux
+               if (! -e "$dir/include") {
+                       (my $kheaders=$rpm)=~s#/kernel-source-([^/]*)$#/kernel-headers-$1#
+                                       or confess "Invalid RPM basename of: $rpm";
+                       _system "rpm2cpio '$kheaders'|(cd modbin-tmp;cpio -id)"
+                                       and confess "RPM kheaders extraction of $rpm";
+                       }
+               for my $TYPE ("","smp","smp64G") {
+                       for my $ARCH (qw(i386 i586 i686 athlon)) {
+                               # Use even 'A-Z' for the 'release' for TurboLinux 2.4.9-3D
+                               next if !glob "$dir/configs/kernel-*-*[0-9A-Z]$TYPE-$ARCH.config";
+                               _system "set -ex; cd '$dir';"
+                                                               # Forbid 'cd /usr/src/linux' in './SetupKernelSource.sh'
+                                                               # but permit later 'cd's by make(1) subprocesses.
+                                                               # Therefore do not 'export -f cd;' but 'source ./SetupKernelSource.sh'.
+                                                               .' function cd { :; };' # Do not: 'export -f cd;'
+#                                                              .' function make {(set -ex;unset make; make "$@"; make symlinks; );}; export -f make;'
+                                                               # Permit 'errors' for 'grep smp' in TurboLinux 2.4.5-0.5
+                                                               ." set +e; source ./SetupKernelSource.sh $ARCH$TYPE;"
+                                               and confess "SetupKernelSource.sh $ARCH$TYPE in $dir";
+                               prebuild_kernel $dir,$vendor,$uname_r.".".$ARCH.$TYPE;
+                               $built_total++;
+                               }
                        }
                }
        else {
-               my $built_total=0;
                # RedHat/Mandrake/old-SuSE kernels
                for my $smp ("","smp") {
                        my @archs=qw(i386 i586 i686 athlon);
@@ -376,9 +415,9 @@ RHCONFIG_H_NOBOOT_EOF
                                                if !$single_config;
                                }
                        }
-               # Old SuSE kernels have no '.config' or 'configs/'.
-               confess "Not a buildable kernel: $rpm" if !$built_total;
                }
+       # Old SuSE kernels have no '.config' or 'configs/'.
+       confess "Not a buildable kernel: $rpm" if !$built_total;
        _system "rm -rf modbin-tmp" and confess "Remove of extracted kernel-source-$uname_r";
 }