[PATCH] attempt to not install to buildroot in %build

Kyle McMartin kmcmartin at redhat.com
Wed Nov 2 17:55:03 UTC 2011


This can probably be better but...
---
 kernel.spec |  112 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/kernel.spec b/kernel.spec
index ff5734e..1e38fbe 100644
--- a/kernel.spec
+++ b/kernel.spec
@@ -1,6 +1,3 @@
-# We have to override the new %%install behavior because, well... the kernel is special.
-%global __spec_install_pre %{___build_pre}
-
 Summary: The Linux kernel
 
 # For a stable, released kernel, released_kernel should be 1. For rawhide
@@ -1386,6 +1383,8 @@ cd ..
 ###
 %build
 
+TARGET=$PWD/buildroot-%{rpmversion}-%{pkg_release}
+
 %if %{with_sparse}
 %define sparse_mflags	C=1
 %endif
@@ -1457,36 +1456,36 @@ BuildKernel() {
 
     # Start installing the results
 %if %{with_debuginfo}
-    mkdir -p $RPM_BUILD_ROOT%{debuginfodir}/boot
-    mkdir -p $RPM_BUILD_ROOT%{debuginfodir}/%{image_install_path}
+    mkdir -p $TARGET%{debuginfodir}/boot
+    mkdir -p $TARGET%{debuginfodir}/%{image_install_path}
 %endif
-    mkdir -p $RPM_BUILD_ROOT/%{image_install_path}
-    install -m 644 .config $RPM_BUILD_ROOT/boot/config-$KernelVer
-    install -m 644 System.map $RPM_BUILD_ROOT/boot/System.map-$KernelVer
+    mkdir -p $TARGET/%{image_install_path}
+    install -m 644 .config $TARGET/boot/config-$KernelVer
+    install -m 644 System.map $TARGET/boot/System.map-$KernelVer
 
     # We estimate the size of the initramfs because rpm needs to take this size
     # into consideration when performing disk space calculations. (See bz #530778)
-    dd if=/dev/zero of=$RPM_BUILD_ROOT/boot/initramfs-$KernelVer.img bs=1M count=20
+    dd if=/dev/zero of=$TARGET/boot/initramfs-$KernelVer.img bs=1M count=20
 
     if [ -f arch/$Arch/boot/zImage.stub ]; then
-      cp arch/$Arch/boot/zImage.stub $RPM_BUILD_ROOT/%{image_install_path}/zImage.stub-$KernelVer || :
+      cp arch/$Arch/boot/zImage.stub $TARGET/%{image_install_path}/zImage.stub-$KernelVer || :
     fi
     $CopyKernel $KernelImage \
-    		$RPM_BUILD_ROOT/%{image_install_path}/$InstallName-$KernelVer
-    chmod 755 $RPM_BUILD_ROOT/%{image_install_path}/$InstallName-$KernelVer
+    		$TARGET/%{image_install_path}/$InstallName-$KernelVer
+    chmod 755 $TARGET/%{image_install_path}/$InstallName-$KernelVer
 
-    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer
+    mkdir -p $TARGET/lib/modules/$KernelVer
     # Override $(mod-fw) because we don't want it to install any firmware
     # we'll get it from the linux-firmware package and we don't want conflicts
-    make -s ARCH=$Arch INSTALL_MOD_PATH=$RPM_BUILD_ROOT modules_install KERNELRELEASE=$KernelVer mod-fw=
+    make -s ARCH=$Arch INSTALL_MOD_PATH=$TARGET modules_install KERNELRELEASE=$KernelVer mod-fw=
 %ifarch %{vdso_arches}
-    make -s ARCH=$Arch INSTALL_MOD_PATH=$RPM_BUILD_ROOT vdso_install KERNELRELEASE=$KernelVer
+    make -s ARCH=$Arch INSTALL_MOD_PATH=$TARGET vdso_install KERNELRELEASE=$KernelVer
     if [ ! -s ldconfig-kernel.conf ]; then
       echo > ldconfig-kernel.conf "\
 # Placeholder file, no vDSO hwcap entries used in this kernel."
     fi
     %{__install} -D -m 444 ldconfig-kernel.conf \
-        $RPM_BUILD_ROOT/etc/ld.so.conf.d/kernel-$KernelVer.conf
+        $TARGET/etc/ld.so.conf.d/kernel-$KernelVer.conf
 %endif
 
     # And save the headers/makefiles etc for building modules against
@@ -1496,52 +1495,52 @@ BuildKernel() {
     # * all Makefile/Kconfig files
     # * all script/ files
 
-    rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
-    rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/source
-    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
-    (cd $RPM_BUILD_ROOT/lib/modules/$KernelVer ; ln -s build source)
+    rm -f $TARGET/lib/modules/$KernelVer/build
+    rm -f $TARGET/lib/modules/$KernelVer/source
+    mkdir -p $TARGET/lib/modules/$KernelVer/build
+    (cd $TARGET/lib/modules/$KernelVer ; ln -s build source)
     # dirs for additional modules per module-init-tools, kbuild/modules.txt
-    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/extra
-    mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/updates
+    mkdir -p $TARGET/lib/modules/$KernelVer/extra
+    mkdir -p $TARGET/lib/modules/$KernelVer/updates
     # first copy everything
-    cp --parents `find  -type f -name "Makefile*" -o -name "Kconfig*"` $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
-    cp Module.symvers $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
-    cp System.map $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
+    cp --parents `find  -type f -name "Makefile*" -o -name "Kconfig*"` $TARGET/lib/modules/$KernelVer/build
+    cp Module.symvers $TARGET/lib/modules/$KernelVer/build
+    cp System.map $TARGET/lib/modules/$KernelVer/build
     if [ -s Module.markers ]; then
-      cp Module.markers $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
+      cp Module.markers $TARGET/lib/modules/$KernelVer/build
     fi
     # then drop all but the needed Makefiles/Kconfig files
-    rm -rf $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/Documentation
-    rm -rf $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/scripts
-    rm -rf $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include
-    cp .config $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
-    cp -a scripts $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
+    rm -rf $TARGET/lib/modules/$KernelVer/build/Documentation
+    rm -rf $TARGET/lib/modules/$KernelVer/build/scripts
+    rm -rf $TARGET/lib/modules/$KernelVer/build/include
+    cp .config $TARGET/lib/modules/$KernelVer/build
+    cp -a scripts $TARGET/lib/modules/$KernelVer/build
     if [ -d arch/$Arch/scripts ]; then
-      cp -a arch/$Arch/scripts $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/arch/%{_arch} || :
+      cp -a arch/$Arch/scripts $TARGET/lib/modules/$KernelVer/build/arch/%{_arch} || :
     fi
     if [ -f arch/$Arch/*lds ]; then
-      cp -a arch/$Arch/*lds $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/arch/%{_arch}/ || :
+      cp -a arch/$Arch/*lds $TARGET/lib/modules/$KernelVer/build/arch/%{_arch}/ || :
     fi
-    rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/scripts/*.o
-    rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/scripts/*/*.o
+    rm -f $TARGET/lib/modules/$KernelVer/build/scripts/*.o
+    rm -f $TARGET/lib/modules/$KernelVer/build/scripts/*/*.o
 %ifarch ppc
-    cp -a --parents arch/powerpc/lib/crtsavres.[So] $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
+    cp -a --parents arch/powerpc/lib/crtsavres.[So] $TARGET/lib/modules/$KernelVer/build/
 %endif
     if [ -d arch/%{asmarch}/include ]; then
-      cp -a --parents arch/%{asmarch}/include $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/
+      cp -a --parents arch/%{asmarch}/include $TARGET/lib/modules/$KernelVer/build/
     fi
-    cp -a include $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include
+    cp -a include $TARGET/lib/modules/$KernelVer/build/include
 
     # Make sure the Makefile and version.h have a matching timestamp so that
     # external modules can be built
-    touch -r $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/Makefile $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include/linux/version.h
-    touch -r $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/.config $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include/linux/autoconf.h
+    touch -r $TARGET/lib/modules/$KernelVer/build/Makefile $TARGET/lib/modules/$KernelVer/build/include/linux/version.h
+    touch -r $TARGET/lib/modules/$KernelVer/build/.config $TARGET/lib/modules/$KernelVer/build/include/linux/autoconf.h
     # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
-    cp $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/.config $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include/config/auto.conf
+    cp $TARGET/lib/modules/$KernelVer/build/.config $TARGET/lib/modules/$KernelVer/build/include/config/auto.conf
 
 %if %{with_debuginfo}
     if test -s vmlinux.id; then
-      cp vmlinux.id $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/vmlinux.id
+      cp vmlinux.id $TARGET/lib/modules/$KernelVer/build/vmlinux.id
     else
       echo >&2 "*** ERROR *** no vmlinux build ID! ***"
       exit 1
@@ -1550,11 +1549,11 @@ BuildKernel() {
     #
     # save the vmlinux file for kernel debugging into the kernel-debuginfo rpm
     #
-    mkdir -p $RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer
-    cp vmlinux $RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer
+    mkdir -p $TARGET%{debuginfodir}/lib/modules/$KernelVer
+    cp vmlinux $TARGET%{debuginfodir}/lib/modules/$KernelVer
 %endif
 
-    find $RPM_BUILD_ROOT/lib/modules/$KernelVer -name "*.ko" -type f >modnames
+    find $TARGET/lib/modules/$KernelVer -name "*.ko" -type f >modnames
 
     # mark modules executable so that strip-to-file can strip them
     xargs --no-run-if-empty chmod u+x < modnames
@@ -1567,7 +1566,7 @@ BuildKernel() {
     collect_modules_list()
     {
       sed -r -n -e "s/^([^ ]+) \\.?($2)\$/\\1/p" drivers.undef |
-      LC_ALL=C sort -u > $RPM_BUILD_ROOT/lib/modules/$KernelVer/modules.$1
+      LC_ALL=C sort -u > $TARGET/lib/modules/$KernelVer/modules.$1
     }
 
     collect_modules_list networking \
@@ -1583,7 +1582,7 @@ BuildKernel() {
     rm -f modinfo
     while read i
     do
-      echo -n "${i#$RPM_BUILD_ROOT/lib/modules/$KernelVer/} " >> modinfo
+      echo -n "${i#$TARGET/lib/modules/$KernelVer/} " >> modinfo
       /sbin/modinfo -l $i >> modinfo
     done < modnames
 
@@ -1596,26 +1595,24 @@ BuildKernel() {
     # remove files that will be auto generated by depmod at rpm -i time
     for i in alias alias.bin builtin.bin ccwmap dep dep.bin ieee1394map inputmap isapnpmap ofmap pcimap seriomap symbols symbols.bin usbmap
     do
-      rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/modules.$i
+      rm -f $TARGET/lib/modules/$KernelVer/modules.$i
     done
 
     # Move the devel headers out of the root file system
-    mkdir -p $RPM_BUILD_ROOT/usr/src/kernels
-    mv $RPM_BUILD_ROOT/lib/modules/$KernelVer/build $RPM_BUILD_ROOT/$DevelDir
-    ln -sf ../../..$DevelDir $RPM_BUILD_ROOT/lib/modules/$KernelVer/build
+    mkdir -p $TARGET/usr/src/kernels
+    mv $TARGET/lib/modules/$KernelVer/build $TARGET/$DevelDir
+    ln -sf ../../..$DevelDir $TARGET/lib/modules/$KernelVer/build
 
     # prune junk from kernel-devel
-    find $RPM_BUILD_ROOT/usr/src/kernels -name ".*.cmd" -exec rm -f {} \;
+    find $TARGET/usr/src/kernels -name ".*.cmd" -exec rm -f {} \;
 }
 
 ###
 # DO it...
 ###
 
-# prepare directories
-rm -rf $RPM_BUILD_ROOT
-mkdir -p $RPM_BUILD_ROOT/boot
-mkdir -p $RPM_BUILD_ROOT%{_libexecdir}
+rm -rf $TARGET
+mkdir -p $TARGET
 
 cd linux-%{kversion}.%{_target_cpu}
 
@@ -1706,6 +1703,9 @@ find Documentation -type d | xargs chmod u+w
 
 %install
 
+rm -rf $RPM_BUILD_ROOT/
+cp -ar buildroot-%{rpmversion}-%{pkg_release}/ $RPM_BUILD_ROOT/
+
 cd linux-%{kversion}.%{_target_cpu}
 
 %if %{with_doc}


More information about the kernel mailing list