1
1
2
2
# aliases
3
3
all : tinygo
4
- tinygo : build/tinygo
5
4
6
5
# Default build and source directories, as created by `make llvm-build`.
7
6
LLVM_BUILDDIR ?= llvm-build
33
32
LLVM_OPTION += '-DLLVM_ENABLE_ASSERTIONS=OFF'
34
33
endif
35
34
36
- .PHONY : all tinygo build/tinygo test $(LLVM_BUILDDIR ) llvm-source clean fmt gen-device gen-device-nrf gen-device-avr
35
+ .PHONY : all tinygo test $(LLVM_BUILDDIR ) llvm-source clean fmt gen-device gen-device-nrf gen-device-avr
37
36
38
37
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
39
38
40
- UNAME_S := $( shell uname -s )
41
- ifeq ( $( UNAME_S ) ,Linux)
39
+ ifeq ( $( OS ) ,Windows_NT )
40
+ EXE = .exe
42
41
START_GROUP = -Wl,--start-group
43
42
END_GROUP = -Wl,--end-group
44
- else ifeq ($(UNAME_S),Darwin)
43
+
44
+ # LLVM compiled using MinGW on Windows appears to have problems with threads.
45
+ # Without this flag, linking results in errors like these:
46
+ # libLLVMSupport.a(Threading.cpp.obj):Threading.cpp:(.text+0x55): undefined reference to `std::thread::hardware_concurrency()'
47
+ LLVM_OPTION += -DLLVM_ENABLE_THREADS=OFF
48
+
49
+ CGO_LDFLAGS += -static -static-libgcc -static-libstdc++
50
+ CGO_LDFLAGS_EXTRA += -lversion
51
+
52
+ # Build libclang manually because the CMake-based build system on Windows
53
+ # doesn't allow building libclang as a static library.
54
+ LIBCLANG_PATH = $(abspath build/libclang-custom.a)
55
+ LIBCLANG_FILES = $(abspath $(wildcard $(LLVM_BUILDDIR ) /tools/clang/tools/libclang/CMakeFiles/libclang.dir/* .cpp.obj) )
56
+
57
+ # Add the libclang dependency to the tinygo binary target.
58
+ tinygo : $(LIBCLANG_PATH )
59
+ test : $(LIBCLANG_PATH )
60
+ # Build libclang.
61
+ $(LIBCLANG_PATH ) : $(LIBCLANG_FILES )
62
+ @mkdir -p build
63
+ ar rcs $(LIBCLANG_PATH ) $^
64
+
65
+ else ifeq ($(shell uname -s),Darwin)
45
66
MD5SUM = md5
67
+ LIBCLANG_PATH = $(abspath $(LLVM_BUILDDIR ) ) /lib/libclang.a
68
+ else
69
+ LIBCLANG_PATH = $(abspath $(LLVM_BUILDDIR ) ) /lib/libclang.a
70
+ START_GROUP = -Wl,--start-group
71
+ END_GROUP = -Wl,--end-group
46
72
endif
47
73
48
- 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 $(END_GROUP ) -lstdc++
74
+ CLANG_LIBS = $(START_GROUP ) -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 $(END_GROUP ) -lstdc++
49
75
50
76
LLD_LIBS = $(START_GROUP ) -llldCOFF -llldCommon -llldCore -llldDriver -llldELF -llldMachO -llldMinGW -llldReaderWriter -llldWasm -llldYAML $(END_GROUP )
51
77
52
78
53
79
# For static linking.
54
- ifneq ("$(wildcard $(LLVM_BUILDDIR ) /bin/llvm-config) ","")
80
+ ifneq ("$(wildcard $(LLVM_BUILDDIR ) /bin/llvm-config* ) ","")
55
81
CGO_CPPFLAGS =$(shell $(LLVM_BUILDDIR ) /bin/llvm-config --cppflags) -I$(abspath $(CLANG_SRC ) ) /include -I$(abspath $(LLD_SRC ) ) /include
56
82
CGO_CXXFLAGS=-std =c++11
57
- CGO_LDFLAGS =- L$(LLVM_BUILDDIR ) /lib $(CLANG_LIBS ) $(LLD_LIBS ) $(shell $(LLVM_BUILDDIR ) /bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS ) )
83
+ CGO_LDFLAGS+ = $( LIBCLANG_PATH ) -std=c++11 - L$(abspath $( LLVM_BUILDDIR ) /lib) $(CLANG_LIBS ) $(LLD_LIBS ) $(shell $(LLVM_BUILDDIR ) /bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS ) ) -lstdc++ $( CGO_LDFLAGS_EXTRA )
58
84
endif
59
85
60
86
@@ -108,9 +134,9 @@ $(LLVM_BUILDDIR): $(LLVM_BUILDDIR)/build.ninja
108
134
109
135
110
136
# Build the Go compiler.
111
- build/ tinygo :
137
+ tinygo :
112
138
@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
113
- CGO_CPPFLAGS=" $( CGO_CPPFLAGS) " CGO_CXXFLAGS=" $( CGO_CXXFLAGS) " CGO_LDFLAGS=" $( CGO_LDFLAGS) " $(GO ) build -o build/tinygo -tags byollvm .
139
+ CGO_CPPFLAGS=" $( CGO_CPPFLAGS) " CGO_CXXFLAGS=" $( CGO_CXXFLAGS) " CGO_LDFLAGS=" $( CGO_LDFLAGS) " $(GO ) build -o build/tinygo$( EXE ) -tags byollvm .
114
140
115
141
test :
116
142
CGO_CPPFLAGS=" $( CGO_CPPFLAGS) " CGO_CXXFLAGS=" $( CGO_CXXFLAGS) " CGO_LDFLAGS=" $( CGO_LDFLAGS) " $(GO ) test -v -tags byollvm ./interp ./transform .
@@ -198,7 +224,7 @@ endif
198
224
$(TINYGO) build -o wasm.wasm -target=wasm examples/wasm/export
199
225
$(TINYGO) build -o wasm.wasm -target=wasm examples/wasm/main
200
226
201
- release : build/ tinygo gen-device
227
+ release : tinygo gen-device
202
228
@mkdir -p build/release/tinygo/bin
203
229
@mkdir -p build/release/tinygo/lib/clang/include
204
230
@mkdir -p build/release/tinygo/lib/CMSIS/CMSIS
@@ -208,7 +234,7 @@ release: build/tinygo gen-device
208
234
@mkdir -p build/release/tinygo/pkg/armv7m-none-eabi
209
235
@mkdir -p build/release/tinygo/pkg/armv7em-none-eabi
210
236
@echo copying source files
211
- @cp -p build/tinygo build/release/tinygo/bin
237
+ @cp -p build/tinygo$( EXE ) build/release/tinygo/bin
212
238
@cp -p $(abspath $(CLANG_SRC ) ) /lib/Headers/* .h build/release/tinygo/lib/clang/include
213
239
@cp -rp lib/CMSIS/CMSIS/Include build/release/tinygo/lib/CMSIS/CMSIS
214
240
@cp -rp lib/CMSIS/README.md build/release/tinygo/lib/CMSIS
0 commit comments