Skip to content

Commit

Permalink
makefile: autodetect target arch for builds
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Sakhnov <mikhail@skhnv.me>
  • Loading branch information
mikhail-sakhnov committed Jan 7, 2025
1 parent 85350ad commit f0337a4
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ GOOS ?= $(shell go env GOOS)

# The target architecture for linux kernel. Possible values: amd64 or arm64.
# Any other supported by linux kernel architecture could be added by introducing new build step into neonvm/hack/kernel/Dockerfile.kernel-builder
KERNEL_TARGET_ARCH ?= amd64
TARGET_ARCH ?= amd64
UNAME_ARCH := $(shell uname -m)
ifeq ($(UNAME_ARCH),x86_64)
KERNEL_TARGET_ARCH ?= amd64
TARGET_ARCH ?= amd64
else ifeq ($(UNAME_ARCH),aarch64)
KERNEL_TARGET_ARCH ?= arm64
TARGET_ARCH ?= arm64
else
$(error Unsupported architecture: $(UNAME_ARCH))
endif

# Get the currently used golang base path
GOPATH=$(shell go env GOPATH)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
Expand Down Expand Up @@ -264,21 +273,16 @@ ifndef ignore-not-found
ignore-not-found = false
endif

# Build the kernel for the amd64 architecture. Uses generic target.
.PHONY: kernel_amd64
kernel_amd64: KERNEL_TARGET_ARCH=amd64
kernel_amd64: kernel

# Build the kernel for the arm64 architecture. Uses generic target.
.PHONY: kernel_arm64
kernel_arm64: KERNEL_TARGET_ARCH=arm64
kernel_arm64: kernel
# Build the kernel for the current architecture. Uses generic target.
.PHONY: kernel
kernel: KERNEL_TARGET_ARCH=$(TARGET_ARCH)
kernel: build_kernel

# Build the kernel for the target architecture.
# The builder image platform is not specified because the kernel is built for the target architecture using crosscompilation.
# Target is generic and can be used for any supported architecture by specifying the KERNEL_TARGET_ARCH variable.
.PHONY: kernel
kernel: ## Build linux kernel.
.PHONY: build_kernel
build_kernel: ## Build linux kernel.
rm -f neonvm-kernel/vmlinuz; \
linux_config=$$(ls neonvm-kernel/linux-config-*) \
kernel_version=$${linux_config##*-} \
Expand Down Expand Up @@ -394,12 +398,9 @@ load-example-vms: check-local-context kubectl kind k3d ## Load the testing VM im
@if [ $$($(KUBECTL) config current-context) = kind-$(CLUSTER_NAME) ]; then $(KIND) load docker-image $(E2E_TESTS_VM_IMG) --name $(CLUSTER_NAME); fi

.PHONY: example-vms
example-vms: TARGET_ARCH=$(TARGET_ARCH)
example-vms: docker-build-examples load-example-vms ## Build and push the testing VM images to the kind/k3d cluster.

.PHONY: example-vms-arm64
example-vms-arm64: TARGET_ARCH=arm64
example-vms-arm64: example-vms

.PHONY: load-pg16-disk-test
load-pg16-disk-test: check-local-context kubectl kind k3d ## Load the pg16-disk-test VM image to the kind/k3d cluster.
@if [ $$($(KUBECTL) config current-context) = k3d-$(CLUSTER_NAME) ]; then $(K3D) image import $(PG16_DISK_TEST_IMG) --cluster $(CLUSTER_NAME) --mode direct; fi
Expand Down

0 comments on commit f0337a4

Please sign in to comment.