From 20cb961329c305ecdad3a029950db6e4c6a4bef3 Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Mon, 7 Feb 2022 01:17:52 +0100 Subject: [PATCH] example/wasm: add prebuild hello.wasm --- examples/wasm/Makefile | 2 +- examples/wasm/wasm_sample/Makefile | 31 ++++++++++++++---- examples/wasm/wasm_sample/hello_prebuild.wasm | Bin 0 -> 242 bytes 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100755 examples/wasm/wasm_sample/hello_prebuild.wasm diff --git a/examples/wasm/Makefile b/examples/wasm/Makefile index 49ec5ba448..3c3102e8e0 100644 --- a/examples/wasm/Makefile +++ b/examples/wasm/Makefile @@ -25,7 +25,7 @@ QUIET ?= 1 all: hello.wasm -hello.wasm: wasm_sample/hello.c +hello.wasm: wasm_sample/hello.c wasm_sample/Makefile make -C wasm_sample hello.wasm mv wasm_sample/hello.wasm . diff --git a/examples/wasm/wasm_sample/Makefile b/examples/wasm/wasm_sample/Makefile index 15befee6bc..824a594987 100644 --- a/examples/wasm/wasm_sample/Makefile +++ b/examples/wasm/wasm_sample/Makefile @@ -1,19 +1,24 @@ #sometimes there might not be a wasm-ld (Ubuntu:focal) #lets check if we can find a specific version -ifneq ($(shell (command -v wasm-ld)),) +#this is a kind of crazy which from +#https://www.gnu.org/software/make/manual/html_node/Call-Function.html#Call-Function +#see https://github.com/RIOT-OS/RIOT/pull/16806 and /16807 and /16776 for why +search_fn = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH))))) + +ifneq ($(call search_fn,wasm-ld),) WASM-LD ?= wasm-ld else - ifneq ($(shell (command -v wasm-ld-11)),) + ifneq ($(call search_fn,wasm-ld-11),) LLVM_VERSION := 11 else - ifneq ($(shell (command -v wasm-ld-10)),) + ifneq ($(call search_fn,wasm-ld-10),) LLVM_VERSION := 10 else - ifneq ($(shell (command -v wasm-ld-9)),) + ifneq ($(call search_fn,wasm-ld-9),) LLVM_VERSION := 9 else - ifneq ($(shell (command -v wasm-ld-8)),) + ifneq ($(call search_fn,wasm-ld-8),) LLVM_VERSION := 8 endif endif @@ -30,7 +35,10 @@ else CLANGPP ?= clang++ endif -WASM-LD ?= echo "!! NO wasm-ld(-VERSION) found !!"; false +ifeq ($(WASM-LD),) + WASM-LD ?= echo "!! NO wasm-ld(-VERSION) found !!"; false + COPY_HELLO := YES +endif LINK_FLAGS := -z stack-size=4096 \ --export main \ @@ -95,4 +103,15 @@ COMPILE_FLAGS := -Wall \ %.wat: %.wasm Makefile wasm2wat -o $@ $< +ifeq ($(COPY_HELLO),YES) +hello.wasm: hello_prebuild.wasm + @echo "!! NO wasm-ld(-VERSION) found !!" + @echo "!! copying hello_prebuild.wasm !! " + cp hello_prebuild.wasm hello.wasm +else +hello_prebuild.wasm: hello.wasm + cp hello.wasm hello_prebuild.wasm +endif + + .PHONY: FORCE diff --git a/examples/wasm/wasm_sample/hello_prebuild.wasm b/examples/wasm/wasm_sample/hello_prebuild.wasm new file mode 100755 index 0000000000000000000000000000000000000000..78a35e794eea8234f0d58f41236870c21bbd2a2a GIT binary patch literal 242 zcmXX;%}&BV7@Y6hT1Yo)BPTsAA_-4GJi0eHnHWyQwQQ$nHlvzd9* z8w1OeV;CB7)K}WD{XQLYWZ0-N!+x|q!|CtpqDj-`|HGlD^*O=TU43>py`5p=SF5!d JR%Vzb_yK${I5hwO literal 0 HcmV?d00001