forked from alibaba/xoc
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMakefile.option
125 lines (115 loc) · 3.29 KB
/
Makefile.option
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
#SET DEBUG FLAG
ifeq ($(DEBUG),)
#Default build mode is DEBUG mode.
DEBUG=true
endif
CFLAGS+=-Wno-bool-compare
ifeq ($(DEBUG), true)
#Add predefined macro if build host is Windows.
CFLAGS+=-D_DEBUG_
CFLAGS+=-O0 -g2
CFLAGS+=-MMD #Ask compiler generate dependent files information.
else
CFLAGS+=-O2
CFLAGS+=-MMD #Ask compiler generate dependent files information.
endif
ifeq ($(REF_TARGMACH_INFO),true)
CFLAGS+=-DREF_TARGMACH_INFO #LSRA use targmach info
endif
#The code attemps to compile an empty C++ file with the option, and
#return YES if compilation is successful, otherwise return NO. The return info
#is record in a makefile variable.
CC_SUPPORTS_C11 := $(shell echo "" | \
$(CC) -std=c++11 -c -x c++ \
- > /dev/null 2>&1 && echo YES || echo NO)
ifeq ($(CC_SUPPORTS_C11),YES)
$(info "NOTE:$(CC) SUPPORT C++11")
CFLAGS+=-std=c++11
else
$(info "NOTE:$(CC) DOES NOT SUPPORT C++11")
endif
#Try to disable the warning.
WARN=class-memaccess
CC_SUPPORTS_WNO-$(WARN) := $(shell echo "" | \
$(CC) -Wno-$(WARN) -c -x c++ \
- > /dev/null 2>&1 && echo YES || echo NO)
ifeq ($(CC_SUPPORTS_WNO-$(WARN)),YES)
$(info "NOTE:$(CC) SUPPORT -Wno-$(WARN)")
CFLAGS+=-Wno-$(WARN)
else
$(info "NOTE:$(CC) DOES NOT SUPPORT -Wno-$(WARN)")
endif
#Try to disable the warning.
WARN=delete-incomplete
CC_SUPPORTS_WNO-$(WARN) := $(shell echo "" | \
$(CC) -Wno-$(WARN) -c -x c++ \
- > /dev/null 2>&1 && echo YES || echo NO)
ifeq ($(CC_SUPPORTS_WNO-$(WARN)),YES)
$(info "NOTE:$(CC) SUPPORT -Wno-$(WARN)")
CFLAGS+=-Wno-$(WARN)
else
$(info "NOTE:$(CC) DOES NOT SUPPORT -Wno-$(WARN)")
endif
#Try to disable the warning.
#The code attemps to compile an empty C++ file with the warning option, and
#return YES if compilation is successful, otherwise return NO. The return info
#is record in a makefile variable.
#The warning is NOT effect without optimization, thus code must be
#compiled with the -O2 option in order for GCC to find the bug.
WARN=mismatched-new-delete
CC_SUPPORTS_WNO-$(WARN) := $(shell echo "" | \
$(CC) -Wno-$(WARN) -c -x c++ \
- > /dev/null 2>&1 && echo YES || echo NO)
ifeq ($(CC_SUPPORTS_WNO-$(WARN)),YES)
$(info "NOTE:$(CC) SUPPORT -Wno-$(WARN)")
CFLAGS+=-Wno-$(WARN)
else
$(info "NOTE:$(CC) DOES NOT SUPPORT -Wno-$(WARN)")
endif
#To conveninently use DUMMYUSE, some compiler will complain for comma
#expression.
USE_DUMMYUSE=true
ifeq ($(USE_DUMMYUSE), true)
CFLAGS+=-Wno-unused-value
endif
#ADD OS FLAG
ifeq ($(WIN), true)
$(info "ON WINDOWS")
#Add predefined macro if build host is Windows.
CFLAGS+=-D_ON_WINDOWS_
ifeq ($(WSL), true)
CFLAGS+=-D_USE_GCC_
endif
else
$(info "ON LINUX OR UNIX")
CFLAGS+=-D_USE_GCC_
endif
#SET COMPILER
ifeq ($(WIN), true)
$(info "ON WINDOWS")
ifeq ($(WSL), true)
ifndef CC
CC:=$(shell which clang++ > /dev/null)
ifndef CC
CC=$(if $(shell which clang),clang.exe,gcc.exe)
endif
endif
else
$(error "THERE IS NO CC COMPILER AVAIABLE WITHOUT WSL ENVIRONMENT")
endif
ifndef CC
$(error "THERE IS NO CC COMPILER AVAIABLE")
#$(info "CC is defined="$(CC))
endif
else
$(info "ON LINUX OR UNIX")
ifndef CC
CC:=$(shell which clang++ > /dev/null)
ifndef CC
CC=$(if $(shell which clang),clang,gcc)
endif
endif
ifndef CC
$(error "THERE IS NO CC COMPILER AVAIABLE")
endif
endif