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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
# SPDX-FileCopyrightText: 2013 Stefano Babic <stefano.babic@swupdate.org>
#
# SPDX-License-Identifier: GPL-2.0-only
# ==========================================================================
# Build system
# ==========================================================================
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
# Generate version
KBUILD_CPPFLAGS += -DVERSION=$(VERSION)
KBUILD_CPPFLAGS += -DVERSION_PATCHLEVEL=$(PATCHLEVEL)
KBUILD_CPPFLAGS += -DVERSION_SUBLEVEL=$(SUBLEVEL)
KBUILD_CPPFLAGS += -DVERSION_EXTRAVERSION=$(shell cd $(srctree) && ver=$$(./scripts/gen_extraversion); [ -n "$$ver" ] && echo -$$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)))
$(1)_VERSION := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --modversion $(2) | cut -d'.' -f1,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
# Always link pthread, libubootenv, and json-c
LDLIBS += pthread ubootenv json-c
# lua
ifneq ($(CONFIG_LUA),)
LDFLAGS_swupdate += -Wl,-E
ifeq ($(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --exists ${CONFIG_LUAPKG}; echo $$?), 0)
$(eval $(call pkg_check_modules, LUABUILD, ${CONFIG_LUAPKG}))
else ifeq ($(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --exists lua; echo $$?), 0)
$(eval $(call pkg_check_modules, LUABUILD, lua))
endif
KBUILD_CFLAGS += $(LUABUILD_CFLAGS)
KBUILD_LIBS += $(LUABUILD_LIBS)
LDLIBS += $(LUABUILD_LDLIBS)
LUAVER := $(LUABUILD_VERSION)
endif
ifeq ($(CONFIG_LUA),y)
ifeq ($(CONFIG_EMBEDDED_LUA_HANDLER),y)
ifneq ($(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE),)
# Strip quotes from filename
CONFIG_EMBEDDED_LUA_HANDLER_SOURCE := $(patsubst "%",%,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE))
ifeq ($(findstring /,$(word 1,$(subst /, /,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE)))),)
# It's not an absolute path, assume it's relative to $(srcdir)
ifeq ($(realpath $(srctree)/$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE)),)
$(error File specified in CONFIG_EMBEDDED_LUA_HANDLER_SOURCE=$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE) not found)
endif
CONFIG_EMBEDDED_LUA_HANDLER_SOURCE := $(realpath $(srctree)/$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE))
endif
LDFLAGS_swupdate += -Wl,--format=binary -Wl,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE) -Wl,--format=default
KBUILD_CPPFLAGS += -DEMBEDDED_LUA_SRC_START="_binary_$(strip $(subst -,_,$(subst +,_,$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE)))))))_start"
KBUILD_CPPFLAGS += -DEMBEDDED_LUA_SRC_END="_binary_$(strip $(subst -,_,$(subst +,_,$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE)))))))_end"
endif
endif
endif
# Image downloading support
ifneq ($(CONFIG_CURL),)
LDLIBS += curl
endif
# libconfig is always compiled
LDLIBS += config
# libarchive
ifeq ($(CONFIG_ARCHIVE),y)
LDLIBS += archive
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_SSL_IMPL_MBEDTLS),y)
LDLIBS += mbedcrypto mbedtls mbedx509
endif
ifeq ($(CONFIG_SSL_IMPL_GPGME),y)
LDLIBS += gpgme
endif
ifeq ($(CONFIG_PKCS11),y)
$(eval $(call pkg_check_modules, P11BUILD, "p11-kit-1"))
KBUILD_CFLAGS += $(P11BUILD_CFLAGS)
KBUILD_LIBS += $(P11BUILD_LIBS)
LDLIBS += p11-kit
endif
# MTD
ifeq ($(CONFIG_MTD),y)
LDLIBS += ubi mtd
endif
ifeq ($(CONFIG_GUNZIP),y)
LDLIBS += z
endif
ifeq ($(CONFIG_XZ),y)
LDLIBS += lzma
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_BOOTLOADER_EBG),y)
LDLIBS += ebgenv
endif
ifeq ($(CONFIG_BOOTLOADER_CBOOT),y)
LDLIBS += tegra-boot-tools
endif
else
ifeq ($(CONFIG_UBOOT),y)
LDLIBS += dl
endif
ifeq ($(CONFIG_BOOTLOADER_EBG),y)
LDLIBS += dl
endif
ifeq ($(CONFIG_BOOTLOADER_CBOOT),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 ifeq ($(CONFIG_BOOTLOADER_DEFAULT_CBOOT),y)
KBUILD_CPPFLAGS += -DBOOTLOADER_DEFAULT="cboot"
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),)
# Strip quotes from filename
CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE := $(patsubst "%",%,$(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE))
ifeq ($(findstring /,$(word 1,$(subst /, /,$(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE)))),)
# It's not an absolute path, assume it's relative to $(srcdir)
ifeq ($(realpath $(srctree)/$(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE)),)
$(error File specified in CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE=$(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE) not found)
endif
CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE := $(realpath $(srctree)/$(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE))
endif
LDFLAGS_swupdate += -Wl,--format=binary -Wl,$(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE) -Wl,--format=default
KBUILD_CPPFLAGS += -DEMBEDDED_SURICATTA_LUA_SOURCE_START="_binary_$(strip $(subst -,_,$(subst +,_,$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_SURICATTA_LUA_SOURCE)))))))_start"
KBUILD_CPPFLAGS += -DEMBEDDED_SURICATTA_LUA_SOURCE_END="_binary_$(strip $(subst -,_,$(subst +,_,$(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
|