Skip to content

Commit f62c49d

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

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
@@ -73,6 +73,7 @@ ifeq ($(TIMESYNC),1)
7373
endif
7474

7575
OS = $(shell uname -s)
76+
ARCH = $(shell uname -m)
7677

7778
KRUN_BINARY_Linux = libkrun$(VARIANT).so.$(FULL_VERSION)
7879
KRUN_SONAME_Linux = libkrun$(VARIANT).so.$(ABI_VERSION)
@@ -100,10 +101,18 @@ all: $(LIBRARY_RELEASE_$(OS)) libkrun.pc
100101

101102
debug: $(LIBRARY_DEBUG_$(OS)) libkrun.pc
102103

104+
ifeq ($(SYSROOT_LINUX),)
105+
# Build on Linux host
106+
CC_LINUX=$(CC)
107+
else
108+
# Cross-compile on macOS with the LLVM linker (brew install lld)
109+
CC_LINUX=clang -target $(ARCH)-linux-gnu -fuse-ld=lld -Wl,-strip-debug --sysroot $(SYSROOT_LINUX) -Wno-c23-extensions
110+
endif
111+
103112
ifeq ($(BUILD_INIT),1)
104113
INIT_BINARY = init/init
105114
$(INIT_BINARY): $(INIT_SRC)
106-
$(CC) -O2 -static -Wall $(INIT_DEFS) -o $@ $(INIT_SRC) $(INIT_DEFS)
115+
$(CC_LINUX) -O2 -static -Wall $(INIT_DEFS) -o $@ $(INIT_SRC) $(INIT_DEFS)
107116
endif
108117

109118
$(LIBRARY_RELEASE_$(OS)): $(INIT_BINARY)

0 commit comments

Comments
 (0)