-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcompiler.mk
75 lines (57 loc) · 1.81 KB
/
compiler.mk
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
# GCC Compiler
################################################################################
# Ccache
#
export CCACHE_DIR=/tmp/ccache/makefile/$(PROJ_NAME)
CCACHE=ccache
################################################################################
# Toolchain
#
AS = $(CCACHE) gcc -x assembler-with-cpp
CC = $(CCACHE) gcc
CXX = $(CCACHE) g++
LD = gcc
AR = ar
SZ = size
OC = objcopy
NM = nm
################################################################################
# Flags
#
# Compiler errors and warnings
CPPFLAGS += \
-Werror -Wall -Wextra -Wshadow \
-Wpedantic -pedantic-errors -Wformat=2 -Wformat-truncation -Wundef \
-Wcomments -Wmisleading-indentation \
-Wstrict-aliasing -fstrict-aliasing \
-Wduplicated-branches -Wduplicated-cond \
-Wcast-align -Wdangling-else \
-Wunused-parameter -Wimplicit-fallthrough -Wunused-function \
-fno-common -Wdouble-promotion
# Linker warnings are treated as errors
LDFLAGS += -Wl,--fatal-warnings
CPPFLAGS += -Wmisleading-indentation -Wmaybe-uninitialized
# CPPFLAGS += -Wpadded
# Do not show more than a few errors at a time.
CPPFLAGS += -fmax-errors=5
CFLAGS += -Wmissing-prototypes # Valid only for C
# Generate stack usage information (*.su)
CPPFLAGS += -fstack-usage -Wstack-protector -Wstack-usage=50
# Eliminate unused code
CPPFLAGS += -ffunction-sections -fdata-sections
LDFLAGS += -Wl,--gc-sections
# C language specification
CFLAGS += -std=c99
# C++ language specification
CXXFLAGS += -std=c++11
# Autodependency
CPPFLAGS += -MT $@ -MMD -MP -MF $(@:%.o=%.Td)
# Generate listing
CPPFLAGS += -Wa,-a,-ad,-alms=$(@:%.o=%.lst)
# Debug/Release flags
ifeq ($(TARGET),dbg)
CPPFLAGS+=-g3 -Og -gdwarf-2 -DDEBUG
endif
ifeq ($(TARGET),rel)
CPPFLAGS+=-O3 -DNDEBUG
endif