Skip to content

Commit b2baf63

Browse files
committed
added option to cross compile
1 parent 3a9b01a commit b2baf63

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
.PHONY: build
22
build:
33
./build.sh
4+
5+
.PHONY: build-on-arm64
6+
build-on-arm64:
7+
CROSS_COMPILE_X86=1 ./build.sh

build.sh

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@
33

44
set -euo pipefail
55

6+
# Cross-compilation settings
7+
CROSS_COMPILE_X86="${CROSS_COMPILE_X86:-}"
8+
HOST_ARCH=$(uname -m)
9+
TARGET_ARCH="x86_64"
10+
CROSS_COMPILE_PREFIX="${TARGET_ARCH}-linux-gnu-"
11+
612
function install_dependencies {
713
apt update
8-
apt install -y bc flex bison gcc make libelf-dev libssl-dev squashfs-tools busybox-static tree cpio curl patch
14+
local packages="bc flex bison gcc make libelf-dev libssl-dev squashfs-tools busybox-static tree cpio curl patch git"
15+
16+
# Add cross-compilation toolchain if needed (use gcc-12 to avoid C23 issues with newer GCC)
17+
if [[ "$CROSS_COMPILE_X86" == "1" ]]; then
18+
packages="$packages gcc-12-x86-64-linux-gnu"
19+
fi
20+
21+
apt install -y $packages
922
}
1023

1124
# From above mentioned script
@@ -32,11 +45,24 @@ function build_version {
3245
cp ../configs/"${version}.config" .config
3346

3447
echo "Checking out repo for kernel at version: $version"
48+
git reset --hard
49+
git clean -fdx
3550
git checkout "$(get_tag "$version")"
3651

52+
# Clean build artifacts from previous build
53+
make mrproper || true
54+
55+
# Set up cross-compilation if needed
56+
local make_opts=""
57+
if [[ "$CROSS_COMPILE_X86" == "1" ]]; then
58+
echo "Cross-compiling for $TARGET_ARCH on $HOST_ARCH"
59+
# Use gcc-12 to avoid C23 issues with newer GCC (bool/true/false keywords)
60+
make_opts="ARCH=$TARGET_ARCH CROSS_COMPILE=$CROSS_COMPILE_PREFIX CC=${CROSS_COMPILE_PREFIX}gcc-12"
61+
fi
62+
3763
echo "Building kernel version: $version"
38-
make olddefconfig
39-
make vmlinux -j "$(nproc)"
64+
make $make_opts olddefconfig
65+
make $make_opts vmlinux -j "$(nproc)"
4066

4167
echo "Copying finished build to builds directory"
4268
mkdir -p "../builds/vmlinux-${version}"
@@ -50,8 +76,6 @@ install_dependencies
5076
[ -d linux ] || git clone --no-checkout --filter=tree:0 https://github.com/amazonlinux/linux
5177
pushd linux
5278

53-
make distclean || true
54-
5579
grep -v '^ *#' <../kernel_versions.txt | while IFS= read -r version; do
5680
build_version "$version"
5781
done

0 commit comments

Comments
 (0)