+Automatic rebulding and pre-building of kernel module.
authorshort <>
Wed, 20 Aug 2003 13:43:45 +0000 (13:43 +0000)
committershort <>
Wed, 20 Aug 2003 13:43:45 +0000 (13:43 +0000)
autogen.pl
configure.in
kernel/Linux/2.4/Makefile.am
kernel/Linux/2.5/Makefile.am
kernel/Linux/Makefile.am
kernel/Linux/modbin/Makefile.am [new file with mode: 0644]
kernel/Linux/prepmod.in [new file with mode: 0755]
lufs.spec.in
util/Makefile.am

index c0ea5e0..1994c9b 100755 (executable)
@@ -40,6 +40,9 @@ AutoGen->run(
                                ./util/lufsmnt
                                ./util/lufsmount
                                ./util/lufsumount
+                               ./kernel/Linux/prepmod
+                               ./kernel/Linux/modbin/*.o
+                               ./kernel/Linux/modbin/prepmod-tmp-dir
                                )],
                "ChangeLog"=>"ChangeLog.captive",
                );
index 103f7bf..e9a2ab8 100644 (file)
@@ -305,11 +305,14 @@ AC_OUTPUT(\
        kernel/Linux/Makefile \
        kernel/Linux/2.4/Makefile \
        kernel/Linux/2.5/Makefile \
+       kernel/Linux/modbin/Makefile \
        include/Makefile \
        docs/Makefile \
        man/Makefile \
        lufs.spec \
+       kernel/Linux/prepmod \
         )
+chmod +x kernel/Linux/prepmod
 
 echo "###############################################################################"
 echo " supported filesystems: $opt_fs"
index b30b888..3911e4e 100644 (file)
@@ -1,19 +1,7 @@
-INCLUDES=-I@KERNEL_HDR@ @all_includes@
+basedir=$(datadir)/lufs
+src24dir=$(basedir)/2.4
 
-LIBS=
-
-AM_CFLAGS=@MODV_FLAGS@ @KDEBUG_FLAGS@ -O2 -pipe -fomit-frame-pointer -fno-strict-aliasing -mpreferred-stack-boundary=2 -Wall -D__KERNEL__ -DMODULE -DLINUX
-AM_LDFLAGS=-r
-
-moduledir=@MODULES_DIR@/kernel/fs/lufs
-
-module_PROGRAMS=lufs.o
-
-noinst_HEADERS=lufs.h proc.h
-lufs_o_SOURCES=proc.c inode.c dir.c file.c symlink.c
-lufs_o_LDADD=
-
-install-data-hook:
-       depmod -aq
-       if [ "`lsmod | grep lufs`" ]; then rmmod lufs; fi
-       modprobe lufs
+src24_DATA= \
+               lufs.h proc.h \
+               proc.c inode.c dir.c file.c symlink.c
+EXTRA_DIST=$(src24_DATA)
index d372ae2..72c09a2 100644 (file)
@@ -1,19 +1,7 @@
-INCLUDES=-I@KERNEL_HDR@ -I@KERNEL_HDR@/asm-i386/mach-default @all_includes@
+basedir=$(datadir)/lufs
+src25dir=$(basedir)/2.5
 
-LIBS=
-
-AM_CFLAGS=@MODV_FLAGS@ @KDEBUG_FLAGS@ -DKBUILD_MODNAME=lufs -O2 -pipe -fomit-frame-pointer -fno-strict-aliasing -mpreferred-stack-boundary=2 -Wall -D__KERNEL__ -DMODULE -DLINUX
-AM_LDFLAGS=-r
-
-moduledir=@MODULES_DIR@/kernel/fs/lufs
-
-module_PROGRAMS=lufs.o
-
-noinst_HEADERS=lufs.h proc.h
-lufs_o_SOURCES=proc.c inode.c dir.c file.c symlink.c
-lufs_o_LDADD=
-
-install-data-hook:
-       depmod -aq
-       if [ "`lsmod | grep lufs`" ]; then rmmod lufs; fi
-       modprobe lufs
+src25_DATA= \
+               lufs.h proc.h \
+               proc.c inode.c dir.c file.c symlink.c
+EXTRA_DIST=$(src25_DATA)
index 6081b19..1155710 100644 (file)
@@ -1,2 +1,13 @@
-SUBDIRS = @KERNEL_DIR@
-DIST_SUBDIRS = 2.4 2.5
+SUBDIRS = 2.4 2.5 modbin
+
+EXTRA_DIST=prepmod.in
+
+basedir=$(datadir)/lufs
+
+base_SCRIPTS=prepmod
+
+install-exec-hook:
+       $(mkinstalldirs) $(DESTDIR)$(bindir)
+       $(RM) $(DESTDIR)$(bindir)/lufsmnt
+       $(LN_S) $(basedir)/prepmod $(DESTDIR)$(bindir)/lufsmnt
+
diff --git a/kernel/Linux/modbin/Makefile.am b/kernel/Linux/modbin/Makefile.am
new file mode 100644 (file)
index 0000000..34a35b6
--- /dev/null
@@ -0,0 +1,13 @@
+modbindir=$(datadir)/lufs/modbin
+
+# FIXME: We need double make invocation to properly build files and resolve the wildcard during 'install'!
+modbin_DATA=$(wildcard lufs-*.o)
+CLEANFILES=$(modbin_DATA)
+
+all-local: *.o
+
+*.o:
+       $(srcdir)/../prepmod --modbindir=. --basedir=$(srcdir)/.. --prebuild \
+                       $(wildcard /usr/src/kernel-headers-*) \
+                       $(wildcard $(top_srcdir)/../kernel-source-*.rpm)
+
diff --git a/kernel/Linux/prepmod.in b/kernel/Linux/prepmod.in
new file mode 100755 (executable)
index 0000000..ca9daa7
--- /dev/null
@@ -0,0 +1,202 @@
+#! /usr/bin/perl -w
+# 
+# $Id$
+# Check and possibly rebuild lufs kernel module for the current kernel.
+# Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+# 
+# 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; exactly version 2 of June 1991 is required
+# 
+# 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
+
+
+use strict;
+use Carp qw(cluck confess);
+use Getopt::Long;
+# Do not use any non-core Perl modules here.
+# Be perl-5.0 compatible (is it needed if we require Linux kernel >= 2.4 ?)
+
+
+my $basedir='@datadir@/lufs';
+$basedir=~s#\$\Q{prefix}\E#@prefix@#g;
+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;
+die if !GetOptions(
+               "q|quiet",\$quiet,
+                 "kernel",\$kernel,    # it must contain "include" subdir
+                 "modbindir=s",\$modbindir,
+                 "basedir=s",\$basedir,
+                 "prebuild",\&prebuild,
+                );
+
+
+my $lufsmnt_bin;
+if ($0 eq "lufsmnt" || $0=~m#/lufsmnt$#) {
+       $quiet=1;
+       $lufsmnt_bin='@modbindir@/lufsmnt-bin';
+       }
+
+
+sub _readfile
+{
+my($filename,$optional)=@_;
+
+       local $/=undef();
+       local *F;
+       open F,$filename or do { cluck "Open \"$filename\": $!" if !$optional; return ""; };
+       my $r=<F>;
+       close F or cluck "Close \"$filename\": $!";
+       return $r;
+}
+
+sub _system
+{
+my(@args)=@_;
+
+       print STDERR "+ ".join(" ",@args)."\n" if !$quiet;
+       return system @args;
+}
+
+sub _pass
+{
+my($load)=@_;
+
+       my $modproberc;
+       if ($load) {
+               do { ($modproberc=_system $_) and cluck "$_ failed - ignoring"; } for ("depmod -aq","modprobe lufs");
+               }
+       exit ($modproberc ? 1 : 0) if !$lufsmnt_bin;
+       do { exec $lufsmnt_bin,@ARGV; };
+       confess "Failed to exec '$lufsmnt_bin': $!";
+}
+
+
+my $filesystems=_readfile "/proc/filesystems"; # 'lufs' may be built-in
+_pass if $filesystems=~/\blufs$/m;
+my $modules=_readfile "/proc/modules"; # 'lufs' may be already loaded
+_pass if $modules=~/^lufs\b/m;
+_pass if !_system "modprobe lufs";
+
+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_r_base=($uname_r=~/^([^-]+)/)[0];
+print STDERR "Running kernel version: $uname_r (base version $uname_r_base)\n" if !$quiet;
+
+do { $kernel||=$_ if -d $_; } for ("/lib/modules/$uname_r/build");
+do { $kernel||=$_ if -d $_; } for ("/usr/src/kernel-headers-$uname_r");
+do { $kernel||=$_ if -d $_; } for ("/usr/src/linux-$uname_r");
+do { $kernel||=$_ if -d $_; } for ("/usr/src/linux-$uname_r_base");
+do { $kernel||=$_ if -d $_; } for ("/usr/src/linux");
+confess "Failed to find kernel headers for $uname_r" if !$kernel;
+
+my $moduledir="/lib/modules/$uname_r/kernel/fs/lufs";
+print STDERR "Destination module directory: $moduledir\n" if !$quiet;
+_system "mkdir -p $moduledir" and confess "Cannot create moduledir: $moduledir";
+
+_pass 1 if build($kernel,$uname_r,"$moduledir/lufs.o");
+
+local $_;
+while (<$modbindir/*.o>) {
+       next if _system "rmmod lufs 2>/dev/null; insmod -o lufs -p $_ 2>/dev/null";
+       do { cluck "Failed to symlink $_"; next; } if _system "mkdir -p $moduledir; ln -s $_ $moduledir/lufs.o";
+       _pass 1;
+       }
+confess "lufs module not loaded: $basedir not compilable and no module of $modbindir/*.o usable";
+
+
+sub build
+{
+my($kernel,$uname_r,$destmodule)=@_;
+
+       print STDERR "Using kernel sources: $kernel\n" if !$quiet;
+       confess "Kernel sources $kernel do not contain 'include' subdirectory" if ! -d $kernel."/include";
+
+       my $cmdline="gcc"
+                       .($quiet ? " 2>/dev/null" : "")
+                       ." -O2 -pipe -fomit-frame-pointer -fno-strict-aliasing -mpreferred-stack-boundary=2 -Wall"
+                       ." -D__KERNEL__ -DMODULE -DLINUX -DKBUILD_MODNAME=lufs"
+                       ." -I$kernel/include"
+                       ." -I$kernel/include/asm-i386/mach-default";    # gcc should not care if this 2.5 dir does not exist
+
+       my $config=_readfile "$kernel/.config","optional";
+       my $autoconf=_readfile "$kernel/include/linux/autoconf.h","optional";
+       $cmdline.=" -DMODVERSIONS -include $kernel/include/linux/modversions.h"
+                       if 0
+                                       || $config=~/^CONFIG_MODVERSIONS=y\b/m
+                                       || $autoconf=~/^#define CONFIG_MODVERSIONS\b/m
+                                       || (!$config && !$autoconf);    # assume modversions if not known
+
+       my @objects=map({ my $o=$_; $o=~s/[.]c$/.o/; $o; } @sources);
+       return !_system "set -e; mkdir -p `dirname $destmodule`;"
+                       ." $cmdline -c ".join(" ",map({ srcdir($uname_r)."/".$_; } @sources)).";"
+                       ." ld -r -o $destmodule ".join(" ",@objects).";"
+                       ." rm -f ".join(" ",@objects);
+}
+
+
+sub prebuild_kernel
+{
+my($dir,$vendor,$uname_r)=@_;
+
+       confess "Unrecognized vendor for dir: $dir" if !$vendor;
+       confess "Unrecognized uname_r for dir: $dir" if !$uname_r;
+       confess "Failed to build $dir" if !build $dir,$uname_r,$modbindir."/lufs-$vendor-$uname_r.o";
+}
+
+
+sub prebuild_rpm
+{
+my($rpm)=@_;
+
+       my $vendor=_readfile "rpm 2>/dev/null --qf '%{VENDOR}' -qp '$rpm' |";
+       $vendor=~s/,.*//;
+       $vendor=~tr/ //d;
+       my $uname_r;
+       $uname_r||=($rpm=~m#/kernel-source-([^-]+-[^-]+)[.][^.]+[.]rpm$#)[0];
+       _system "rm -rf $tmp_dir; mkdir $tmp_dir; set -e;"
+                       # Here we will extract even some false 'include's but we filter dirs just for speed/space.
+                       ." rpm2cpio '$rpm' | (cd $tmp_dir; cpio -id --quiet ./usr/src/linux*/{.config,include/*})"
+                       and confess "Extraction of: $rpm";
+       prebuild_kernel $tmp_dir."/usr/src/linux-$uname_r",$vendor,$uname_r;
+       _system "rm -rf $tmp_dir" and confess "Deletion of: $tmp_dir";
+}
+
+sub prebuild_dir
+{
+my($dir)=@_;
+
+       my $vendor;
+       chomp (my $debian=_readfile "/etc/debian_version","optional");
+       $vendor="Debian".$debian if $debian && $dir=~m#^/usr/src/#;
+       my $uname_r;
+       $uname_r||=($dir=~m#/kernel-headers-([^/]+)/*$#)[0];
+       $uname_r||=($dir=~m#/linux-([^/]+)/*$#)[0];
+       $uname_r||=($dir=~m#^/lib/modules/([^/]+)/build/*$#)[0];
+       prebuild_kernel $dir,$vendor,$uname_r;
+}
+
+sub prebuild
+{
+       for (@ARGV) {
+               do { prebuild_rpm $_; next; } if /[.]rpm$/;
+               do { prebuild_dir $_; next; } if -d $_;
+               confess "Unrecognized kernel: $_";
+               }
+       exit 0;
+}
index 302d04d..4c63ca0 100644 (file)
@@ -1,22 +1,16 @@
-# Your kernel version, tries to auto-detect here
-%define kernelversion %(uname -r)
-
 Summary:       lufs - Linux Userland File System
 Name:          @PACKAGE@
 Version:       @VERSION@
-Release:       1
+Release:       1captive
 License:       GPL
 Group:         Base
 Source0:       @PACKAGE@-@VERSION@.tar.gz
 Patch1:                @PACKAGE@-@VERSION@-captive.patch
-
 BuildRequires: autoconf
 BuildRequires: automake
 BuildRequires: libtool
-#BuildRequires:        kernel-source = %{kernelversion}
-
-#Requires:   kernel = %{kernelversion}
-
+BuildRequires: perl
+Requires:      perl
 BuildRoot:     /tmp/buildroot-@PACKAGE@-@VERSION@
 
 %description
@@ -25,6 +19,15 @@ sshfs, ftpfs, localfs, locasefs, gvfs, cardfs, cefs, etc.  Lots of other
 "exotic" filesystems are in the planning phase: socketfs, httpfs, freenetfs
 and others.
 
+%package devel
+Summary:       lufs - Linux Userland File System files for filesystems development
+Group:         Development/Base
+Requires:      lufs = %{PACKAGE_VERSION}
+
+%description devel
+Support for development of 3rd party filesystem modules for LUFS - a hybrid
+userspace filesystem framework supporting many filesystems: sshfs, ftpfs,
+localfs, locasefs, gvfs, cardfs, cefs, etc.
 
 %prep
 %setup -q
@@ -38,66 +41,58 @@ and others.
 %{__automake} --add-missing
 %{__autoconf}
 %configure
-#      --with-kernel=%{kernelversion} \
-#      --with-kheaders=/lib/modules/%{kernelversion}/build/include 
 %{__make}
 
 %install
 rm -rf $RPM_BUILD_ROOT
-
-%{__make} install \
-       DESTDIR=$RPM_BUILD_ROOT
+%{__make} install DESTDIR=$RPM_BUILD_ROOT
 
 %clean
 rm -rf $RPM_BUILD_ROOT
 
 %post
-
-ln -s /usr/bin/auto.sshfs /etc/auto.sshfs
-ln -s /usr/bin/auto.ftpfs /etc/auto.ftpfs
-ln -s /usr/bin/lufsd /sbin/mount.lufs
-
+ln -s %{_bindir}/auto.sshfs /etc/auto.sshfs
+ln -s %{_bindir}/auto.ftpfs /etc/auto.ftpfs
+ln -s %{_bindir}/lufsd /sbin/mount.lufs
 depmod -a
-
 if [ "`lsmod | grep lufs`" ]; then rmmod lufs; fi
-
 modprobe lufs
 
 %preun
-
 if [ "`lsmod | grep lufs`" ]; then rmmod lufs; fi
 
 %postun
-
 depmod -a
-
 rm -f /etc/auto.sshfs
 rm -f /etc/auto.ftpfs
 rm -f /sbin/mount.lufs
 
-
 %files
 %defattr(644,root,root)
-
-/lib/modules/%{kernelversion}/kernel/fs/lufs/lufs.o
 /etc/lufsd.conf
-
+%{_datadir}/lufs
 %defattr(755,root,root)
-
-/usr/bin/lufsd
-/usr/bin/lussh
-/usr/bin/lufsmount
-
-/usr/bin/auto.sshfs
-/usr/bin/auto.ftpfs
-
+%{_bindir}/lufsd
+%{_bindir}/lussh
+%{_bindir}/lufsmount
+%{_bindir}/lufsmnt
+%{_bindir}/auto.sshfs
+%{_bindir}/auto.ftpfs
+%{_libdir}/lib*.so*
+%{_mandir}/man*/lufs*
 # These are SUID root...
-
 %defattr(4755,root,root)
-/usr/bin/lufsmnt
-/usr/bin/lufsumount
+%{_bindir}/lufsmnt-bin
+%{_bindir}/lufsumount
 
+%files devel
+%defattr(644,root,root)
+%{_includedir}/lufs
+%{_libdir}/lib*.la
 
 %changelog
+* Wed Aug 20 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+- rewritten for AutoGen as a support subsystem of Captive project
+
 * Sun Nov 24 2002 Dave Wilson <dave@...>
 - initial version
index d684828..16c1288 100644 (file)
@@ -1,11 +1,11 @@
 INCLUDES=-I../
 LSUID:= @LUFS_SUID@
 
-bin_PROGRAMS=lufsmount lufsumount lufsmnt auto.sshfs auto.ftpfs
+bin_PROGRAMS=lufsmount lufsumount lufsmnt-bin auto.sshfs auto.ftpfs
 
 lufsmount_SOURCES=lufsmount.c
 lufsumount_SOURCES=lufsumount.c
-lufsmnt_SOURCES=lufsmnt.c
+lufsmnt_bin_SOURCES=lufsmnt.c
 auto_sshfs_SOURCES=auto.sshfs.c
 auto_ftpfs_SOURCES=auto.ftpfs.c