forked from sbabic/swupdate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.flags
223 lines (193 loc) · 6.54 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# ==========================================================================
# 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,)
# 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)
ifneq ($(CC),clang)
KBUILD_CFLAGS += $(call cc-option, -finline-limit=0,)
endif
KBUILD_CFLAGS += $(call cc-option,-fno-builtin-strlen -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,)
ifneq ($(CC),clang)
KBUILD_CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -static-libgcc,)
endif
# 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))
$(1)_LDLIBS := $(patsubst -l%,%,$(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs-only-l $(2)))
endef
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),)
LDFLAGS_swupdate += -Wl,-E
$(eval $(call pkg_check_modules, LUABUILD, ${CONFIG_LUAPKG}))
KBUILD_CFLAGS += $(LUABUILD_CFLAGS)
KBUILD_LIBS += $(LUABUILD_LIBS)
LDLIBS += $(LUABUILD_LDLIBS)
endif
ifeq ($(CONFIG_LUA),y)
ifeq ($(CONFIG_HANDLER_IN_LUA),y)
ifeq ($(CONFIG_EMBEDDED_LUA_HANDLER),y)
ifneq ($(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE),)
LDFLAGS_swupdate += -Wl,--format=binary -Wl,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE) -Wl,--format=default
KBUILD_CPPFLAGS += -DEMBEDDED_LUA_SRC="_binary_$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE))))_start"
endif
endif
endif
endif
# Image downloading support
ifneq ($(CONFIG_CURL),)
LDLIBS += curl
endif
# libconfig is always 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
# signed images require openssl (digest)
ifneq ($(CONFIG_HASH_VERIFY),)
LDLIBS += crypto ssl
endif
# signed images require openssl (digest)
ifneq ($(CONFIG_ENCRYPTED_IMAGES),)
LDLIBS += crypto ssl
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_REMOTE_HANDLER),y)
LDLIBS += zmq
endif
ifeq ($(CONFIG_UBOOT),y)
LDLIBS += z ubootenv
endif
ifeq ($(CONFIG_SYSTEMD),y)
LDLIBS += systemd
endif
# suricatta
ifneq ($(CONFIG_SURICATTA),)
ifneq ($(CONFIG_SURICATTA_SSL),)
ifeq ($(strip $(findstring crypto,$(LDLIBS))),)
LDLIBS += crypto ssl
endif
endif
ifneq ($(CONFIG_SURICATTA_HAWKBIT),)
ifeq ($(strip $(findstring json-c,$(LDLIBS))),)
LDLIBS += json-c
endif
ifeq ($(strip $(findstring curl,$(LDLIBS))),)
LDLIBS += curl
endif
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