#!/bin/sh set -ef export PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 prj_dir=$(readlink -f "$(dirname "$0")/../..") cd "${prj_dir}" [ -s debian/changelog ] dpkg-parsechangelog --show-field Source | grep -Eq '^linux' ch_ver=$(dpkg-parsechangelog --show-field Version) v=$1 [ -n "$v" ] || v=$(echo "${ch_ver}" | sed -E 's/^\d+://;s/-[^-]+$//') [ -n "$v" ] ## should be source tree with patches applied src_dir=$2 [ -n "${src_dir}" ] || src_dir="/tmp/linux-$v" [ -n "${src_dir}" ] [ -d "${src_dir}" ] src_dir=$(readlink -f "${src_dir}") nproc=$(nproc || printf 2) case "${nproc}" in [0-1] ) nproc=2 ;; [2-9] | 1[0-9] ) ;; * ) nproc=20 ;; esac rm -rf debian/build/ make -f debian/rules debian/control [ -f debian/rules.gen ] configs=$(sed -En '\,debian/build/(config\.[^ :]+):$,{s,,\1,p}' debian/rules.gen | sort -uV | tr -s '[:space:]' ' ') [ -n "${configs}" ] ## produce configs make -f debian/rules.gen "-j${nproc}" $(printf ' debian/build/%s' ${configs}) ## refresh configs for c in ${configs} ; do echo "# refreshing $c" >&2 f="debian/build/$c" cp -f "$f" "${src_dir}/.config" env -C "${src_dir}" make "-j${nproc}" oldconfig cp -f "${src_dir}/.config" "$f" done ## remove build-generated options find debian/build/ -name 'config.*' -type f -exec \ sed -i -E \ -e '/CONFIG_BUILD_SALT/d' \ -e '/CONFIG_(AS|CC|PAHOLE)_((CAN|HAS)_)/d' \ -e '/CONFIG_(AS|CLANG|GCC|LD|LLD|PAHOLE)_VERSION/d' \ -e '/CONFIG_(BINDGEN|CC|RUSTC)_VERSION_TEXT/d' \ -e '/CONFIG_AS_(AVX512|GFNI|SHA(1|256)_NI|TPAUSE|VAES|VPCLMULQDQ|WRUSS)/d' \ -e '/CONFIG_CC_(IMPLICIT_FALLTHROUGH)/d' \ -e '/CONFIG_(CC|GCC10)_NO_ARRAY_BOUNDS/d' \ -e '/CONFIG_(CC|GCC)_((|NO_)STRINGOP_OVERFLOW)/d' \ {} + ## prepare configs for splitting find debian/build/ -name 'config.*' -type f -exec sed -i -En '/CONFIG_/p' {} + ( cd debian/build mkdir -p split-configs cd split-configs "${prj_dir}/../kconfigeditor2/split-common.py" $(printf ' ../%s' ${configs}) find ./ -mindepth 1 -maxdepth 1 -type f -exec sed -i -En '/CONFIG_/p' {} + cp -f output-common "${prj_dir}/debian/config/config" i=0 for c in ${configs} ; do i=$((i+1)) ## config.amd64_none_cloud -> amd64/config.cloud ## config.amd64_rt_desktop -> amd64/rt/config.desktop read -r arch featureset flavour <<-EOF $(printf '%s' "${c#config.}" | tr '_' ' ') EOF [ -n "${arch}" ] || continue [ -n "${featureset}" ] || continue [ -n "${flavour}" ] || continue case "${featureset}" in none ) o="${arch}/config.${flavour}" ;; * ) o="${arch}/${featureset}/config.${flavour}" ;; esac cp -f "output-part-$i" "${prj_dir}/debian/config/$o" done ) "${prj_dir}/../kconfigeditor2/process.py" -s "${src_dir}" .