Skip to content

Instantly share code, notes, and snippets.

@stvhay
Last active December 26, 2022 13:40
Show Gist options
  • Save stvhay/581b582bc06ead5654ccb460cb21cafa to your computer and use it in GitHub Desktop.
Save stvhay/581b582bc06ead5654ccb460cb21cafa to your computer and use it in GitHub Desktop.
Build all packages (LOL)
#!/bin/bash
pkg_dir="$(pwd)/debian-packages"
mtune="cortex-a76.cortex-a55"
march="armv8.2-a+dotprod+rcpc+ssbs+sb" -mtune=cortex-a76.cortex-a55
# -march=armv8.2-a+dotprod+rcpc+ssbs+sb -mtune=cortex-a76.cortex-a55
#function get_source_packages () {
# pkg_file="$1"
# cat $pkg_file | xargs apt-cache show | grep Source: | awk '{print $2}' | sort | uniq > $pkg_file.sourcepackages
#}
# careful! must pass this function a glob pattern!
function glob_exists () {
(shopt -s nullglob dotglob; f=($1); ((${#f[@]})));
}
set_flags() {
export DEB_CFLAGS_APPEND="-march=$march -mtune=$mtune"
export DEB_CXXFLAGS_APPEND="-march=$march -mtune=$mtune"
export DEB_FCFLAGS_APPEND="-march=$march -mtune=$mtune"
export DEB_FFFLAGS_APPEND="-march=$march -mtune=$mtune"
export DEB_GCJFLAGS_APPEND="-march=$march -mtune=$mtune"
export DEB_OBJCFLAGS_APPEND="-march=$march -mtune=$mtune"
export DEB_OBJCXXFLAGS_APPEND="-march=$march -mtune=$mtune"
}
build_package() {
package="$1"
if ! glob_exists debs/"${package}_*.deb"; then
mkdir -p src/debian
pushd src/debian/ > /dev/null || exit 1
echo "Building Package: $package"
sudo apt build-dep -y "$package" > build.log 2>&1
apt-get source --compile "$package" > build.log 2>&1
rm -f *-dbgsym_*.deb
mv ./*.deb "$pkg_dir/debs" 2>/dev/null || { mv build.log "$pkg_dir/logs/${package}.build.log"; echo "Build Failed: $package"; }
rm -R -f ./*
popd > /dev/null || exit 1
else
echo "Package Exists: $package"
fi
}
pkg_file=$(pwd)/$1
sudo apt-get install -y build-essential fakeroot devscripts
mkdir -p "$pkg_dir"/{debs,logs}
#echo "Consolidating package list to source packages..."
#get_source_packages "$pkg_file" # side effect
echo "Starting Build."
pushd "$pkg_dir" || exit 1
set_flags
while read -r pkg; do
build_package "$pkg" || exit 2
done < "$pkg_file"
popd || exit 1
#rm -f "$pkg_file.sourcepackages" # clean up side effect
echo "Build complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment