Compatibilized Linux kernel driver building.
authorshort <>
Sun, 28 Sep 2003 14:27:46 +0000 (14:27 +0000)
committershort <>
Sun, 28 Sep 2003 14:27:46 +0000 (14:27 +0000)
 - Suggestion/patch by Martin Drab.

autogen.pl
configure.in
kernel/Linux/2.4/Makefile.am
kernel/Linux/2.4/makefile.in [new file with mode: 0644]
kernel/Linux/2.5/Makefile.am
kernel/Linux/2.5/makefile.in [new file with mode: 0644]
kernel/Linux/prepmod.in

index 08f3e49..b8a375b 100755 (executable)
@@ -50,6 +50,8 @@ AutoGen->run(
                                ./kernel/Linux/prepmod
                                ./kernel/Linux/modbin/*.o
                                ./kernel/Linux/modbin/prepmod-tmp-dir
+                               ./kernel/Linux/2.4/makefile
+                               ./kernel/Linux/2.5/makefile
                                ./debian/changelog
                                )],
                "ChangeLog"=>"ChangeLog.captive",
index 5961c9c..c5a7924 100644 (file)
@@ -239,6 +239,8 @@ AC_OUTPUT(\
        lufs.spec \
        kernel/Linux/prepmod \
        debian/changelog \
+       kernel/Linux/2.4/makefile \
+       kernel/Linux/2.5/makefile \
         )
 
 echo "###############################################################################"
index 3911e4e..99ec121 100644 (file)
@@ -1,7 +1,13 @@
 basedir=$(datadir)/lufs
 src24dir=$(basedir)/2.4
 
-src24_DATA= \
+src24= \
                lufs.h proc.h \
                proc.c inode.c dir.c file.c symlink.c
-EXTRA_DIST=$(src24_DATA)
+
+src24_DATA= \
+               lufs.h proc.h \
+               proc.c inode.c dir.c file.c symlink.c \
+               makefile
+
+EXTRA_DIST=$(src24) makefile.in
diff --git a/kernel/Linux/2.4/makefile.in b/kernel/Linux/2.4/makefile.in
new file mode 100644 (file)
index 0000000..5d39477
--- /dev/null
@@ -0,0 +1,17 @@
+#We may get include to Makefile.am:
+ifdef TOPDIR
+
+obj-m := lufs.o
+
+lufs-objs := dir.o file.o inode.o proc.o symlink.o
+
+EXTRA_CFLAGS=-I@includedir@
+
+include $(TOPDIR)/Rules.make
+
+lufs.o: $(lufs-objs)
+       $(LD) -r -o $@ $(lufs-objs)
+
+else
+include Makefile
+endif
index 72c09a2..6937861 100644 (file)
@@ -1,7 +1,13 @@
 basedir=$(datadir)/lufs
 src25dir=$(basedir)/2.5
 
-src25_DATA= \
+src25= \
                lufs.h proc.h \
                proc.c inode.c dir.c file.c symlink.c
-EXTRA_DIST=$(src25_DATA)
+
+src25_DATA= \
+               lufs.h proc.h \
+               proc.c inode.c dir.c file.c symlink.c \
+               makefile
+
+EXTRA_DIST=$(src25) makefile.in
diff --git a/kernel/Linux/2.5/makefile.in b/kernel/Linux/2.5/makefile.in
new file mode 100644 (file)
index 0000000..5d39477
--- /dev/null
@@ -0,0 +1,17 @@
+#We may get include to Makefile.am:
+ifdef TOPDIR
+
+obj-m := lufs.o
+
+lufs-objs := dir.o file.o inode.o proc.o symlink.o
+
+EXTRA_CFLAGS=-I@includedir@
+
+include $(TOPDIR)/Rules.make
+
+lufs.o: $(lufs-objs)
+       $(LD) -r -o $@ $(lufs-objs)
+
+else
+include Makefile
+endif
index 2811439..9a2a9a9 100755 (executable)
@@ -27,19 +27,22 @@ use Getopt::Long;
 
 my $basedir='@datadir@/lufs';
 my $vardir='@localstatedir@/lib/lufs';
+my $includedir='@includedir@'; # '/lufs' is required by C '#include'
 $basedir=~s#\$\Q{prefix}\E#'@prefix@';#ge;
 $vardir=~s#\$\Q{prefix}\E#'@prefix@';#ge;
 $vardir="" if $vardir=~/^@/;
+$includedir=~s#\$\Q{prefix}\E#'@prefix@';#ge;
+$includedir="" if $includedir=~/^@/;
 sub srcdir { my($uname_r)=@_; $basedir."/".($uname_r lt "2.5" ? "2.4" : "2.5"); }
 my $modbindir=$basedir."/modbin";
 my @sources=qw(proc.c inode.c dir.c file.c symlink.c);
-my $tmp_dir="prepmod-tmp-dir";
 
 my $quiet;
 my $kernel;
 my $prebuild;
 use vars qw($kernel_gcc_args);
 $kernel_gcc_args="";
+$kernel_gcc_args="-I$includedir" if $includedir;
 
 my $lufsmnt_bin;
 if ($0 eq "lufsmnt" || $0=~m#/lufsmnt$#) {
@@ -115,10 +118,11 @@ my $proc_version=_readfile "/proc/version";
 my $uname_r=($proc_version=~/^Linux version (\S+)/)[0] || _readfile "uname -r|";
 chomp $uname_r;
 confess "Failed to detect kernel version" if !$uname_r;
+my $uname_smp=($uname_r=~s/smp$// && "smp");
 my $uname_r_base=($uname_r=~/^([^-]+)/)[0];
 print STDERR "Running kernel version: $uname_r (base version $uname_r_base)\n" if !$quiet;
 
-my $moduledir="/lib/modules/$uname_r/kernel/fs/lufs";
+my $moduledir="/lib/modules/$uname_r$uname_smp/kernel/fs/lufs";
 print STDERR "Destination module directory: $moduledir\n" if !$quiet;
 
 do { $kernel||=$_ if -d $_; } for ("/lib/modules/$uname_r/build");
@@ -155,7 +159,7 @@ for (<$modbindir/*-$uname_r*/*.o>,<$modbindir/*-${uname_r_base}*/*.o>,<$modbindi
 confess "lufs module not loaded: Try running $basedir/prepmod to see more.";
 
 
-sub build
+sub build_gcc
 {
 my($kernel,$uname_r,$destmodule)=@_;
 
@@ -192,6 +196,52 @@ my($kernel,$uname_r,$destmodule)=@_;
 }
 
 
+sub build_make
+{
+my($kernel,$uname_r,$destmodule)=@_;
+
+       print STDERR "Using kernel sources: $kernel\n" if !$quiet;
+       confess "Kernel sources $kernel do not contain 'Rules.make' file" if ! -f $kernel."/Rules.make";
+
+       my $kdebug="";
+       do { $kdebug=$_ if !/^@/; } for ('@KDEBUG_FLAGS@');
+       my $predir=srcdir $uname_r;
+       $predir=$ENV{"PWD"}."/$predir" if $predir!~m#^/#;
+       my $cmdline="make -C $kernel"
+                       ." SUBDIRS=\"$predir\" modules"
+                       ." EXTRA_CFLAGS=\"$kernel_gcc_args\""
+                       .($quiet ? ' &>/dev/null' : '');
+       my @objects=map({ my $o=$_; $o=~s/[.]c$/.o/; $o; } @sources);
+       return !_system "set -e; /bin/mkdir -p `dirname $destmodule`; /bin/rm -f $destmodule;"
+                       ." $cmdline;"
+                       ." /bin/rm -f ".join(" ",map(("$predir/$_","$predir/.$_.flags"),@objects)).";"
+                       ." /bin/mv -f $predir/lufs.o $destmodule;";
+}
+
+
+sub build
+{
+my($kernel,$uname_r,$destmodule)=@_;
+
+       my $arch=_readfile "uname -p|";
+       chomp $arch;
+       my $single_config=-f "$kernel/.config";
+       if (!$single_config) {
+               my $spec_config="$kernel/configs/kernel-$uname_r_base-$arch".($uname_smp ? "-smp" : "").".config";
+               _system "ln -s $spec_config $kernel/.config"
+                               if -f $spec_config;
+               }
+       my $r;
+       if (-f "$kernel/Rules.make" && -f "$kernel/.config")
+               { $r=build_make $kernel,$uname_r,$destmodule; }
+       else
+               { $r=build_gcc $kernel,$uname_r,$destmodule; }
+       _system "rm -f $kernel/.config"
+                       if !$single_config;
+       return $r;
+}
+
+
 sub prebuild_kernel
 {
 my($dir,$vendor,$uname_r)=@_;
@@ -212,27 +262,17 @@ my($rpm)=@_;
        my $uname_r;
        $uname_r||=($rpm=~m#/kernel-source-([^-]+-[^-]+)[.][^.]+[.]rpm$#)[0];
        my $uname_r_base=($uname_r=~/^([^-]+)/)[0];
-       _system "/bin/rm -rf $tmp_dir; /bin/mkdir $tmp_dir; set -e;"
-                       # Here we will extract even some false 'include's but we filter dirs just for speed/space.
-                       ." /usr/bin/rpm2cpio '$rpm' | (cd $tmp_dir; /bin/cpio -id --quiet ./usr/src/linux*/{.config,include/*})"
-                       and confess "Extraction of: $rpm";
        my $dir;
-       do { $dir||=$_ if -d $_; } for ($tmp_dir."/usr/src/linux-$uname_r");
-       do { $dir||=$_ if -d $_; } for ($tmp_dir."/usr/src/linux-$uname_r_base");       # older RedHat kernels
+       do { $dir||=$_ if -d $_; } for ("/usr/src/linux-$uname_r");
+       do { $dir||=$_ if -d $_; } for ("/usr/src/linux-$uname_r_base");        # older RedHat kernels
+       confess "Kernel sources already found in $dir" if $dir;
+       # '--nodeps' to prevent: error: Failed dependencies: perl-base is needed by *mdk
+       _system "rpm -i --nodeps '$rpm'" and confess "RPM installation of $rpm";
+       do { $dir||=$_ if -d $_; } for ("/usr/src/linux-$uname_r");
+       do { $dir||=$_ if -d $_; } for ("/usr/src/linux-$uname_r_base");        # older RedHat kernels
        $dir or confess "Kernel source tree not found in: $rpm";
-       _writefile "| patch $dir/include/linux/rhconfig.h",<<'RHCONFIG_H_NOBOOT_EOF';
---- ./include/linux/rhconfig.h-orig    Thu Aug 21 14:50:16 2003
-+++ ./include/linux/rhconfig.h Thu Aug 21 14:59:22 2003
-@@ -10,7 +10,7 @@
-  * /boot/kernel.h - initscripts should create it for us
-  */
--#include "/boot/kernel.h"
-+/* lufs: #include "/boot/kernel.h" */
- #if defined(__BOOT_KERNEL_SMP) && (__BOOT_KERNEL_SMP == 1)
- #define __module__smp
-RHCONFIG_H_NOBOOT_EOF
+       _system "cp -p $dir/include/linux/rhconfig.h $dir/include/linux/rhconfig.h-orig"
+                               if -f "$dir/include/linux/rhconfig.h";
        for my $smp ("","smp") {
                my @archs=qw(i386 i586 i686 athlon);
                for my $arch (@archs) {
@@ -245,13 +285,42 @@ RHCONFIG_H_NOBOOT_EOF
                                        "__BOOT_KERNEL_BIGMEM"=>0,
                                        "__BOOT_KERNEL_DEBUG"=>0,
                                        );
-                       local $kernel_gcc_args=join(" ",map({ " -D$_=".($boot{$_} ? 1 : 0); } keys(%boot)))
-                                       ." -march=$arch"
-                                       ." ".$kernel_gcc_args;
+                       if (-f "$dir/include/linux/rhconfig.h") {
+                               my $defines="";
+                               for (keys(%boot)) {
+                                       $defines.="+#define $_ ".($boot{$_} ? 1 : 0)."\n";
+                                       }
+                               _system "cp -p -f $dir/include/linux/rhconfig.h-orig $dir/include/linux/rhconfig.h";
+                               _writefile "| tee /tmp/1 | patch $dir/include/linux/rhconfig.h",<<"RHCONFIG_H_NOBOOT_EOF";
+--- ./include/linux/rhconfig.h-orig    Thu Aug 21 14:50:16 2003
++++ ./include/linux/rhconfig.h Thu Aug 21 14:59:22 2003
+\@\@ -10,7 +10,@{[ 7+keys(%boot) ]} \@\@
+  * /boot/kernel.h - initscripts should create it for us
+  */
+-#include "/boot/kernel.h"
++/* lufs: #include "/boot/kernel.h" */
+$defines
+ #if defined(__BOOT_KERNEL_SMP) && (__BOOT_KERNEL_SMP == 1)
+ #define __module__smp
+RHCONFIG_H_NOBOOT_EOF
+                               }
+                       _system "make -C $dir dep"
+                                       if ! -f "$dir/tmp_include_depends";
+                       # Mandrake packages have no configs/ and they have just that '.config' file.
+                       my $single_config=-f "$dir/.config";
+                       if (!$single_config) {
+                               my $spec_config="$dir/configs/kernel-$uname_r_base-$arch".($smp ? "-smp" : "").".config";
+                               next if ! -f $spec_config;
+                               _system "ln -s $spec_config $dir/.config";
+                               }
                        prebuild_kernel $dir,$vendor,$uname_r.$smp.".".$arch;
+                       _system "rm -f $dir/.config"
+                                       if !$single_config;
                        }
                }
-       _system "/bin/rm -rf $tmp_dir" and confess "Deletion of: $tmp_dir";
+       _system "rpm -e kernel-source-$uname_r" and confess "Remove of kernel-source-$uname_r";
+       _system "rm -rf $dir";
 }
 
 sub prebuild_dir