forked from sbabic/swupdate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.flags
179 lines (153 loc) · 5.45 KB
/
Makefile.flags
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# ==========================================================================
# Build system
# ==========================================================================
SWU_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
export SWU_VER
SKIP_STRIP ?= n
# -std=gnu99 needed for [U]LLONG_MAX on some systems
KBUILD_CPPFLAGS += $(call cc-option,-std=gnu99,)
KBUILD_CPPFLAGS += -D_GNU_SOURCE -DNDEBUG \
-D"SWU_VER=KBUILD_STR($(SWU_VER))"
KBUILD_CFLAGS += $(call cc-option,-Wall,)
KBUILD_CFLAGS += $(call cc-option,-Wshadow,)
KBUILD_CFLAGS += $(call cc-option,-Wwrite-strings,)
KBUILD_CFLAGS += $(call cc-option,-Wundef,)
KBUILD_CFLAGS += $(call cc-option,-Wstrict-prototypes,)
KBUILD_CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,)
KBUILD_CFLAGS += $(call cc-option,-Wunused-function -Wunused-value,)
KBUILD_CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
KBUILD_CFLAGS += $(call cc-option,-Wno-format-security,)
# warn about C99 declaration after statement
KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
# If you want to add more -Wsomething above, make sure that it is
# still possible to build bbox without warnings.
ifeq ($(CONFIG_WERROR),y)
KBUILD_CFLAGS += $(call cc-option,-Werror,)
## TODO:
## gcc version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC) is a PITA:
## const char *ptr; ... off_t v = *(off_t*)ptr; -> BOOM
## and no easy way to convince it to shut the hell up.
## We have a lot of such things all over the place.
## Classic *(off_t*)(void*)ptr does not work,
## and I am unwilling to do crazy gcc specific ({ void *ppp = ...; })
## stuff in macros. This would obfuscate the code too much.
## Maybe try __attribute__((__may_alias__))?
#KBUILD_CFLAGS += $(call cc-ifversion, -eq, 0404, -fno-strict-aliasing)
endif
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
KBUILD_CFLAGS += $(call cc-option,-fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
# -fno-guess-branch-probability: prohibit pseudo-random guessing
# of branch probabilities (hopefully makes bloatcheck more stable):
KBUILD_CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
KBUILD_CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,)
KBUILD_CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,)
# Defeat .eh_frame bloat (gcc 4.6.3 x86-32 defconfig: 20% smaller binary):
KBUILD_CFLAGS += $(call cc-option,-fno-unwind-tables,)
KBUILD_CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
# FIXME: These warnings are at least partially to be concerned about and should
# be fixed..
#KBUILD_CFLAGS += $(call cc-option,-Wconversion,)
ifneq ($(CONFIG_DEBUG),y)
KBUILD_CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
else
KBUILD_CFLAGS += $(call cc-option,-g,)
#KBUILD_CFLAGS += "-D_FORTIFY_SOURCE=2"
ifeq ($(CONFIG_DEBUG_PESSIMIZE),y)
KBUILD_CFLAGS += $(call cc-option,-O0,)
else
KBUILD_CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
endif
endif
# Usage: $(eval $(call pkg_check_modules,VARIABLE-PREFIX,MODULES))
define pkg_check_modules
$(1)_CFLAGS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --cflags $(2))
$(1)_LIBS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs $(2))
endef
ifeq ($(CONFIG_STATIC),y)
CFLAGS_swupdate += -static
PKG_CONFIG_FLAGS += --static
endif
ifneq ($(CONFIG_EXTRA_CFLAGS),)
KBUILD_CFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_CFLAGS)))
#"))
endif
# Note: both "" (string consisting of two quote chars) and empty string
# are possible, and should be skipped below.
ifneq ($(subst "",,$(CONFIG_SYSROOT)),)
KBUILD_CFLAGS += --sysroot=$(CONFIG_SYSROOT)
export SYSROOT=$(CONFIG_SYSROOT)
endif
# Links always pthread
LDLIBS += pthread
# lua
ifneq ($(CONFIG_LUA),)
LDLIBS += lua${LUAVERSION} dl m
LDFLAGS_swupdate += -Wl,-E
endif
# Image downloading support
ifneq ($(CONFIG_DOWNLOAD),)
LDLIBS += curl
endif
# libconfig is alwasy compiled
ifeq ($(CONFIG_LIBCONFIG),y)
LDLIBS += config
endif
# libarchive
ifeq ($(CONFIG_ARCHIVE),y)
LDLIBS += archive
endif
# json-c
ifeq ($(CONFIG_JSON),y)
LDLIBS += json-c
endif
# mongoose / webserver
ifneq ($(CONFIG_WEBSERVER),)
ifneq ($(CONFIG_MONGOOSESSL),)
KBUILD_CFLAGS += -DNO_SSL_DL
LDLIBS += crypto ssl
else
KBUILD_CFLAGS += -DNO_SSL
endif
ifneq ($(CONFIG_MONGOOSELUA),)
KBUILD_CFLAGS += -DUSE_LUA
endif
ifneq ($(CONFIG_MONGOOSEIPV6),)
KBUILD_CFLAGS += -DUSE_IPV6
endif
endif
# MTD
ifeq ($(CONFIG_MTD),y)
LDLIBS += ubi mtd
endif
ifeq ($(CONFIG_GUNZIP),y)
LDLIBS += z
endif
ifeq ($(CONFIG_UBOOT),y)
LDLIBS += z
ifeq ($(CONFIG_UBOOT_LIBRARY),y)
LDLIBS += ubootenv
endif
endif
# If a flat binary should be built, CFLAGS_swupdate="-elf2flt"
# env var should be set for make invocation.
# Here we check whether CFLAGS_swupdate indeed contains that flag.
# (For historical reasons, we also check LDFLAGS, which doesn't
# seem to be entirely correct variable to put "-elf2flt" into).
W_ELF2FLT = -elf2flt
ifneq (,$(findstring $(W_ELF2FLT),$(LDFLAGS) $(CFLAGS_swupdate)))
SKIP_STRIP = y
endif
ifneq ($(CONFIG_EXTRA_LDFLAGS),)
EXTRA_LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
#"))
endif
ifneq ($(CONFIG_EXTRA_LDLIBS),)
LDLIBS += $(strip $(subst ",,$(CONFIG_EXTRA_LDLIBS)))
#"))
endif
# Busybox is a stack-fatty so make sure we increase default size
# TODO: use "make stksizes" to find & fix big stack users
# (we stole scripts/checkstack.pl from the kernel... thanks guys!)
# Reduced from 20k to 16k in 1.9.0.
FLTFLAGS += -s 16000