From a9d6c0bb62450e7f1a87f25f4ad8da7642d30cd2 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sun, 25 Jan 2026 19:46:56 +0100 Subject: [PATCH] makefile: add compilation steps for host program --- wasm-base/examples/Makefile | 62 ++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/wasm-base/examples/Makefile b/wasm-base/examples/Makefile index 8598af5..50edcb9 100644 --- a/wasm-base/examples/Makefile +++ b/wasm-base/examples/Makefile @@ -1,33 +1,67 @@ -WAMRC := /opt/wamr-wamrc/wamrc -IWASM := /opt/wamr-iwasm/iwasm +# 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 -SRCS := $(wildcard *.c) -WASMS := $(SRCS:.c=.wasm) -AOTS := $(WASMS:.wasm=.aot) +# 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 -.PHONY: build-all build-wasms build-aots clean +# Files +SRCS := $(wildcard *.c) +WASMS := $(SRCS:.c=.wasm) +AOTS := $(WASMS:.wasm=.aot) +OBJS := $(SRCS:.c=.o) +DEPS := $(OBJS:.o=.d) -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)