Skip to content

Commit

Permalink
packaging: sync builddeb changes
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Nelson <[email protected]>
  • Loading branch information
RobertCNelson committed Apr 14, 2016
1 parent c839553 commit ff3e9a6
Showing 1 changed file with 86 additions and 26 deletions.
112 changes: 86 additions & 26 deletions scripts/package/builddeb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set -e
create_package() {
local pname="$1" pdir="$2"

mkdir -m 755 -p "$pdir/DEBIAN"
mkdir -p "$pdir/usr/share/doc/$pname"
cp debian/copyright "$pdir/usr/share/doc/$pname/"
cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
Expand All @@ -25,8 +27,13 @@ create_package() {
chown -R root:root "$pdir"
chmod -R go-w "$pdir"

# Create the package
dpkg-gencontrol $forcearch -Vkernel:debarch="${debarch}" -p$pname -P"$pdir"
dpkg --build "$pdir" ..
}

set_debarch() {
# Attempt to find the correct Debian architecture
local forcearch="" debarch=""
case "$UTS_MACHINE" in
i386|ia64|alpha)
debarch="$UTS_MACHINE" ;;
Expand All @@ -45,8 +52,18 @@ create_package() {
arm64)
debarch=arm64 ;;
arm*)
debarch=arm$(grep -q CONFIG_AEABI=y $KCONFIG_CONFIG && echo el || true) ;;
if grep -q CONFIG_AEABI=y $KCONFIG_CONFIG; then
if grep -q CONFIG_VFP=y $KCONFIG_CONFIG; then
debarch=armhf
else
debarch=armel
fi
else
debarch=arm
fi
;;
*)
debarch=$(dpkg --print-architecture)
echo "" >&2
echo "** ** ** WARNING ** ** **" >&2
echo "" >&2
Expand All @@ -59,13 +76,8 @@ create_package() {
if [ -n "$KBUILD_DEBARCH" ] ; then
debarch="$KBUILD_DEBARCH"
fi
if [ -n "$debarch" ] ; then
forcearch="-DArchitecture=$debarch"
fi
forcearch="-DArchitecture=$debarch"

# Create the package
dpkg-gencontrol $forcearch -Vkernel:debarch="${debarch:-$(dpkg --print-architecture)}" -p$pname -P"$pdir"
dpkg --build "$pdir" ..
}

# Some variables and settings used throughout the script
Expand All @@ -76,6 +88,7 @@ if [ -n "$KDEB_PKGVERSION" ]; then
else
packageversion=$version-$revision
fi
sourcename=$KDEB_SOURCENAME
tmpdir="$objtree/debian/tmp"
fwdir="$objtree/debian/fwtmp"
kernel_headers_dir="$objtree/debian/hdrtmp"
Expand All @@ -86,6 +99,9 @@ fwpackagename=linux-firmware-image-$version
kernel_headers_packagename=linux-headers-$version
libc_headers_packagename=linux-libc-dev
dbg_packagename=$packagename-dbg
debarch=
forcearch=
set_debarch

if [ "$ARCH" = "um" ] ; then
packagename=user-mode-linux-$version
Expand All @@ -108,26 +124,15 @@ esac
BUILD_DEBUG="$(grep -s '^CONFIG_DEBUG_INFO=y' $KCONFIG_CONFIG || true)"

# Setup the directory structure
rm -rf "$tmpdir" "$fwdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir"
rm -rf "$tmpdir" "$fwdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" $objtree/debian/files
mkdir -m 755 -p "$tmpdir/DEBIAN"
mkdir -p "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
mkdir -m 755 -p "$fwdir/DEBIAN"
mkdir -p "$fwdir/lib/firmware/$version/" "$fwdir/usr/share/doc/$fwpackagename"
mkdir -m 755 -p "$libc_headers_dir/DEBIAN"
mkdir -p "$libc_headers_dir/usr/share/doc/$libc_headers_packagename"
mkdir -m 755 -p "$kernel_headers_dir/DEBIAN"
mkdir -p "$kernel_headers_dir/usr/share/doc/$kernel_headers_packagename"
mkdir -p "$tmpdir/lib" "$tmpdir/boot"
mkdir -p "$fwdir/lib/firmware/$version/"
mkdir -p "$kernel_headers_dir/lib/modules/$version/"
if [ "$ARCH" = "um" ] ; then
mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
fi
if [ -n "$BUILD_DEBUG" ] ; then
mkdir -p "$dbg_dir/usr/share/doc/$dbg_packagename"
mkdir -m 755 -p "$dbg_dir/DEBIAN"
fi

