github.com/aykevl/tinygo@v0.5.0/Makefile (about) 1 2 # aliases 3 all: tinygo 4 tinygo: build/tinygo 5 6 .PHONY: all tinygo build/tinygo test llvm-build llvm-source clean fmt gen-device gen-device-nrf gen-device-avr 7 8 # Default build and source directories, as created by `make llvm-build`. 9 LLVM_BUILDDIR ?= llvm-build 10 CLANG_SRC ?= llvm/tools/clang 11 LLD_SRC ?= llvm/tools/lld 12 13 LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines debuginfodwarf executionengine instrumentation interpreter ipo irreader linker lto mc mcjit objcarcopts option profiledata scalaropts support target 14 15 UNAME_S := $(shell uname -s) 16 ifeq ($(UNAME_S),Linux) 17 START_GROUP = -Wl,--start-group 18 END_GROUP = -Wl,--end-group 19 endif 20 21 CLANG_LIBS = $(START_GROUP) $(abspath $(LLVM_BUILDDIR))/lib/libclang.a -lclangAnalysis -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangBasic -lclangCodeGen -lclangCrossTU -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangHandleCXX -lclangHandleLLVM -lclangIndex -lclangLex -lclangParse -lclangRewrite -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTooling -lclangToolingASTDiff -lclangToolingCore -lclangToolingInclusions -lclangToolingRefactor $(END_GROUP) -lstdc++ 22 23 LLD_LIBS = $(START_GROUP) -llldCOFF -llldCommon -llldCore -llldDriver -llldELF -llldMachO -llldMinGW -llldReaderWriter -llldWasm -llldYAML $(END_GROUP) 24 25 26 # For static linking. 27 CGO_CPPFLAGS=$(shell $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(CLANG_SRC))/include -I$(abspath $(LLD_SRC))/include 28 CGO_CXXFLAGS=-std=c++11 29 CGO_LDFLAGS=-L$(LLVM_BUILDDIR)/lib $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) 30 31 32 clean: 33 @rm -rf build 34 35 FMT_PATHS = ./*.go compiler interp ir loader src/device/arm src/examples src/machine src/os src/reflect src/runtime src/sync src/syscall 36 fmt: 37 @gofmt -l -w $(FMT_PATHS) 38 fmt-check: 39 @unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1 40 41 gen-device: gen-device-avr gen-device-nrf gen-device-sam gen-device-stm32 42 43 gen-device-avr: 44 ./tools/gen-device-avr.py lib/avr/packs/atmega src/device/avr/ 45 ./tools/gen-device-avr.py lib/avr/packs/tiny src/device/avr/ 46 go fmt ./src/device/avr 47 48 gen-device-nrf: 49 ./tools/gen-device-svd.py lib/nrfx/mdk/ src/device/nrf/ --source=https://github.com/NordicSemiconductor/nrfx/tree/master/mdk 50 go fmt ./src/device/nrf 51 52 gen-device-sam: 53 ./tools/gen-device-svd.py lib/cmsis-svd/data/Atmel/ src/device/sam/ --source=https://github.com/posborne/cmsis-svd/tree/master/data/Atmel 54 go fmt ./src/device/sam 55 56 gen-device-stm32: 57 ./tools/gen-device-svd.py lib/cmsis-svd/data/STMicro/ src/device/stm32/ --source=https://github.com/posborne/cmsis-svd/tree/master/data/STMicro 58 go fmt ./src/device/stm32 59 60 61 # Get LLVM sources. 62 llvm/README.txt: 63 git clone -b release_80 https://github.com/llvm-mirror/llvm.git llvm 64 llvm/tools/clang/README.txt: 65 git clone -b release_80 https://github.com/llvm-mirror/clang.git llvm/tools/clang 66 llvm/tools/lld/README.md: 67 git clone -b release_80 https://github.com/llvm-mirror/lld.git llvm/tools/lld 68 llvm-source: llvm/README.txt llvm/tools/clang/README.txt llvm/tools/lld/README.md 69 70 # Configure LLVM. 71 llvm-build/build.ninja: llvm-source 72 mkdir -p llvm-build; cd llvm-build; cmake -G Ninja ../llvm "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;WebAssembly" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF -DLIBCLANG_BUILD_STATIC=ON 73 74 # Build LLVM. 75 llvm-build: llvm-build/build.ninja 76 cd llvm-build; ninja 77 78 79 # Build the Go compiler. 80 build/tinygo: 81 @if [ ! -f llvm-build/bin/llvm-config ]; then echo "Fetch and build LLVM first by running:\n make llvm-source\n make llvm-build"; exit 1; fi 82 CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build -o build/tinygo -tags byollvm . 83 84 test: 85 CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go test -v -tags byollvm . 86 87 release: build/tinygo gen-device 88 @mkdir -p build/release/tinygo/bin 89 @mkdir -p build/release/tinygo/lib/CMSIS/CMSIS 90 @mkdir -p build/release/tinygo/lib/compiler-rt/lib 91 @mkdir -p build/release/tinygo/lib/nrfx 92 @mkdir -p build/release/tinygo/pkg/armv6m-none-eabi 93 @mkdir -p build/release/tinygo/pkg/armv7m-none-eabi 94 @mkdir -p build/release/tinygo/pkg/armv7em-none-eabi 95 @cp -p build/tinygo build/release/tinygo/bin 96 @cp -rp lib/CMSIS/CMSIS/Include build/release/tinygo/lib/CMSIS/CMSIS 97 @cp -rp lib/CMSIS/README.md build/release/tinygo/lib/CMSIS 98 @cp -rp lib/compiler-rt/lib/builtins build/release/tinygo/lib/compiler-rt/lib 99 @cp -rp lib/compiler-rt/LICENSE.TXT build/release/tinygo/lib/compiler-rt 100 @cp -rp lib/compiler-rt/README.txt build/release/tinygo/lib/compiler-rt 101 @cp -rp lib/nrfx/* build/release/tinygo/lib/nrfx 102 @cp -rp src build/release/tinygo/src 103 @cp -rp targets build/release/tinygo/targets 104 ./build/tinygo build-builtins -target=armv6m-none-eabi -o build/release/tinygo/pkg/armv6m-none-eabi/compiler-rt.a 105 ./build/tinygo build-builtins -target=armv7m-none-eabi -o build/release/tinygo/pkg/armv7m-none-eabi/compiler-rt.a 106 ./build/tinygo build-builtins -target=armv7em-none-eabi -o build/release/tinygo/pkg/armv7em-none-eabi/compiler-rt.a 107 tar -czf build/release.tar.gz -C build/release tinygo