Skip to content

Commit

Permalink
Makefile: support cross-compiling
Browse files Browse the repository at this point in the history
Support passing ARCH around for cross-compiling. Only tested
cross-compiling to aarch64 from x86_64.

Signed-off-by: Sergio Lopez <[email protected]>
  • Loading branch information
slp committed Sep 26, 2024
1 parent 3ee4f72 commit 92b9fe1
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,20 @@ ifeq ($(SEV),1)
KERNEL_PATCHES += $(shell find patches-sev/ -name "0*.patch" | sort)
endif

ARCH = $(shell uname -m)
HOSTARCH = $(shell uname -m)
OS = $(shell uname -s)
ifeq ($(ARCH),)
GUESTARCH := $(HOSTARCH)
STRIP := strip
else ifeq ($(ARCH),arm64)
GUESTARCH := aarch64
CC := $(CROSS_COMPILE)gcc
STRIP := $(CROSS_COMPILE)strip
else
GUESTARCH := $(ARCH)
CC := $(CROSS_COMPILE)gcc
STRIP := $(CROSS_COMPILE)strip
endif

KBUNDLE_TYPE_x86_64 = vmlinux
KBUNDLE_TYPE_aarch64 = Image
Expand Down Expand Up @@ -62,20 +74,20 @@ $(KERNEL_TARBALL):
$(KERNEL_SOURCES): $(KERNEL_TARBALL)
tar xf $(KERNEL_TARBALL)
for patch in $(KERNEL_PATCHES); do patch -p1 -d $(KERNEL_SOURCES) < "$$patch"; done
cp config-libkrunfw$(VARIANT)_$(ARCH) $(KERNEL_SOURCES)/.config
cp config-libkrunfw$(VARIANT)_$(GUESTARCH) $(KERNEL_SOURCES)/.config
cd $(KERNEL_SOURCES) ; $(MAKE) olddefconfig

$(KERNEL_BINARY_$(ARCH)): $(KERNEL_SOURCES)
$(KERNEL_BINARY_$(GUESTARCH)): $(KERNEL_SOURCES)
cd $(KERNEL_SOURCES) ; rm -f .version ; $(MAKE) $(MAKEFLAGS) $(KERNEL_FLAGS)

ifeq ($(OS),Darwin)
$(KERNEL_C_BUNDLE):
@echo "Building on macOS, using ./build_on_krunvm.sh"
./build_on_krunvm.sh
else
$(KERNEL_C_BUNDLE): $(KERNEL_BINARY_$(ARCH))
@echo "Generating $(KERNEL_C_BUNDLE) from $(KERNEL_BINARY_$(ARCH))..."
@python3 bin2cbundle.py -t $(KBUNDLE_TYPE_$(ARCH)) $(KERNEL_BINARY_$(ARCH)) kernel.c
$(KERNEL_C_BUNDLE): $(KERNEL_BINARY_$(GUESTARCH))
@echo "Generating $(KERNEL_C_BUNDLE) from $(KERNEL_BINARY_$(GUESTARCH))..."
@python3 bin2cbundle.py -t $(KBUNDLE_TYPE_$(GUESTARCH)) $(KERNEL_BINARY_$(GUESTARCH)) kernel.c
endif

ifeq ($(SEV),1)
Expand All @@ -91,7 +103,7 @@ endif
$(KRUNFW_BINARY_$(OS)): $(KERNEL_C_BUNDLE) $(QBOOT_C_BUNDLE) $(INITRD_C_BUNDLE)
$(CC) -fPIC -DABI_VERSION=$(ABI_VERSION) -shared $(SONAME_$(OS)) -o $@ $(KERNEL_C_BUNDLE) $(QBOOT_C_BUNDLE) $(INITRD_C_BUNDLE)
ifeq ($(OS),Linux)
strip $(KRUNFW_BINARY_$(OS))
$(STRIP) $(KRUNFW_BINARY_$(OS))
endif

install:
Expand Down

0 comments on commit 92b9fe1

Please sign in to comment.