# Build and install the kernel
if [ "$ARCH" = "um" ] ; then
mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename"
$MAKE linux
cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config"
Expand All @@ -143,6 +148,22 @@ else
cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/$installed_image_path"
fi

if grep -q "^CONFIG_OF=y" $KCONFIG_CONFIG ; then
mkdir -p "$tmpdir/boot/dtbs/$version"
# Only some architectures with OF support have this target
if grep -q dtbs_install "${srctree}/arch/$SRCARCH/Makefile"; then
$MAKE KBUILD_SRC= INSTALL_DTBS_PATH="$tmpdir/boot/dtbs/$version" dtbs_install
else
$MAKE KBUILD_SRC= dtbs
find arch/arm/boot/ -iname "*.dtb" -exec cp -v '{}' "$tmpdir/boot/dtbs/$version" \;
fi

#make dtbs_install seems to add an .old directory
if [ -d "$tmpdir/boot/dtbs/$version.old" ] ; then
rm -rf "$tmpdir/boot/dtbs/$version.old"
fi
fi

if grep -q '^CONFIG_MODULES=y' $KCONFIG_CONFIG ; then
INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_install
rm -f "$tmpdir/lib/modules/$version/build"
Expand All @@ -162,6 +183,12 @@ if grep -q '^CONFIG_MODULES=y' $KCONFIG_CONFIG ; then
# then add a link to those
$OBJCOPY --add-gnu-debuglink=$dbg_dir/usr/lib/debug/$module $tmpdir/$module
done

# resign stripped modules
MODULE_SIG_ALL="$(grep -s '^CONFIG_MODULE_SIG_ALL=y' $KCONFIG_CONFIG || true)"
if [ -n "$MODULE_SIG_ALL" ]; then
INSTALL_MOD_PATH="$tmpdir" $MAKE KBUILD_SRC= modules_sign
fi
fi
fi

Expand Down Expand Up @@ -206,7 +233,7 @@ if [ -n "$DEBEMAIL" ]; then
elif [ -n "$EMAIL" ]; then
email=$EMAIL
else
email=$(id -nu)@$(hostname -f)
email=$(id -nu)@$(hostname -f 2>/dev/null || hostname)
fi
if [ -n "$DEBFULLNAME" ]; then
name=$DEBFULLNAME
Expand All @@ -230,7 +257,7 @@ fi

# Generate a simple changelog template
cat <<EOF > debian/changelog
linux-upstream ($packageversion) $distribution; urgency=low
$sourcename ($packageversion) $distribution; urgency=low
* Custom built Linux kernel.
Expand All @@ -257,12 +284,16 @@ On Debian GNU/Linux systems, the complete text of the GNU General Public
License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
EOF


build_depends="bc, kmod, cpio "

# Generate a control file
cat <<EOF > debian/control
Source: linux-upstream
Source: $sourcename
Section: kernel
Priority: optional
Maintainer: $maintainer
Build-Depends: $build_depends
Standards-Version: 3.8.4
Homepage: http://www.kernel.org/
EOF
Expand Down Expand Up @@ -383,4 +414,33 @@ EOF
create_package "$dbg_packagename" "$dbg_dir"
fi

if [ "x$1" = "xdeb-pkg" ]
then
cat <<EOF > debian/rules
#!/usr/bin/make -f
build:
\$(MAKE)
binary-arch:
\$(MAKE) KDEB_SOURCENAME=${sourcename} KDEB_PKGVERSION=${packageversion} bindeb-pkg
clean:
rm -rf debian/*tmp debian/files
mv debian/ debian.backup # debian/ might be cleaned away
\$(MAKE) clean
mv debian.backup debian
binary: binary-arch
EOF
mv ${sourcename}.tar.gz ../${sourcename}_${version}.orig.tar.gz
tar caf ../${sourcename}_${packageversion}.debian.tar.gz debian/{copyright,rules,changelog,control}
dpkg-source -cdebian/control -ldebian/changelog --format="3.0 (custom)" --target-format="3.0 (quilt)" \
-b / ../${sourcename}_${version}.orig.tar.gz ../${sourcename}_${packageversion}.debian.tar.gz
mv ${sourcename}_${packageversion}*dsc ..
dpkg-genchanges > ../${sourcename}_${packageversion}_${debarch}.changes
else
dpkg-genchanges -b > ../${sourcename}_${packageversion}_${debarch}.changes
fi

exit 0

0 comments on commit ff3e9a6

Please sign in to comment.