github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/GNUmakefile (about)

     1  
     2  # aliases
     3  all: tinygo
     4  
     5  # Default build and source directories, as created by `make llvm-build`.
     6  LLVM_BUILDDIR ?= llvm-build
     7  LLVM_PROJECTDIR ?= llvm-project
     8  CLANG_SRC ?= $(LLVM_PROJECTDIR)/clang
     9  LLD_SRC ?= $(LLVM_PROJECTDIR)/lld
    10  
    11  # Try to autodetect LLVM build tools.
    12  # Versions are listed here in descending priority order.
    13  LLVM_VERSIONS = 17 16 15
    14  errifempty = $(if $(1),$(1),$(error $(2)))
    15  detect = $(shell which $(call errifempty,$(firstword $(foreach p,$(2),$(shell command -v $(p) 2> /dev/null && echo $(p)))),failed to locate $(1) at any of: $(2)))
    16  toolSearchPathsVersion = $(1)-$(2)
    17  ifeq ($(shell uname -s),Darwin)
    18  	# Also explicitly search Brew's copy, which is not in PATH by default.
    19  	BREW_PREFIX := $(shell brew --prefix)
    20  	toolSearchPathsVersion += $(BREW_PREFIX)/opt/llvm@$(2)/bin/$(1)-$(2) $(BREW_PREFIX)/opt/llvm@$(2)/bin/$(1)
    21  endif
    22  # First search for a custom built copy, then move on to explicitly version-tagged binaries, then just see if the tool is in path with its normal name.
    23  findLLVMTool = $(call detect,$(1),$(abspath llvm-build/bin/$(1)) $(foreach ver,$(LLVM_VERSIONS),$(call toolSearchPathsVersion,$(1),$(ver))) $(1))
    24  CLANG ?= $(call findLLVMTool,clang)
    25  LLVM_AR ?= $(call findLLVMTool,llvm-ar)
    26  LLVM_NM ?= $(call findLLVMTool,llvm-nm)
    27  
    28  # Go binary and GOROOT to select
    29  GO ?= go
    30  export GOROOT = $(shell $(GO) env GOROOT)
    31  
    32  # Flags to pass to go test.
    33  GOTESTFLAGS ?=
    34  GOTESTPKGS ?= ./builder ./cgo ./compileopts ./compiler ./interp ./transform .
    35  
    36  # tinygo binary for tests
    37  TINYGO ?= $(call detect,tinygo,tinygo $(CURDIR)/build/tinygo)
    38  
    39  # Check for ccache if the user hasn't set it to on or off.
    40  ifeq (, $(CCACHE))
    41      # Use CCACHE for LLVM if possible
    42      ifneq (, $(shell command -v ccache 2> /dev/null))
    43          CCACHE := ON
    44      else
    45          CCACHE := OFF
    46      endif
    47  endif
    48  LLVM_OPTION += '-DLLVM_CCACHE_BUILD=$(CCACHE)'
    49  
    50  # Allow enabling LLVM assertions
    51  ifeq (1, $(ASSERT))
    52      LLVM_OPTION += '-DLLVM_ENABLE_ASSERTIONS=ON'
    53  else
    54      LLVM_OPTION += '-DLLVM_ENABLE_ASSERTIONS=OFF'
    55  endif
    56  
    57  # Enable AddressSanitizer
    58  ifeq (1, $(ASAN))
    59      LLVM_OPTION += -DLLVM_USE_SANITIZER=Address
    60      CGO_LDFLAGS += -fsanitize=address
    61  endif
    62  
    63  ifeq (1, $(STATIC))
    64      # Build TinyGo as a fully statically linked binary (no dynamically loaded
    65      # libraries such as a libc). This is not supported with glibc which is used
    66      # on most major Linux distributions. However, it is supported in Alpine
    67      # Linux with musl.
    68      CGO_LDFLAGS += -static
    69      # Also set the thread stack size to 1MB. This is necessary on musl as the
    70      # default stack size is 128kB and LLVM uses more than that.
    71      # For more information, see:
    72      # https://wiki.musl-libc.org/functional-differences-from-glibc.html#Thread-stack-size
    73      CGO_LDFLAGS += -Wl,-z,stack-size=1048576
    74      # Build wasm-opt with static linking.
    75      # For details, see:
    76      # https://github.com/WebAssembly/binaryen/blob/version_102/.github/workflows/ci.yml#L181
    77      BINARYEN_OPTION += -DCMAKE_CXX_FLAGS="-static" -DCMAKE_C_FLAGS="-static"
    78  endif
    79  
    80  # Cross compiling support.
    81  ifneq ($(CROSS),)
    82      CC = $(CROSS)-gcc
    83      CXX = $(CROSS)-g++
    84      LLVM_OPTION += \
    85          -DCMAKE_C_COMPILER=$(CC) \
    86          -DCMAKE_CXX_COMPILER=$(CXX) \
    87          -DLLVM_DEFAULT_TARGET_TRIPLE=$(CROSS) \
    88          -DCROSS_TOOLCHAIN_FLAGS_NATIVE="-UCMAKE_C_COMPILER;-UCMAKE_CXX_COMPILER"
    89      ifeq ($(CROSS), arm-linux-gnueabihf)
    90          # Assume we're building on a Debian-like distro, with QEMU installed.
    91          LLVM_CONFIG_PREFIX = qemu-arm -L /usr/arm-linux-gnueabihf/
    92          # The CMAKE_SYSTEM_NAME flag triggers cross compilation mode.
    93          LLVM_OPTION += \
    94              -DCMAKE_SYSTEM_NAME=Linux \
    95              -DLLVM_TARGET_ARCH=ARM
    96          GOENVFLAGS = GOARCH=arm CC=$(CC) CXX=$(CXX) CGO_ENABLED=1
    97          BINARYEN_OPTION += -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX)
    98      else ifeq ($(CROSS), aarch64-linux-gnu)
    99          # Assume we're building on a Debian-like distro, with QEMU installed.
   100          LLVM_CONFIG_PREFIX = qemu-aarch64 -L /usr/aarch64-linux-gnu/
   101          # The CMAKE_SYSTEM_NAME flag triggers cross compilation mode.
   102          LLVM_OPTION += \
   103              -DCMAKE_SYSTEM_NAME=Linux \
   104              -DLLVM_TARGET_ARCH=AArch64
   105          GOENVFLAGS = GOARCH=arm64 CC=$(CC) CXX=$(CXX) CGO_ENABLED=1
   106          BINARYEN_OPTION += -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX)
   107      else
   108          $(error Unknown cross compilation target: $(CROSS))
   109      endif
   110  endif
   111  
   112  .PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr gen-device-rp
   113  
   114  LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendhlsl frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest
   115  
   116  ifeq ($(OS),Windows_NT)
   117      EXE = .exe
   118      START_GROUP = -Wl,--start-group
   119      END_GROUP = -Wl,--end-group
   120  
   121      # PIC needs to be disabled for libclang to work.
   122      LLVM_OPTION += -DLLVM_ENABLE_PIC=OFF
   123  
   124      CGO_CPPFLAGS += -DCINDEX_NO_EXPORTS
   125      CGO_LDFLAGS += -static -static-libgcc -static-libstdc++
   126      CGO_LDFLAGS_EXTRA += -lversion
   127  
   128      USE_SYSTEM_BINARYEN ?= 1
   129  
   130  else ifeq ($(shell uname -s),Darwin)
   131      MD5SUM ?= md5
   132  
   133      CGO_LDFLAGS += -lxar
   134  
   135      USE_SYSTEM_BINARYEN ?= 1
   136  
   137  else ifeq ($(shell uname -s),FreeBSD)
   138      MD5SUM ?= md5
   139      START_GROUP = -Wl,--start-group
   140      END_GROUP = -Wl,--end-group
   141  else
   142      START_GROUP = -Wl,--start-group
   143      END_GROUP = -Wl,--end-group
   144  endif
   145  
   146  # md5sum binary default, can be overridden by an environment variable
   147  MD5SUM ?= md5sum
   148  
   149  # Libraries that should be linked in for the statically linked Clang.
   150  CLANG_LIB_NAMES = clangAnalysis clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangExtractAPI clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangLex clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangSupport clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions
   151  CLANG_LIBS = $(START_GROUP) $(addprefix -l,$(CLANG_LIB_NAMES)) $(END_GROUP) -lstdc++
   152  
   153  # Libraries that should be linked in for the statically linked LLD.
   154  LLD_LIB_NAMES = lldCOFF lldCommon lldELF lldMachO lldMinGW lldWasm
   155  LLD_LIBS = $(START_GROUP) $(addprefix -l,$(LLD_LIB_NAMES)) $(END_GROUP)
   156  
   157  # Other libraries that are needed to link TinyGo.
   158  EXTRA_LIB_NAMES = LLVMInterpreter LLVMMCA LLVMRISCVTargetMCA LLVMX86TargetMCA
   159  
   160  # All libraries to be built and linked with the tinygo binary (lib/lib*.a).
   161  LIB_NAMES = clang $(CLANG_LIB_NAMES) $(LLD_LIB_NAMES) $(EXTRA_LIB_NAMES)
   162  
   163  # These build targets appear to be the only ones necessary to build all TinyGo
   164  # dependencies. Only building a subset significantly speeds up rebuilding LLVM.
   165  # The Makefile rules convert a name like lldELF to lib/liblldELF.a to match the
   166  # library path (for ninja).
   167  # This list also includes a few tools that are necessary as part of the full
   168  # TinyGo build.
   169  NINJA_BUILD_TARGETS = clang llvm-config llvm-ar llvm-nm $(addprefix lib/lib,$(addsuffix .a,$(LIB_NAMES)))
   170  
   171  # For static linking.
   172  ifneq ("$(wildcard $(LLVM_BUILDDIR)/bin/llvm-config*)","")
   173      CGO_CPPFLAGS+=$(shell $(LLVM_CONFIG_PREFIX) $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(LLVM_BUILDDIR))/tools/clang/include -I$(abspath $(CLANG_SRC))/include -I$(abspath $(LLD_SRC))/include
   174      CGO_CXXFLAGS=-std=c++17
   175      CGO_LDFLAGS+=-L$(abspath $(LLVM_BUILDDIR)/lib) -lclang $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_CONFIG_PREFIX) $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA)
   176  endif
   177  
   178  clean:
   179  	@rm -rf build
   180  
   181  FMT_PATHS = ./*.go builder cgo/*.go compiler interp loader src transform
   182  fmt:
   183  	@gofmt -l -w $(FMT_PATHS)
   184  fmt-check:
   185  	@unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo "  $$fn"; done; exit 1
   186  
   187  
   188  gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp
   189  ifneq ($(STM32), 0)
   190  gen-device: gen-device-stm32
   191  endif
   192  
   193  gen-device-avr:
   194  	@if [ ! -e lib/avr/README.md ]; then echo "Submodules have not been downloaded. Please download them using:\n  git submodule update --init"; exit 1; fi
   195  	$(GO) build -o ./build/gen-device-avr ./tools/gen-device-avr/
   196  	./build/gen-device-avr lib/avr/packs/atmega src/device/avr/
   197  	./build/gen-device-avr lib/avr/packs/tiny src/device/avr/
   198  	@GO111MODULE=off $(GO) fmt ./src/device/avr
   199  
   200  build/gen-device-svd: ./tools/gen-device-svd/*.go
   201  	$(GO) build -o $@ ./tools/gen-device-svd/
   202  
   203  gen-device-esp: build/gen-device-svd
   204  	./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Espressif-Community -interrupts=software lib/cmsis-svd/data/Espressif-Community/ src/device/esp/
   205  	./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Espressif -interrupts=software lib/cmsis-svd/data/Espressif/ src/device/esp/
   206  	GO111MODULE=off $(GO) fmt ./src/device/esp
   207  
   208  gen-device-nrf: build/gen-device-svd
   209  	./build/gen-device-svd -source=https://github.com/NordicSemiconductor/nrfx/tree/master/mdk lib/nrfx/mdk/ src/device/nrf/
   210  	GO111MODULE=off $(GO) fmt ./src/device/nrf
   211  
   212  gen-device-nxp: build/gen-device-svd
   213  	./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/NXP lib/cmsis-svd/data/NXP/ src/device/nxp/
   214  	GO111MODULE=off $(GO) fmt ./src/device/nxp
   215  
   216  gen-device-sam: build/gen-device-svd
   217  	./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Atmel lib/cmsis-svd/data/Atmel/ src/device/sam/
   218  	GO111MODULE=off $(GO) fmt ./src/device/sam
   219  
   220  gen-device-sifive: build/gen-device-svd
   221  	./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/SiFive-Community -interrupts=software lib/cmsis-svd/data/SiFive-Community/ src/device/sifive/
   222  	GO111MODULE=off $(GO) fmt ./src/device/sifive
   223  
   224  gen-device-kendryte: build/gen-device-svd
   225  	./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Kendryte-Community -interrupts=software lib/cmsis-svd/data/Kendryte-Community/ src/device/kendryte/
   226  	GO111MODULE=off $(GO) fmt ./src/device/kendryte
   227  
   228  gen-device-stm32: build/gen-device-svd
   229  	./build/gen-device-svd -source=https://github.com/tinygo-org/stm32-svd lib/stm32-svd/svd src/device/stm32/
   230  	GO111MODULE=off $(GO) fmt ./src/device/stm32
   231  
   232  gen-device-rp: build/gen-device-svd
   233  	./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/RaspberryPi lib/cmsis-svd/data/RaspberryPi/ src/device/rp/
   234  	GO111MODULE=off $(GO) fmt ./src/device/rp
   235  
   236  gen-device-renesas: build/gen-device-svd
   237  	./build/gen-device-svd -source=https://github.com/tinygo-org/renesas-svd lib/renesas-svd/ src/device/renesas/
   238  	GO111MODULE=off $(GO) fmt ./src/device/renesas
   239  
   240  # Get LLVM sources.
   241  $(LLVM_PROJECTDIR)/llvm:
   242  	git clone -b xtensa_release_17.0.1 --depth=1 https://github.com/espressif/llvm-project $(LLVM_PROJECTDIR)
   243  llvm-source: $(LLVM_PROJECTDIR)/llvm
   244  
   245  # Configure LLVM.
   246  TINYGO_SOURCE_DIR=$(shell pwd)
   247  $(LLVM_BUILDDIR)/build.ninja:
   248  	mkdir -p $(LLVM_BUILDDIR) && cd $(LLVM_BUILDDIR) && cmake -G Ninja $(TINYGO_SOURCE_DIR)/$(LLVM_PROJECTDIR)/llvm "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;RISCV;WebAssembly" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR;Xtensa" -DCMAKE_BUILD_TYPE=Release -DLIBCLANG_BUILD_STATIC=ON -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_LIBEDIT=OFF -DLLVM_ENABLE_Z3_SOLVER=OFF -DLLVM_ENABLE_OCAMLDOC=OFF -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DCLANG_ENABLE_ARCMT=OFF $(LLVM_OPTION)
   249  
   250  # Build LLVM.
   251  $(LLVM_BUILDDIR): $(LLVM_BUILDDIR)/build.ninja
   252  	cd $(LLVM_BUILDDIR) && ninja $(NINJA_BUILD_TARGETS)
   253  
   254  ifneq ($(USE_SYSTEM_BINARYEN),1)
   255  # Build Binaryen
   256  .PHONY: binaryen
   257  binaryen: build/wasm-opt$(EXE)
   258  build/wasm-opt$(EXE):
   259  	mkdir -p build
   260  	cd lib/binaryen && cmake -G Ninja . -DBUILD_STATIC_LIB=ON -DBUILD_TESTS=OFF $(BINARYEN_OPTION) && ninja bin/wasm-opt$(EXE)
   261  	cp lib/binaryen/bin/wasm-opt$(EXE) build/wasm-opt$(EXE)
   262  endif
   263  
   264  # Build wasi-libc sysroot
   265  .PHONY: wasi-libc
   266  wasi-libc: lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a
   267  lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a:
   268  	@if [ ! -e lib/wasi-libc/Makefile ]; then echo "Submodules have not been downloaded. Please download them using:\n  git submodule update --init"; exit 1; fi
   269  	cd lib/wasi-libc && $(MAKE) -j4 EXTRA_CFLAGS="-O2 -g -DNDEBUG -mnontrapping-fptoint -msign-ext" MALLOC_IMPL=none CC="$(CLANG)" AR=$(LLVM_AR) NM=$(LLVM_NM)
   270  
   271  # Check for Node.js used during WASM tests.
   272  NODEJS_VERSION := $(word 1,$(subst ., ,$(shell node -v | cut -c 2-)))
   273  MIN_NODEJS_VERSION=18
   274  
   275  .PHONY: check-nodejs-version
   276  check-nodejs-version:
   277  ifeq (, $(shell which node))
   278  	@echo "Install NodeJS version 18+ to run tests."; exit 1;
   279  endif
   280  	@if [ $(NODEJS_VERSION) -lt $(MIN_NODEJS_VERSION) ]; then echo "Install NodeJS version 18+ to run tests."; exit 1; fi
   281  
   282  # Build the Go compiler.
   283  tinygo:
   284  	@if [ ! -f "$(LLVM_BUILDDIR)/bin/llvm-config" ]; then echo "Fetch and build LLVM first by running:"; echo "  $(MAKE) llvm-source"; echo "  $(MAKE) $(LLVM_BUILDDIR)"; exit 1; fi
   285  	CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GOENVFLAGS) $(GO) build -buildmode exe -o build/tinygo$(EXE) -tags "byollvm osusergo" -ldflags="-X github.com/tinygo-org/tinygo/goenv.GitSha1=`git rev-parse --short HEAD`" .
   286  test: wasi-libc check-nodejs-version
   287  	CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=20m -buildmode exe -tags "byollvm osusergo" $(GOTESTPKGS)
   288  
   289  # Standard library packages that pass tests on darwin, linux, wasi, and windows, but take over a minute in wasi
   290  TEST_PACKAGES_SLOW = \
   291  	compress/bzip2 \
   292  	crypto/dsa \
   293  	index/suffixarray \
   294  
   295  # Standard library packages that pass tests quickly on darwin, linux, wasi, and windows
   296  TEST_PACKAGES_FAST = \
   297  	compress/lzw \
   298  	compress/zlib \
   299  	container/heap \
   300  	container/list \
   301  	container/ring \
   302  	crypto/des \
   303  	crypto/md5 \
   304  	crypto/rc4 \
   305  	crypto/sha1 \
   306  	crypto/sha256 \
   307  	crypto/sha512 \
   308  	debug/macho \
   309  	embed/internal/embedtest \
   310  	encoding \
   311  	encoding/ascii85 \
   312  	encoding/base32 \
   313  	encoding/base64 \
   314  	encoding/csv \
   315  	encoding/hex \
   316  	go/scanner \
   317  	hash \
   318  	hash/adler32 \
   319  	hash/crc64 \
   320  	hash/fnv \
   321  	html \
   322  	internal/itoa \
   323  	internal/profile \
   324  	math \
   325  	math/cmplx \
   326  	net/http/internal/ascii \
   327  	net/mail \
   328  	os \
   329  	path \
   330  	reflect \
   331  	sync \
   332  	testing \
   333  	testing/iotest \
   334  	text/scanner \
   335  	unicode \
   336  	unicode/utf16 \
   337  	unicode/utf8 \
   338  	$(nil)
   339  
   340  # Assume this will go away before Go2, so only check minor version.
   341  ifeq ($(filter $(shell $(GO) env GOVERSION | cut -f 2 -d.), 16 17 18), )
   342  TEST_PACKAGES_FAST += crypto/internal/nistec/fiat
   343  else
   344  TEST_PACKAGES_FAST += crypto/elliptic/internal/fiat
   345  endif
   346  
   347  # archive/zip requires os.ReadAt, which is not yet supported on windows
   348  # bytes requires mmap
   349  # compress/flate appears to hang on wasi
   350  # crypto/hmac fails on wasi, it exits with a "slice out of range" panic
   351  # debug/plan9obj requires os.ReadAt, which is not yet supported on windows
   352  # image requires recover(), which is not  yet supported on wasi
   353  # io/ioutil requires os.ReadDir, which is not yet supported on windows or wasi
   354  # mime/quotedprintable requires syscall.Faccessat
   355  # strconv requires recover() which is not yet supported on wasi
   356  # text/tabwriter requries recover(), which is not  yet supported on wasi
   357  # text/template/parse requires recover(), which is not yet supported on wasi
   358  # testing/fstest requires os.ReadDir, which is not yet supported on windows or wasi
   359  
   360  # Additional standard library packages that pass tests on individual platforms
   361  TEST_PACKAGES_LINUX := \
   362  	archive/zip \
   363  	bytes \
   364  	compress/flate \
   365  	crypto/hmac \
   366  	debug/dwarf \
   367  	debug/plan9obj \
   368  	image \
   369  	io/ioutil \
   370  	mime/quotedprintable \
   371  	net \
   372  	strconv \
   373  	testing/fstest \
   374  	text/tabwriter \
   375  	text/template/parse
   376  
   377  TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX)
   378  
   379  TEST_PACKAGES_WINDOWS := \
   380  	compress/flate \
   381  	crypto/hmac \
   382  	strconv \
   383  	text/template/parse \
   384  	$(nil)
   385  
   386  # Report platforms on which each standard library package is known to pass tests
   387  jointmp := $(shell echo /tmp/join.$$$$)
   388  report-stdlib-tests-pass:
   389  	@for t in $(TEST_PACKAGES_DARWIN); do echo "$$t darwin"; done | sort > $(jointmp).darwin
   390  	@for t in $(TEST_PACKAGES_LINUX); do echo "$$t linux"; done | sort > $(jointmp).linux
   391  	@for t in $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW); do echo "$$t darwin linux wasi windows"; done | sort > $(jointmp).portable
   392  	@join -a1 -a2 $(jointmp).darwin $(jointmp).linux | \
   393  	join -a1 -a2 - $(jointmp).portable
   394  	@rm $(jointmp).*
   395  
   396  # Standard library packages that pass tests quickly on the current platform
   397  ifeq ($(shell uname),Darwin)
   398  TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_DARWIN)
   399  TEST_IOFS := true
   400  endif
   401  ifeq ($(shell uname),Linux)
   402  TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_LINUX)
   403  TEST_IOFS := true
   404  endif
   405  ifeq ($(OS),Windows_NT)
   406  TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_WINDOWS)
   407  TEST_IOFS := false
   408  endif
   409  
   410  # Test known-working standard library packages.
   411  # TODO: parallelize, and only show failing tests (no implied -v flag).
   412  .PHONY: tinygo-test
   413  tinygo-test:
   414  	$(TINYGO) test $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW)
   415  	@# io/fs requires os.ReadDir, not yet supported on windows or wasi. It also
   416  	@# requires a large stack-size. Hence, io/fs is only run conditionally.
   417  	@# For more details, see the comments on issue #3143.
   418  ifeq ($(TEST_IOFS),true)
   419  	$(TINYGO) test -stack-size=6MB io/fs
   420  endif
   421  tinygo-test-fast:
   422  	$(TINYGO) test $(TEST_PACKAGES_HOST)
   423  tinygo-bench:
   424  	$(TINYGO) test -bench . $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW)
   425  tinygo-bench-fast:
   426  	$(TINYGO) test -bench . $(TEST_PACKAGES_HOST)
   427  
   428  # Same thing, except for wasi rather than the current platform.
   429  tinygo-test-wasi:
   430  	$(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
   431  tinygo-test-wasip1:
   432  	GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
   433  tinygo-test-wasi-fast:
   434  	$(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
   435  tinygo-test-wasip1-fast:
   436  	GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
   437  tinygo-bench-wasi:
   438  	$(TINYGO) test -target wasip1 -bench . $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW)
   439  tinygo-bench-wasi-fast:
   440  	$(TINYGO) test -target wasip1 -bench . $(TEST_PACKAGES_FAST)
   441  
   442  # Test external packages in a large corpus.
   443  test-corpus:
   444  	CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml
   445  test-corpus-fast:
   446  	CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus -short . -corpus=testdata/corpus.yaml
   447  test-corpus-wasi: wasi-libc
   448  	CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasip1
   449  
   450  tinygo-baremetal:
   451  	# Regression tests that run on a baremetal target and don't fit in either main_test.go or smoketest.
   452  	# regression test for #2666: e.g. encoding/hex must pass on baremetal
   453  	$(TINYGO) test -target cortex-m-qemu encoding/hex
   454  
   455  .PHONY: smoketest
   456  smoketest:
   457  	$(TINYGO) version
   458  	$(TINYGO) targets > /dev/null
   459  	# regression test for #2892
   460  	cd tests/testing/recurse && ($(TINYGO) test ./... > recurse.log && cat recurse.log && test $$(wc -l < recurse.log) = 2 && rm recurse.log)
   461  	# compile-only platform-independent examples
   462  	cd tests/text/template/smoke && $(TINYGO) test -c && rm -f smoke.test
   463  	# regression test for #2563
   464  	cd tests/os/smoke && $(TINYGO) test -c -target=pybadge && rm smoke.test
   465  	# test all examples (except pwm)
   466  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/blinky1
   467  	@$(MD5SUM) test.hex
   468  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/adc
   469  	@$(MD5SUM) test.hex
   470  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/blinkm
   471  	@$(MD5SUM) test.hex
   472  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/blinky2
   473  	@$(MD5SUM) test.hex
   474  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/button
   475  	@$(MD5SUM) test.hex
   476  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/button2
   477  	@$(MD5SUM) test.hex
   478  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/echo
   479  	@$(MD5SUM) test.hex
   480  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/echo2
   481  	@$(MD5SUM) test.hex
   482  	$(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/i2s
   483  	@$(MD5SUM) test.hex
   484  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/mcp3008
   485  	@$(MD5SUM) test.hex
   486  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/memstats
   487  	@$(MD5SUM) test.hex
   488  	$(TINYGO) build -size short -o test.hex -target=microbit            examples/microbit-blink
   489  	@$(MD5SUM) test.hex
   490  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/pininterrupt
   491  	@$(MD5SUM) test.hex
   492  	$(TINYGO) build -size short -o test.hex -target=nano-rp2040         examples/rtcinterrupt
   493  	@$(MD5SUM) test.hex
   494  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/serial
   495  	@$(MD5SUM) test.hex
   496  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/systick
   497  	@$(MD5SUM) test.hex
   498  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/test
   499  	@$(MD5SUM) test.hex
   500  	$(TINYGO) build -size short -o test.hex -target=pca10040            examples/time-offset
   501  	@$(MD5SUM) test.hex
   502  	$(TINYGO) build -size short -o test.hex -target=wioterminal         examples/hid-mouse
   503  	@$(MD5SUM) test.hex
   504  	$(TINYGO) build -size short -o test.hex -target=wioterminal         examples/hid-keyboard
   505  	@$(MD5SUM) test.hex
   506  	$(TINYGO) build -size short -o test.hex -target=feather-rp2040      examples/i2c-target
   507  	@$(MD5SUM) test.hex
   508  	$(TINYGO) build -size short -o test.hex -target=feather-rp2040      examples/watchdog
   509  	@$(MD5SUM) test.hex
   510  	$(TINYGO) build -size short -o test.hex -target=feather-rp2040      examples/device-id
   511  	@$(MD5SUM) test.hex
   512  	# test simulated boards on play.tinygo.org
   513  ifneq ($(WASM), 0)
   514  	$(TINYGO) build -size short -o test.wasm -tags=arduino              examples/blinky1
   515  	@$(MD5SUM) test.wasm
   516  	$(TINYGO) build -size short -o test.wasm -tags=hifive1b             examples/blinky1
   517  	@$(MD5SUM) test.wasm
   518  	$(TINYGO) build -size short -o test.wasm -tags=reelboard            examples/blinky1
   519  	@$(MD5SUM) test.wasm
   520  	$(TINYGO) build -size short -o test.wasm -tags=microbit             examples/microbit-blink
   521  	@$(MD5SUM) test.wasm
   522  	$(TINYGO) build -size short -o test.wasm -tags=circuitplay_express  examples/blinky1
   523  	@$(MD5SUM) test.wasm
   524  	$(TINYGO) build -size short -o test.wasm -tags=circuitplay_bluefruit examples/blinky1
   525  	@$(MD5SUM) test.wasm
   526  	$(TINYGO) build -size short -o test.wasm -tags=mch2022              examples/serial
   527  	@$(MD5SUM) test.wasm
   528  	$(TINYGO) build -size short -o test.wasm -tags=gopher_badge         examples/blinky1
   529  	@$(MD5SUM) test.wasm
   530  endif
   531  	# test all targets/boards
   532  	$(TINYGO) build -size short -o test.hex -target=pca10040-s132v6     examples/blinky1
   533  	@$(MD5SUM) test.hex
   534  	$(TINYGO) build -size short -o test.hex -target=microbit            examples/echo
   535  	@$(MD5SUM) test.hex
   536  	$(TINYGO) build -size short -o test.hex -target=microbit-s110v8     examples/echo
   537  	@$(MD5SUM) test.hex
   538  	$(TINYGO) build -size short -o test.hex -target=microbit-v2         examples/microbit-blink
   539  	@$(MD5SUM) test.hex
   540  	$(TINYGO) build -size short -o test.hex -target=microbit-v2-s113v7  examples/microbit-blink
   541  	@$(MD5SUM) test.hex
   542  	$(TINYGO) build -size short -o test.hex -target=nrf52840-mdk        examples/blinky1
   543  	@$(MD5SUM) test.hex
   544  	$(TINYGO) build -size short -o test.hex -target=pca10031            examples/blinky1
   545  	@$(MD5SUM) test.hex
   546  	$(TINYGO) build -size short -o test.hex -target=reelboard           examples/blinky1
   547  	@$(MD5SUM) test.hex
   548  	$(TINYGO) build -size short -o test.hex -target=reelboard           examples/blinky2
   549  	@$(MD5SUM) test.hex
   550  	$(TINYGO) build -size short -o test.hex -target=pca10056            examples/blinky1
   551  	@$(MD5SUM) test.hex
   552  	$(TINYGO) build -size short -o test.hex -target=pca10056            examples/blinky2
   553  	@$(MD5SUM) test.hex
   554  	$(TINYGO) build -size short -o test.hex -target=pca10059            examples/blinky1
   555  	@$(MD5SUM) test.hex
   556  	$(TINYGO) build -size short -o test.hex -target=pca10059            examples/blinky2
   557  	@$(MD5SUM) test.hex
   558  	$(TINYGO) build -size short -o test.hex -target=bluemicro840        examples/blinky2
   559  	@$(MD5SUM) test.hex
   560  	$(TINYGO) build -size short -o test.hex -target=itsybitsy-m0        examples/blinky1
   561  	@$(MD5SUM) test.hex
   562  	$(TINYGO) build -size short -o test.hex -target=feather-m0          examples/blinky1
   563  	@$(MD5SUM) test.hex
   564  	$(TINYGO) build -size short -o test.hex -target=trinket-m0          examples/blinky1
   565  	@$(MD5SUM) test.hex
   566  	$(TINYGO) build -size short -o test.hex -target=gemma-m0            examples/blinky1
   567  	@$(MD5SUM) test.hex
   568  	$(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/blinky1
   569  	@$(MD5SUM) test.hex
   570  	$(TINYGO) build -size short -o test.hex -target=circuitplay-bluefruit examples/blinky1
   571  	@$(MD5SUM) test.hex
   572  	$(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/i2s
   573  	@$(MD5SUM) test.hex
   574  	$(TINYGO) build -size short -o test.hex -target=clue-alpha          examples/blinky1
   575  	@$(MD5SUM) test.hex
   576  	$(TINYGO) build -size short -o test.gba -target=gameboy-advance     examples/gba-display
   577  	@$(MD5SUM) test.gba
   578  	$(TINYGO) build -size short -o test.hex -target=grandcentral-m4     examples/blinky1
   579  	@$(MD5SUM) test.hex
   580  	$(TINYGO) build -size short -o test.hex -target=itsybitsy-m4        examples/blinky1
   581  	@$(MD5SUM) test.hex
   582  	$(TINYGO) build -size short -o test.hex -target=feather-m4          examples/blinky1
   583  	@$(MD5SUM) test.hex
   584  	$(TINYGO) build -size short -o test.hex -target=matrixportal-m4     examples/blinky1
   585  	@$(MD5SUM) test.hex
   586  	$(TINYGO) build -size short -o test.hex -target=pybadge             examples/blinky1
   587  	@$(MD5SUM) test.hex
   588  	$(TINYGO) build -size short -o test.hex -target=metro-m4-airlift    examples/blinky1
   589  	@$(MD5SUM) test.hex
   590  	$(TINYGO) build -size short -o test.hex -target=pyportal            examples/blinky1
   591  	@$(MD5SUM) test.hex
   592  	$(TINYGO) build -size short -o test.hex -target=particle-argon      examples/blinky1
   593  	@$(MD5SUM) test.hex
   594  	$(TINYGO) build -size short -o test.hex -target=particle-boron      examples/blinky1
   595  	@$(MD5SUM) test.hex
   596  	$(TINYGO) build -size short -o test.hex -target=particle-xenon      examples/blinky1
   597  	@$(MD5SUM) test.hex
   598  	$(TINYGO) build -size short -o test.hex -target=pinetime            examples/blinky1
   599  	@$(MD5SUM) test.hex
   600  	$(TINYGO) build -size short -o test.hex -target=x9pro               examples/blinky1
   601  	@$(MD5SUM) test.hex
   602  	$(TINYGO) build -size short -o test.hex -target=pca10056-s140v7     examples/blinky1
   603  	@$(MD5SUM) test.hex
   604  	$(TINYGO) build -size short -o test.hex -target=pca10059-s140v7     examples/blinky1
   605  	@$(MD5SUM) test.hex
   606  	$(TINYGO) build -size short -o test.hex -target=reelboard-s140v7    examples/blinky1
   607  	@$(MD5SUM) test.hex
   608  	$(TINYGO) build -size short -o test.hex -target=wioterminal         examples/blinky1
   609  	@$(MD5SUM) test.hex
   610  	$(TINYGO) build -size short -o test.hex -target=pygamer             examples/blinky1
   611  	@$(MD5SUM) test.hex
   612  	$(TINYGO) build -size short -o test.hex -target=xiao                examples/blinky1
   613  	@$(MD5SUM) test.hex
   614  	$(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/dac
   615  	@$(MD5SUM) test.hex
   616  	$(TINYGO) build -size short -o test.hex -target=pyportal            examples/dac
   617  	@$(MD5SUM) test.hex
   618  	$(TINYGO) build -size short -o test.hex -target=feather-nrf52840  	examples/blinky1
   619  	@$(MD5SUM) test.hex
   620  	$(TINYGO) build -size short -o test.hex -target=feather-nrf52840-sense examples/blinky1
   621  	@$(MD5SUM) test.hex
   622  	$(TINYGO) build -size short -o test.hex -target=itsybitsy-nrf52840  examples/blinky1
   623  	@$(MD5SUM) test.hex
   624  	$(TINYGO) build -size short -o test.hex -target=qtpy                examples/serial
   625  	@$(MD5SUM) test.hex
   626  	$(TINYGO) build -size short -o test.hex -target=teensy41            examples/blinky1
   627  	@$(MD5SUM) test.hex
   628  	$(TINYGO) build -size short -o test.hex -target=teensy40            examples/blinky1
   629  	@$(MD5SUM) test.hex
   630  	$(TINYGO) build -size short -o test.hex -target=teensy36            examples/blinky1
   631  	@$(MD5SUM) test.hex
   632  	$(TINYGO) build -size short -o test.hex -target=p1am-100            examples/blinky1
   633  	@$(MD5SUM) test.hex
   634  	$(TINYGO) build -size short -o test.hex -target=atsame54-xpro       examples/blinky1
   635  	@$(MD5SUM) test.hex
   636  	$(TINYGO) build -size short -o test.hex -target=atsame54-xpro       examples/can
   637  	@$(MD5SUM) test.hex
   638  	$(TINYGO) build -size short -o test.hex -target=feather-m4-can      examples/blinky1
   639  	@$(MD5SUM) test.hex
   640  	$(TINYGO) build -size short -o test.hex -target=feather-m4-can      examples/caninterrupt
   641  	@$(MD5SUM) test.hex
   642  	$(TINYGO) build -size short -o test.hex -target=arduino-nano33      examples/blinky1
   643  	@$(MD5SUM) test.hex
   644  	$(TINYGO) build -size short -o test.hex -target=arduino-mkrwifi1010 examples/blinky1
   645  	@$(MD5SUM) test.hex
   646  	$(TINYGO) build -size short -o test.hex -target=pico                examples/blinky1
   647  	@$(MD5SUM) test.hex
   648  	$(TINYGO) build -size short -o test.hex -target=nano-33-ble         examples/blinky1
   649  	@$(MD5SUM) test.hex
   650  	$(TINYGO) build -size short -o test.hex -target=nano-rp2040         examples/blinky1
   651  	@$(MD5SUM) test.hex
   652  	$(TINYGO) build -size short -o test.hex -target=feather-rp2040 		examples/blinky1
   653  	@$(MD5SUM) test.hex
   654  	$(TINYGO) build -size short -o test.hex -target=qtpy-rp2040         examples/echo
   655  	@$(MD5SUM) test.hex
   656  	$(TINYGO) build -size short -o test.hex -target=kb2040              examples/echo
   657  	@$(MD5SUM) test.hex
   658  	$(TINYGO) build -size short -o test.hex -target=macropad-rp2040 	examples/blinky1
   659  	@$(MD5SUM) test.hex
   660  	$(TINYGO) build -size short -o test.hex -target=badger2040          examples/blinky1
   661  	@$(MD5SUM) test.hex
   662  	$(TINYGO) build -size short -o test.hex -target=tufty2040           examples/blinky1
   663  	@$(MD5SUM) test.hex
   664  	$(TINYGO) build -size short -o test.hex -target=thingplus-rp2040    examples/blinky1
   665  	@$(MD5SUM) test.hex
   666  	$(TINYGO) build -size short -o test.hex -target=xiao-rp2040         examples/blinky1
   667  	@$(MD5SUM) test.hex
   668  	$(TINYGO) build -size short -o test.hex -target=waveshare-rp2040-zero examples/echo
   669  	@$(MD5SUM) test.hex
   670  	$(TINYGO) build -size short -o test.hex -target=challenger-rp2040    examples/blinky1
   671  	@$(MD5SUM) test.hex
   672  	$(TINYGO) build -size short -o test.hex -target=trinkey-qt2040      examples/temp
   673  	@$(MD5SUM) test.hex
   674  	$(TINYGO) build -size short -o test.hex -target=gopher-badge      examples/blinky1
   675  	@$(MD5SUM) test.hex
   676  	$(TINYGO) build -size short -o test.hex -target=ae-rp2040           examples/echo
   677  	@$(MD5SUM) test.hex
   678  	$(TINYGO) build -size short -o test.hex -target=thumby              examples/echo
   679  	@$(MD5SUM) test.hex
   680  	# test pwm
   681  	$(TINYGO) build -size short -o test.hex -target=itsybitsy-m0        examples/pwm
   682  	@$(MD5SUM) test.hex
   683  	$(TINYGO) build -size short -o test.hex -target=itsybitsy-m4        examples/pwm
   684  	@$(MD5SUM) test.hex
   685  	$(TINYGO) build -size short -o test.hex -target=feather-m4          examples/pwm
   686  	@$(MD5SUM) test.hex
   687  	# test usb
   688  	$(TINYGO) build -size short -o test.hex -target=feather-nrf52840    examples/hid-keyboard
   689  	@$(MD5SUM) test.hex
   690  	$(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/hid-keyboard
   691  	@$(MD5SUM) test.hex
   692  	$(TINYGO) build -size short -o test.hex -target=feather-nrf52840    examples/usb-midi
   693  	@$(MD5SUM) test.hex
   694  	$(TINYGO) build -size short -o test.hex -target=nrf52840-s140v6-uf2-generic	examples/serial
   695  	@$(MD5SUM) test.hex
   696  ifneq ($(STM32), 0)
   697  	$(TINYGO) build -size short -o test.hex -target=bluepill            examples/blinky1
   698  	@$(MD5SUM) test.hex
   699  	$(TINYGO) build -size short -o test.hex -target=feather-stm32f405   examples/blinky1
   700  	@$(MD5SUM) test.hex
   701  	$(TINYGO) build -size short -o test.hex -target=lgt92               examples/blinky1
   702  	@$(MD5SUM) test.hex
   703  	$(TINYGO) build -size short -o test.hex -target=nucleo-f103rb       examples/blinky1
   704  	@$(MD5SUM) test.hex
   705  	$(TINYGO) build -size short -o test.hex -target=nucleo-f722ze       examples/blinky1
   706  	@$(MD5SUM) test.hex
   707  	$(TINYGO) build -size short -o test.hex -target=nucleo-l031k6       examples/blinky1
   708  	@$(MD5SUM) test.hex
   709  	$(TINYGO) build -size short -o test.hex -target=nucleo-l432kc       examples/blinky1
   710  	@$(MD5SUM) test.hex
   711  	$(TINYGO) build -size short -o test.hex -target=nucleo-l552ze       examples/blinky1
   712  	@$(MD5SUM) test.hex
   713  	$(TINYGO) build -size short -o test.hex -target=nucleo-wl55jc       examples/blinky1
   714  	@$(MD5SUM) test.hex
   715  	$(TINYGO) build -size short -o test.hex -target=stm32f4disco        examples/blinky1
   716  	@$(MD5SUM) test.hex
   717  	$(TINYGO) build -size short -o test.hex -target=stm32f4disco        examples/blinky2
   718  	@$(MD5SUM) test.hex
   719  	$(TINYGO) build -size short -o test.hex -target=stm32f4disco-1      examples/blinky1
   720  	@$(MD5SUM) test.hex
   721  	$(TINYGO) build -size short -o test.hex -target=stm32f4disco-1      examples/pwm
   722  	@$(MD5SUM) test.hex
   723  	$(TINYGO) build -size short -o test.hex -target=stm32f469disco      examples/blinky1
   724  	@$(MD5SUM) test.hex
   725  	$(TINYGO) build -size short -o test.hex -target=lorae5              examples/blinky1
   726  	@$(MD5SUM) test.hex
   727  	$(TINYGO) build -size short -o test.hex -target=swan                examples/blinky1
   728  	@$(MD5SUM) test.hex
   729  	$(TINYGO) build -size short -o test.hex -target=mksnanov3           examples/blinky1
   730  	@$(MD5SUM) test.hex
   731  endif
   732  	$(TINYGO) build -size short -o test.hex -target=atmega328pb         examples/blinkm
   733  	@$(MD5SUM) test.hex
   734  	$(TINYGO) build -size short -o test.hex -target=atmega1284p         examples/serial
   735  	@$(MD5SUM) test.hex
   736  	$(TINYGO) build -size short -o test.hex -target=arduino             examples/blinky1
   737  	@$(MD5SUM) test.hex
   738  	$(TINYGO) build -size short -o test.hex -target=arduino-leonardo    examples/blinky1
   739  	@$(MD5SUM) test.hex
   740  	$(TINYGO) build -size short -o test.hex -target=arduino             examples/pwm
   741  	@$(MD5SUM) test.hex
   742  	$(TINYGO) build -size short -o test.hex -target=arduino -scheduler=tasks  examples/blinky1
   743  	@$(MD5SUM) test.hex
   744  	$(TINYGO) build -size short -o test.hex -target=arduino-mega1280    examples/blinky1
   745  	@$(MD5SUM) test.hex
   746  	$(TINYGO) build -size short -o test.hex -target=arduino-mega1280    examples/pwm
   747  	@$(MD5SUM) test.hex
   748  	$(TINYGO) build -size short -o test.hex -target=arduino-nano        examples/blinky1
   749  	@$(MD5SUM) test.hex
   750  	$(TINYGO) build -size short -o test.hex -target=attiny1616          examples/empty
   751  	@$(MD5SUM) test.hex
   752  	$(TINYGO) build -size short -o test.hex -target=digispark           examples/blinky1
   753  	@$(MD5SUM) test.hex
   754  	$(TINYGO) build -size short -o test.hex -target=digispark -gc=leaking examples/blinky1
   755  	@$(MD5SUM) test.hex
   756  ifneq ($(XTENSA), 0)
   757  	$(TINYGO) build -size short -o test.bin -target=esp32-mini32      	examples/blinky1
   758  	@$(MD5SUM) test.bin
   759  	$(TINYGO) build -size short -o test.bin -target=nodemcu             examples/blinky1
   760  	@$(MD5SUM) test.bin
   761  	$(TINYGO) build -size short -o test.bin -target m5stack-core2       examples/serial
   762  	@$(MD5SUM) test.bin
   763  	$(TINYGO) build -size short -o test.bin -target m5stack             examples/serial
   764  	@$(MD5SUM) test.bin
   765  	$(TINYGO) build -size short -o test.bin -target m5stick-c           examples/serial
   766  	@$(MD5SUM) test.bin
   767  	$(TINYGO) build -size short -o test.bin -target mch2022             examples/serial
   768  	@$(MD5SUM) test.bin
   769  endif
   770  	$(TINYGO) build -size short -o test.bin -target=qtpy-esp32c3        examples/serial
   771  	@$(MD5SUM) test.bin
   772  	$(TINYGO) build -size short -o test.bin -target=m5stamp-c3          examples/serial
   773  	@$(MD5SUM) test.bin
   774  	$(TINYGO) build -size short -o test.bin -target=xiao-esp32c3        examples/serial
   775  	@$(MD5SUM) test.bin
   776  	$(TINYGO) build -size short -o test.hex -target=hifive1b            examples/blinky1
   777  	@$(MD5SUM) test.hex
   778  	$(TINYGO) build -size short -o test.hex -target=maixbit             examples/blinky1
   779  	@$(MD5SUM) test.hex
   780  ifneq ($(WASM), 0)
   781  	$(TINYGO) build -size short -o wasm.wasm -target=wasm               examples/wasm/export
   782  	$(TINYGO) build -size short -o wasm.wasm -target=wasm               examples/wasm/main
   783  	$(TINYGO) build -size short -o wasm.wasm -target=wasm-unknown       examples/hello-wasm-unknown
   784  endif
   785  	# test various compiler flags
   786  	$(TINYGO) build -size short -o test.hex -target=pca10040 -gc=none -scheduler=none examples/blinky1
   787  	@$(MD5SUM) test.hex
   788  	$(TINYGO) build -size short -o test.hex -target=pca10040 -opt=1     examples/blinky1
   789  	@$(MD5SUM) test.hex
   790  	$(TINYGO) build -size short -o test.hex -target=pca10040 -serial=none examples/echo
   791  	@$(MD5SUM) test.hex
   792  	$(TINYGO) build -size short -o test.hex -target=pca10040 -serial=rtt examples/echo
   793  	@$(MD5SUM) test.hex
   794  	$(TINYGO) build             -o test.nro -target=nintendoswitch      examples/serial
   795  	@$(MD5SUM) test.nro
   796  	$(TINYGO) build -size short -o test.hex -target=pca10040 -opt=0     ./testdata/stdlib.go
   797  	@$(MD5SUM) test.hex
   798  	GOOS=linux GOARCH=arm $(TINYGO) build -size short -o test.elf       ./testdata/cgo
   799  	GOOS=windows GOARCH=amd64 $(TINYGO) build -size short -o test.exe   ./testdata/cgo
   800  	GOOS=windows GOARCH=arm64 $(TINYGO) build -size short -o test.exe   ./testdata/cgo
   801  	GOOS=darwin GOARCH=amd64 $(TINYGO) build  -size short -o test       ./testdata/cgo
   802  	GOOS=darwin GOARCH=arm64 $(TINYGO) build  -size short -o test       ./testdata/cgo
   803  ifneq ($(OS),Windows_NT)
   804  	# TODO: this does not yet work on Windows. Somehow, unused functions are
   805  	# not garbage collected.
   806  	$(TINYGO) build -o test.elf -gc=leaking -scheduler=none examples/serial
   807  endif
   808  
   809  
   810  wasmtest:
   811  	$(GO) test ./tests/wasm
   812  
   813  build/release: tinygo gen-device wasi-libc $(if $(filter 1,$(USE_SYSTEM_BINARYEN)),,binaryen)
   814  	@mkdir -p build/release/tinygo/bin
   815  	@mkdir -p build/release/tinygo/lib/clang/include
   816  	@mkdir -p build/release/tinygo/lib/CMSIS/CMSIS
   817  	@mkdir -p build/release/tinygo/lib/macos-minimal-sdk
   818  	@mkdir -p build/release/tinygo/lib/mingw-w64/mingw-w64-crt/lib-common
   819  	@mkdir -p build/release/tinygo/lib/mingw-w64/mingw-w64-headers/defaults
   820  	@mkdir -p build/release/tinygo/lib/musl/arch
   821  	@mkdir -p build/release/tinygo/lib/musl/crt
   822  	@mkdir -p build/release/tinygo/lib/musl/src
   823  	@mkdir -p build/release/tinygo/lib/nrfx
   824  	@mkdir -p build/release/tinygo/lib/picolibc/newlib/libc
   825  	@mkdir -p build/release/tinygo/lib/picolibc/newlib/libm
   826  	@mkdir -p build/release/tinygo/lib/wasi-libc/libc-bottom-half/headers
   827  	@mkdir -p build/release/tinygo/lib/wasi-libc/libc-top-half/musl/arch
   828  	@mkdir -p build/release/tinygo/lib/wasi-libc/libc-top-half/musl/src
   829  	@mkdir -p build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0
   830  	@mkdir -p build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0plus
   831  	@mkdir -p build/release/tinygo/pkg/thumbv7em-unknown-unknown-eabi-cortex-m4
   832  	@echo copying source files
   833  	@cp -p  build/tinygo$(EXE)           build/release/tinygo/bin
   834  ifneq ($(USE_SYSTEM_BINARYEN),1)
   835  	@cp -p  build/wasm-opt$(EXE)         build/release/tinygo/bin
   836  endif
   837  	@cp -p $(abspath $(CLANG_SRC))/lib/Headers/*.h build/release/tinygo/lib/clang/include
   838  	@cp -rp lib/CMSIS/CMSIS/Include      build/release/tinygo/lib/CMSIS/CMSIS
   839  	@cp -rp lib/CMSIS/README.md          build/release/tinygo/lib/CMSIS
   840  	@cp -rp lib/macos-minimal-sdk/*      build/release/tinygo/lib/macos-minimal-sdk
   841  	@cp -rp lib/musl/arch/aarch64        build/release/tinygo/lib/musl/arch
   842  	@cp -rp lib/musl/arch/arm            build/release/tinygo/lib/musl/arch
   843  	@cp -rp lib/musl/arch/generic        build/release/tinygo/lib/musl/arch
   844  	@cp -rp lib/musl/arch/i386           build/release/tinygo/lib/musl/arch
   845  	@cp -rp lib/musl/arch/x86_64         build/release/tinygo/lib/musl/arch
   846  	@cp -rp lib/musl/crt/crt1.c          build/release/tinygo/lib/musl/crt
   847  	@cp -rp lib/musl/COPYRIGHT           build/release/tinygo/lib/musl
   848  	@cp -rp lib/musl/include             build/release/tinygo/lib/musl
   849  	@cp -rp lib/musl/src/env             build/release/tinygo/lib/musl/src
   850  	@cp -rp lib/musl/src/errno           build/release/tinygo/lib/musl/src
   851  	@cp -rp lib/musl/src/exit            build/release/tinygo/lib/musl/src
   852  	@cp -rp lib/musl/src/include         build/release/tinygo/lib/musl/src
   853  	@cp -rp lib/musl/src/internal        build/release/tinygo/lib/musl/src
   854  	@cp -rp lib/musl/src/legacy          build/release/tinygo/lib/musl/src
   855  	@cp -rp lib/musl/src/linux           build/release/tinygo/lib/musl/src
   856  	@cp -rp lib/musl/src/malloc          build/release/tinygo/lib/musl/src
   857  	@cp -rp lib/musl/src/mman            build/release/tinygo/lib/musl/src
   858  	@cp -rp lib/musl/src/math            build/release/tinygo/lib/musl/src
   859  	@cp -rp lib/musl/src/signal          build/release/tinygo/lib/musl/src
   860  	@cp -rp lib/musl/src/stdio           build/release/tinygo/lib/musl/src
   861  	@cp -rp lib/musl/src/string          build/release/tinygo/lib/musl/src
   862  	@cp -rp lib/musl/src/thread          build/release/tinygo/lib/musl/src
   863  	@cp -rp lib/musl/src/time            build/release/tinygo/lib/musl/src
   864  	@cp -rp lib/musl/src/unistd          build/release/tinygo/lib/musl/src
   865  	@cp -rp lib/mingw-w64/mingw-w64-crt/def-include                 build/release/tinygo/lib/mingw-w64/mingw-w64-crt
   866  	@cp -rp lib/mingw-w64/mingw-w64-crt/lib-common/api-ms-win-crt-* build/release/tinygo/lib/mingw-w64/mingw-w64-crt/lib-common
   867  	@cp -rp lib/mingw-w64/mingw-w64-crt/lib-common/kernel32.def.in  build/release/tinygo/lib/mingw-w64/mingw-w64-crt/lib-common
   868  	@cp -rp lib/mingw-w64/mingw-w64-headers/crt/                    build/release/tinygo/lib/mingw-w64/mingw-w64-headers
   869  	@cp -rp lib/mingw-w64/mingw-w64-headers/defaults/include        build/release/tinygo/lib/mingw-w64/mingw-w64-headers/defaults
   870  	@cp -rp lib/nrfx/*                   build/release/tinygo/lib/nrfx
   871  	@cp -rp lib/picolibc/newlib/libc/ctype       build/release/tinygo/lib/picolibc/newlib/libc
   872  	@cp -rp lib/picolibc/newlib/libc/include     build/release/tinygo/lib/picolibc/newlib/libc
   873  	@cp -rp lib/picolibc/newlib/libc/locale      build/release/tinygo/lib/picolibc/newlib/libc
   874  	@cp -rp lib/picolibc/newlib/libc/string      build/release/tinygo/lib/picolibc/newlib/libc
   875  	@cp -rp lib/picolibc/newlib/libc/tinystdio   build/release/tinygo/lib/picolibc/newlib/libc
   876  	@cp -rp lib/picolibc/newlib/libm/common      build/release/tinygo/lib/picolibc/newlib/libm
   877  	@cp -rp lib/picolibc/newlib/libm/math        build/release/tinygo/lib/picolibc/newlib/libm
   878  	@cp -rp lib/picolibc-stdio.c         build/release/tinygo/lib
   879  	@cp -rp lib/wasi-libc/libc-bottom-half/headers/public           build/release/tinygo/lib/wasi-libc/libc-bottom-half/headers
   880  	@cp -rp lib/wasi-libc/libc-top-half/musl/arch/generic           build/release/tinygo/lib/wasi-libc/libc-top-half/musl/arch
   881  	@cp -rp lib/wasi-libc/libc-top-half/musl/arch/wasm32            build/release/tinygo/lib/wasi-libc/libc-top-half/musl/arch
   882  	@cp -rp lib/wasi-libc/libc-top-half/musl/src/include            build/release/tinygo/lib/wasi-libc/libc-top-half/musl/src
   883  	@cp -rp lib/wasi-libc/libc-top-half/musl/src/internal           build/release/tinygo/lib/wasi-libc/libc-top-half/musl/src
   884  	@cp -rp lib/wasi-libc/libc-top-half/musl/src/math               build/release/tinygo/lib/wasi-libc/libc-top-half/musl/src
   885  	@cp -rp lib/wasi-libc/libc-top-half/musl/src/string             build/release/tinygo/lib/wasi-libc/libc-top-half/musl/src
   886  	@cp -rp lib/wasi-libc/libc-top-half/musl/include                build/release/tinygo/lib/wasi-libc/libc-top-half/musl
   887  	@cp -rp lib/wasi-libc/sysroot                                   build/release/tinygo/lib/wasi-libc/sysroot
   888  	@cp -rp llvm-project/compiler-rt/lib/builtins build/release/tinygo/lib/compiler-rt-builtins
   889  	@cp -rp llvm-project/compiler-rt/LICENSE.TXT  build/release/tinygo/lib/compiler-rt-builtins
   890  	@cp -rp src                          build/release/tinygo/src
   891  	@cp -rp targets                      build/release/tinygo/targets
   892  	./build/release/tinygo/bin/tinygo build-library -target=cortex-m0     -o build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0/compiler-rt     compiler-rt
   893  	./build/release/tinygo/bin/tinygo build-library -target=cortex-m0plus -o build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0plus/compiler-rt compiler-rt
   894  	./build/release/tinygo/bin/tinygo build-library -target=cortex-m4     -o build/release/tinygo/pkg/thumbv7em-unknown-unknown-eabi-cortex-m4/compiler-rt    compiler-rt
   895  	./build/release/tinygo/bin/tinygo build-library -target=cortex-m0     -o build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0/picolibc     picolibc
   896  	./build/release/tinygo/bin/tinygo build-library -target=cortex-m0plus -o build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0plus/picolibc picolibc
   897  	./build/release/tinygo/bin/tinygo build-library -target=cortex-m4     -o build/release/tinygo/pkg/thumbv7em-unknown-unknown-eabi-cortex-m4/picolibc    picolibc
   898  
   899  release:
   900  	tar -czf build/release.tar.gz -C build/release tinygo
   901  
   902  DEB_ARCH ?= native
   903  deb:
   904  	@mkdir -p build/release-deb/usr/local/bin
   905  	@mkdir -p build/release-deb/usr/local/lib
   906  	cp -ar build/release/tinygo build/release-deb/usr/local/lib/tinygo
   907  	ln -sf ../lib/tinygo/bin/tinygo build/release-deb/usr/local/bin/tinygo
   908  	fpm -f -s dir -t deb -n tinygo -a $(DEB_ARCH) -v $(shell grep "const version = " goenv/version.go | awk '{print $$NF}') -m '@tinygo-org' --description='TinyGo is a Go compiler for small places.' --license='BSD 3-Clause' --url=https://tinygo.org/ --deb-changelog CHANGELOG.md -p build/release.deb -C ./build/release-deb
   909  
   910  ifneq ($(RELEASEONLY), 1)
   911  release: build/release
   912  deb: build/release
   913  endif