1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
#
# Copyright 2016 WebAssembly Community Group participants
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
.SUFFIXES:
USE_NINJA ?= 0
DEFAULT_COMPILER = CLANG
DEFAULT_BUILD_TYPE = DEBUG
COMPILERS := GCC GCC_I686 CLANG
BUILD_TYPES := DEBUG RELEASE
SANITIZERS := NO ASAN MSAN LSAN
EXECUTABLES := sexpr-wasm hexfloat_test
GCC_DEBUG_DIR := out/gcc/Debug
GCC_DEBUG_NO_FLEX_BISON_DIR := out/gcc/Debug-no-flex-bison
GCC_RELEASE_DIR := out/gcc/Release
GCC_I686_DEBUG_DIR := out/gcc-i686/Debug
GCC_I686_RELEASE_DIR := out/gcc-i686/Release
CLANG_DEBUG_DIR := out/clang/Debug
CLANG_RELEASE_DIR := out/clang/Release
DEBUG_FLAG := -DCMAKE_BUILD_TYPE=Debug
RELEASE_FLAG := -DCMAKE_BUILD_TYPE=Release
GCC_FLAG := -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
GCC_I686_FLAG := -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32
CLANG_FLAG := -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
GCC_DEBUG_PREFIX := gcc-debug
GCC_DEBUG_NO_FLEX_BISON_PREFIX := gcc-debug-no-flex-bison
GCC_RELEASE_PREFIX := gcc-release
GCC_I686_DEBUG_PREFIX := gcc-i686-debug
GCC_I686_RELEASE_PREFIX := gcc-i686-release
CLANG_DEBUG_PREFIX := clang-debug
CLANG_RELEASE_PREFIX := clang-release
NO_SUFFIX :=
ASAN_SUFFIX := -asan
MSAN_SUFFIX := -msan
LSAN_SUFFIX := -lsan
ifeq ($(USE_NINJA),1)
BUILD := ninja
BUILD_FILE := build.ninja
GENERATOR := Ninja
else
BUILD := $(MAKE) --no-print-directory
BUILD_FILE := Makefile
GENERATOR := "Unix Makefiles"
endif
define DEFAULT
.PHONY: $(3)$$($(4)_SUFFIX) test$$($(4)_SUFFIX)
$(3)$$($(4)_SUFFIX): $$($(1)_$(2)_PREFIX)$$($(4)_SUFFIX)
ln -sf ../$$($(1)_$(2)_DIR)/$(3)$$($(4)_SUFFIX) out/$(3)$$($(4)_SUFFIX)
test$$($(4)_SUFFIX): test-$$($(1)_$(2)_PREFIX)$$($(4)_SUFFIX)
test-everything: test$$($(4)_SUFFIX)
endef
define CMAKE
$$($(1)_$(2)_DIR)/:
mkdir -p $$($(1)_$(2)_DIR)
$$($(1)_$(2)_DIR)/$$(BUILD_FILE): | $$($(1)_$(2)_DIR)/
cd $$($(1)_$(2)_DIR) && cmake -G $$(GENERATOR) ../../.. $$($(1)_FLAG) $$($(2)_FLAG) $(3)
endef
define EXE
.PHONY: $$($(1)_$(2)_PREFIX)$$($(3)_SUFFIX)
$$($(1)_$(2)_PREFIX)$$($(3)_SUFFIX): $$($(1)_$(2)_DIR)/$$(BUILD_FILE)
$$(BUILD) -C $$($(1)_$(2)_DIR) all$$($(3)_SUFFIX)
endef
define TEST
.PHONY: test-$$($(1)_$(2)_PREFIX)$$($(3)_SUFFIX)
test-$$($(1)_$(2)_PREFIX)$$($(3)_SUFFIX): $$($(1)_$(2)_DIR)/$$(BUILD_FILE)
$$(BUILD) -C $$($(1)_$(2)_DIR) test$$($(3)_SUFFIX)
endef
.PHONY: all
all: ${EXECUTABLES}
.PHONY: clean
clean:
rm -rf out
.PHONY: test-everything
test-everything:
.PHONY: update-bison update-flex
update-bison: src/prebuilt/wasm-bison-parser.c
update-flex: src/prebuilt/wasm-flex-lexer.c
src/prebuilt/wasm-bison-parser.c: src/wasm-bison-parser.y
bison -o $@ $< --defines=src/prebuilt/wasm-bison-parser.h
src/prebuilt/wasm-flex-lexer.c: src/wasm-flex-lexer.l
flex -o $@ $<
# defaults with simple names
$(foreach SANITIZER,$(SANITIZERS), \
$(foreach EXECUTABLE,$(EXECUTABLES), \
$(eval $(call DEFAULT,$(DEFAULT_COMPILER),$(DEFAULT_BUILD_TYPE),$(EXECUTABLE),$(SANITIZER)))))
# running CMake
$(foreach COMPILER,$(COMPILERS), \
$(foreach BUILD_TYPE,$(BUILD_TYPES), \
$(eval $(call CMAKE,$(COMPILER),$(BUILD_TYPE)))))
# building
$(foreach SANITIZER,$(SANITIZERS), \
$(foreach COMPILER,$(COMPILERS), \
$(foreach BUILD_TYPE,$(BUILD_TYPES), \
$(eval $(call EXE,$(COMPILER),$(BUILD_TYPE),$(SANITIZER))))))
# test running
$(foreach SANITIZER,$(SANITIZERS), \
$(foreach COMPILER,$(COMPILERS), \
$(foreach BUILD_TYPE,$(BUILD_TYPES), \
$(eval $(call TEST,$(COMPILER),$(BUILD_TYPE),$(SANITIZER))))))
# One-off build target for running w/out flex + bison
$(eval $(call CMAKE,GCC,DEBUG_NO_FLEX_BISON,-DRUN_FLEX_BISON=OFF))
$(eval $(call EXE,GCC,DEBUG_NO_FLEX_BISON,NO))
$(eval $(call TEST,GCC,DEBUG_NO_FLEX_BISON,NO))
|