Skip to content

Commit b59d444

Browse files
committed
add cross-compilation support to Makefile
Signed-off-by: Jan Noha <[email protected]>
1 parent 3847069 commit b59d444

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,18 @@ all: $(LIBRARY_RELEASE_$(OS)) libkrun.pc
100100

101101
debug: $(LIBRARY_DEBUG_$(OS)) libkrun.pc
102102

103+
ifeq ($(SYSROOT_LINUX),)
104+
# Build on Linux host
105+
CC_LINUX=$(CC)
106+
else
107+
# Cross-compile on macOS with the LLVM linker (brew install lld)
108+
CC_LINUX=clang -target aarch64-linux-gnu -fuse-ld=lld -Wl,-strip-debug --sysroot $(SYSROOT_LINUX) -Wno-c23-extensions
109+
endif
110+
103111
ifeq ($(BUILD_INIT),1)
104112
INIT_BINARY = init/init
105113
$(INIT_BINARY): $(INIT_SRC)
106-
$(CC) -O2 -static -Wall $(INIT_DEFS) -o $@ $(INIT_SRC) $(INIT_DEFS)
114+
$(CC_LINUX) -O2 -static -Wall $(INIT_DEFS) -o $@ $(INIT_SRC) $(INIT_DEFS)
107115
endif
108116

109117
$(LIBRARY_RELEASE_$(OS)): $(INIT_BINARY)

0 commit comments

Comments
 (0)