Skip to content

Commit 42a46f9

Browse files
committed
add cross-compilation support to Makefile
Signed-off-by: Jan Noha <nohajc@gmail.com>
1 parent 2b281e8 commit 42a46f9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ ifeq ($(TIMESYNC),1)
8282
endif
8383

8484
OS = $(shell uname -s)
85+
ARCH = $(shell uname -m)
8586

8687
KRUN_BINARY_Linux = libkrun$(VARIANT).so.$(FULL_VERSION)
8788
KRUN_SONAME_Linux = libkrun$(VARIANT).so.$(ABI_VERSION)
@@ -109,10 +110,18 @@ all: $(LIBRARY_RELEASE_$(OS)) libkrun.pc
109110

110111
debug: $(LIBRARY_DEBUG_$(OS)) libkrun.pc
111112

113+
ifeq ($(SYSROOT_LINUX),)
114+
# Build on Linux host
115+
CC_LINUX=$(CC)
116+
else
117+
# Cross-compile on macOS with the LLVM linker (brew install lld)
118+
CC_LINUX=clang -target $(ARCH)-linux-gnu -fuse-ld=lld -Wl,-strip-debug --sysroot $(SYSROOT_LINUX) -Wno-c23-extensions
119+
endif
120+
112121
ifeq ($(BUILD_INIT),1)
113122
INIT_BINARY = init/init
114123
$(INIT_BINARY): $(INIT_SRC)
115-
$(CC) -O2 -static -Wall $(INIT_DEFS) -o $@ $(INIT_SRC) $(INIT_DEFS)
124+
$(CC_LINUX) -O2 -static -Wall $(INIT_DEFS) -o $@ $(INIT_SRC) $(INIT_DEFS)
116125
endif
117126

118127
NITRO_INIT_BINARY= init/nitro/init

0 commit comments

Comments
 (0)