# Wokwi Custom Chip Makefile # Generated by wokwi-cli # # Usage: # make - Build the chip # make clean - Remove build artifacts # make wokwi-api.h - Download the Wokwi API header # # Requirements: # - WASI-SDK (https://github.com/WebAssembly/wasi-sdk) # - Set WASI_SDK_PATH environment variable or install to ~/.wokwi/wasi-sdk # # Configuration CHIP_NAME ?= heartrate.chip SOURCES ?= main.c OUTPUT ?= $(CHIP_NAME).wasm # WASI-SDK paths WASI_SDK_PATH ?= /l/disk0/alopes/.wokwi/wasi-sdk WASI_SDK_VERSION ?= 25 # Compiler settings CC = $(WASI_SDK_PATH)/bin/clang SYSROOT = $(WASI_SDK_PATH)/share/wasi-sysroot # Compilation flags CFLAGS = --target=wasm32-wasi \ --sysroot=$(SYSROOT) \ -nostartfiles \ -I. \ -O2 LDFLAGS = -Wl,--no-entry \ -Wl,--import-memory \ -Wl,--export-table # Default target all: check-sdk wokwi-api.h $(OUTPUT) # Build the WASM file $(OUTPUT): $(SOURCES) wokwi-api.h @echo "Compiling $(CHIP_NAME)..." $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SOURCES) @echo "Success! Output: $@ ($$(du -h $@ | cut -f1))" # Check WASI-SDK is available check-sdk: @if [ ! -d "$(WASI_SDK_PATH)" ]; then \ echo "Error: WASI-SDK not found at $(WASI_SDK_PATH)"; \ echo ""; \ echo "Install WASI-SDK:"; \ echo " Option 1: Run 'wokwi-cli chip compile' once to auto-install"; \ echo " Option 2: Download from https://github.com/WebAssembly/wasi-sdk/releases"; \ echo " Option 3: Set WASI_SDK_PATH environment variable"; \ exit 1; \ fi # Download wokwi-api.h if not present wokwi-api.h: @if [ ! -f wokwi-api.h ]; then \ echo "Downloading wokwi-api.h..."; \ curl -sL "https://wokwi.com/api/chips/wokwi-api.h" -o wokwi-api.h; \ echo "Downloaded wokwi-api.h"; \ fi # Clean build artifacts clean: rm -f $(OUTPUT) # Clean everything including downloaded files distclean: clean rm -f wokwi-api.h .PHONY: all check-sdk clean distclean