-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
110 lines (91 loc) · 2.76 KB
/
Makefile
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
include config.mk
# == General
TARGETS := rodac
ALL_TARGETS := rodac tests
ALL_SWITCHES := llvm
# ==
# == Feature detection
LLVM_CONFIG ?= llvm-config
LLVM_VERSION ?= $(shell $(LLVM_CONFIG) --version || true)
LLVM_MAJOR ?= $(shell $(LLVM_CONFIG) --version | cut -d "." -f 1)
LLVM ?= $(shell if [ $(LLVM_MAJOR) -ge 10 ] ; then echo yes ; else echo no ; fi)
# ==
# == Enable features
ifeq ($(LLVM),yes)
SWITCHES += llvm
endif
ifeq ($(TESTS),yes)
TARGETS += tests
endif
TARGETS := $(sort $(TARGETS))
SWITCHES := $(sort $(SWITCHES))
export SWITCHES TARGETS
# ==
# == Tools
CC ?= gcc
CXX ?= g++
ifeq ($(LLVM),yes)
LD := $(CXX)
else
LD := $(CC)
endif
LEX ?= flex
YACC := bison
# ==
# == Flags
CFLAGS += -std=c11 -pedantic -Wno-strict-prototypes
ifneq ($(GIT_HEAD),)
CFLAGS += -DGIT_HEAD="\"$(GIT_HEAD)\""
endif
ifneq ($(GIT_URL),)
CFLAGS += -DGIT_URL="\"$(GIT_URL)\""
endif
ifneq ($(LLVM_VERSION),)
CFLAGS += -DLLVM_VERSION="\"$(LLVM_VERSION)\""
endif
YFLAGS += -Wall
CFLAGS.llvm += $(shell $(LLVM_CONFIG) --cflags || true)
LDFLAGS.llvm += $(shell $(LLVM_CONFIG) --ldflags || true)
LDLIBS.llvm += $(shell $(LLVM_CONFIG) --libs --system-libs || true)
LDLIBS += -lm
# ==
# == Parser generator files
LEX_SRC := $(SOURCE_DIR)/parser/lexer.l
LEX_C := $(SOURCE_DIR)/parser/lexer.yy.c
LEX_H := $(SOURCE_DIR)/parser/lexer.yy.h
YACC_SRC := $(SOURCE_DIR)/parser/parser.y
YACC_C := $(SOURCE_DIR)/parser/parser.tab.c
YACC_H := $(SOURCE_DIR)/parser/parser.tab.h
GEN_SOURCES += $(LEX_C) $(YACC_C)
TO_CLEAN += $(LEX_C) $(LEX_H) $(YACC_C) $(YACC_H) $(BASE_DIR)/profile
# ==
include build.mk
# == Parser generator rules
$(LEX_C): $(LEX_SRC) $(YACC_C)
@$(ECHO) "Building $@"
$(LEX) $(LFLAGS) --outfile=$(LEX_C) --header-file=$(LEX_H) $<
$(YACC_C): $(YACC_SRC)
@$(ECHO) "Building $@"
$(YACC) $(YFLAGS) --output=$(YACC_C) --defines=$(YACC_H) $<
# ==
# == Tetsing
.PHONY: run-test test coverage
test:
$(MAKE) TESTS=yes run-test
run-test: build
@$(ECHO) "Starting build-in tests"
$(BINARY_DIR)/tests
@$(ECHO) "Starting tests with --debug"
TEST_ARGS=--debug BINARY=$(BINARY_DIR)/rodac tested -j12 $(BASE_DIR)/tests
@$(ECHO) "Starting tests with -O0"
TEST_ARGS=-O0 BINARY=$(BINARY_DIR)/rodac tested -j12 $(BASE_DIR)/tests
@$(ECHO) "Starting tests with -O2"
TEST_ARGS=-O2 BINARY=$(BINARY_DIR)/rodac tested -j12 $(BASE_DIR)/tests
@$(ECHO) "Finished tests"
coverage:
$(RM) -r $(BASE_DIR)/profile/
LLVM_PROFILE_FILE="profile/tests/%p.profraw" $(MAKE) BUILD=coverage test
llvm-profdata merge $(BASE_DIR)/profile/tests/*.profraw -o $(BASE_DIR)/profile/combined.profdata
llvm-cov show $(BUILD_DIR)/coverage/bin/rodac -instr-profile=$(BASE_DIR)/profile/combined.profdata -o $(BASE_DIR)/profile/report
llvm-cov report $(BUILD_DIR)/coverage/bin/rodac -instr-profile=$(BASE_DIR)/profile/combined.profdata
# ==