forked from sbabic/swupdate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.flags
299 lines (254 loc) · 8.64 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# SPDX-FileCopyrightText: 2013 Stefano Babic <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-only
# ==========================================================================
# Build system
# ==========================================================================
SWU_DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SWU_VER = $(shell git -C $(SWU_DIR) describe --tags --always --dirty)
export SWU_VER
SKIP_STRIP ?= n
ifneq ($(CC),clang)
GCC_MAJOR = $(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
GCC_MINOR = $(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)
GCC_VERSION = $(GCC_MAJOR)$(GCC_MINOR)
endif
# -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=\"$(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,)
ifneq ($(CC),clang)
ifeq ($(shell test $(GCC_VERSION) -ge 70 && echo 1), 1)
KBUILD_CFLAGS += $(call cc-option,-Wno-format-truncation,)
endif
endif
# 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)
LUAVER := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --modversion ${CONFIG_LUAPKG} | cut -d'.' -f1,2)
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_START="_binary_$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE))))_start"
KBUILD_CPPFLAGS += -DEMBEDDED_LUA_SRC_END="_binary_$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE))))_end"
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
ifeq ($(CONFIG_SSL_IMPL_OPENSSL),y)
LDLIBS += crypto ssl
endif
ifeq ($(CONFIG_SSL_IMPL_WOLFSSL),y)
KBUILD_CPPFLAGS += -DOPENSSL_ALL
LDLIBS += wolfssl
else ifeq ($(CONFIG_PKCS11),y)
LDLIBS += wolfssl
endif
ifeq ($(CONFIG_PKCS11),y)
LDLIBS += p11-kit
endif
ifeq ($(CONFIG_SSL_IMPL_MBEDTLS),y)
LDLIBS += mbedcrypto mbedtls mbedx509
endif
# MTD
ifeq ($(CONFIG_MTD),y)
LDLIBS += ubi mtd
endif
ifeq ($(CONFIG_GUNZIP),y)
LDLIBS += z
endif
ifeq ($(CONFIG_ZSTD),y)
LDLIBS += zstd
endif
ifeq ($(CONFIG_DISKPART),y)
LDLIBS += fdisk
endif
ifeq ($(CONFIG_DISKFORMAT_HANDLER),y)
LDLIBS += blkid
endif
ifeq ($(CONFIG_EXT_FILESYSTEM),y)
LDLIBS += ext2fs uuid blkid
endif
ifeq ($(CONFIG_BTRFS_FILESYSTEM_USELIBMKFS),y)
LDLIBS += mkfsbtrfs
endif
ifeq ($(CONFIG_BTRFS_FILESYSTEM),y)
LDLIBS += btrfsutil udev
endif
ifeq ($(CONFIG_UNIQUEUUID),y)
LDLIBS += blkid
endif
ifeq ($(CONFIG_RDIFFHANDLER),y)
LDLIBS += rsync
endif
ifeq ($(CONFIG_REMOTE_HANDLER),y)
LDLIBS += zmq
endif
ifeq ($(CONFIG_UCFWHANDLER),y)
LDLIBS += gpiod
endif
ifeq ($(CONFIG_BOOTLOADER_STATIC_LINKED),y)
ifeq ($(CONFIG_UBOOT),y)
LDLIBS += ubootenv
endif
ifeq ($(CONFIG_BOOTLOADER_EBG),y)
LDLIBS += ebgenv
endif
else
ifeq ($(CONFIG_UBOOT),y)
LDLIBS += dl
endif
ifeq ($(CONFIG_BOOTLOADER_EBG),y)
LDLIBS += dl
endif
endif
ifeq ($(CONFIG_SYSTEMD),y)
LDLIBS += systemd
endif
ifeq ($(CONFIG_BOOTLOADER_DEFAULT_NONE),y)
KBUILD_CPPFLAGS += -DBOOTLOADER_DEFAULT="none"
else ifeq ($(CONFIG_BOOTLOADER_DEFAULT_GRUB),y)
KBUILD_CPPFLAGS += -DBOOTLOADER_DEFAULT="grub"
else ifeq ($(CONFIG_BOOTLOADER_DEFAULT_UBOOT),y)
KBUILD_CPPFLAGS += -DBOOTLOADER_DEFAULT="uboot"
else ifeq ($(CONFIG_BOOTLOADER_DEFAULT_EBG),y)
KBUILD_CPPFLAGS += -DBOOTLOADER_DEFAULT="ebg"
else
KBUILD_CPPFLAGS += -DBOOTLOADER_DEFAULT="none"
endif
ifneq ($(CONFIG_SURICATTA),)
ifneq ($(CONFIG_SURICATTA_LUA),)
ifneq ($(CONFIG_EMBEDDED_SURICATTA_LUA),)
ifneq ($(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE),)
LDFLAGS_swupdate += -Wl,--format=binary -Wl,$(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE) -Wl,--format=default
KBUILD_CPPFLAGS += -DEMBEDDED_SURICATTA_LUA_SOURCE_START="_binary_$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE))))_start"
KBUILD_CPPFLAGS += -DEMBEDDED_SURICATTA_LUA_SOURCE_END="_binary_$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE))))_end"
endif
endif
endif
endif
# SWU forwarder
ifneq ($(CONFIG_SWUFORWARDER_HANDLER),)
LDLIBS += websockets uriparser
endif
# Delta Update
ifneq ($(CONFIG_DELTA),)
LDLIBS += zck
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