makefile: add compilation steps for host program

This commit is contained in:
2026-01-25 19:46:56 +01:00
parent 6b349d3278
commit a9d6c0bb62

View File

@ -1,33 +1,67 @@
# Paths
WAMR_ROOT := /opt/wamr
WAMRC := /opt/wamr-wamrc/wamrc
IWASM := /opt/wamr-iwasm/iwasm
WAMRC_LIB := /opt/wamr-libvmlib
IWASM_LIB := /opt/wamr-libiwasm
WASI_SDK := /opt/wasi-sdk
SYSROOT := $(WASI_SDK)/share/wasi-sysroot
CLANG := $(WASI_SDK)/bin/clang
CFLAGS := --target=wasm32-wasi \
--sysroot=$(SYSROOT) \
-O2
WASI_ROOT := /opt/wasi-sdk
WASI_CC := $(WASI_ROOT)/bin/clang
WASI_CFLAGS := --target=wasm32-wasi \
--sysroot=$(WASI_ROOT)/share/wasi-sysroot \
-O0 -g -Wall
# Embedding
EMBED_CC := gcc
EMBED_INCL := -I$(WAMR_ROOT)/core/iwasm/include \
-I$(WAMR_ROOT)/core/iwasm/common \
-I$(WAMR_ROOT)/core/shared/platform/linux \
-I$(WAMR_ROOT)/core/shared/utils \
-I$(WAMR_ROOT)/core/shared/utils/uncommon
EMBED_SOURCES := $(WAMR_ROOT)/core/shared/utils/uncommon/bh_read_file.c
EMBED_CFLAGS := -O0 -g -Wall $(EMBED_INCL) $(EMBED_SOURCES)
AOT_LDFLAGS := -Wl,-rpath,$(WAMRC_LIB)
AOT_LDLIBS := -L$(WAMRC_LIB) -lvmlib -lm
INTER_LDFLAGS := -Wl,-rpath,$(IWASM_LIB)
INTER_LDLIBS := -L$(IWASM_LIB) -liwasm -lm
# Files
SRCS := $(wildcard *.c)
WASMS := $(SRCS:.c=.wasm)
AOTS := $(WASMS:.wasm=.aot)
OBJS := $(SRCS:.c=.o)
DEPS := $(OBJS:.o=.d)
.PHONY: build-all build-wasms build-aots clean
build-all: build-wasms build-aots
.PHONY: all build-wasms build-aots clean embed_host
all: build-wasms build-aots embed_host
# Compile to wasm bytecode using wasi-sdk
build-wasms: $(WASMS)
%.wasm: %.c
$(CLANG) $(CFLAGS) $< -o $@
$(WASI_CC) $(WASI_CFLAGS) $< -o $@
# Compile ahead-of-time module using wamrc
build-aots: $(AOTS)
%.aot: %.wasm
$(WAMRC) -o $@ $<
# $(WAMRC) --enable-wasi -o $@ $<
clean:
rm -f *.wasm
rm -f *.aot
rm -f *.d
rm -f *.o
# Compile to C-embedded
# embed: $(OBJS)
# $(EMBED_CC) $(OBJS) -o embed $(AOT_LDFLAGS) $(AOT_LDLIBS)
# %.o: %.c
# $(EMBED_CC) $(EMBED_CFLAGS) -o $@ $<
embed_host:
$(EMBED_CC) $(EMBED_CFLAGS) embed/host.c -o host $(INTER_LDFLAGS) $(INTER_LDLIBS)