Due to POSIX style ioctl() declaration in MUSL, arm-trusted-firmware-tools
fails to build on MUSL based hosts with -Werror and -pedantic GCC switches
enabled. Alpine Linux, for example, fixes this with an unconditional cast
to "int". This commit tries to apply this cast only for MUSL based build
hosts, while keeping the type as-is where the cast isn't needed. Maybe
overkill, but cleaner than an unconditional cast.
Fixes: #13339
Signed-off-by: Shine <4c.fce2@proton.me>
Link: https://github.com/openwrt/openwrt/pull/21957
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
BUILDONLY:=1
endef
+ifeq ($(shell uname -s),Linux)
+ HOST_MUSL_FLAG:=$(shell [ "$$(2>&1 ldd --version | head -n 1 | cut -d ' ' -f1)" = "musl" ] && echo " -D__MUSL__")
+else
+ HOST_MUSL_FLAG:=
+endif
+
define Host/Compile
$(MAKE) -C \
$(HOST_BUILD_DIR)/tools/fiptool \
- CPPFLAGS="$(HOST_CFLAGS)" \
+ CPPFLAGS="$(HOST_CFLAGS)$(HOST_MUSL_FLAG)" \
LDFLAGS="$(HOST_LDFLAGS)" \
OPENSSL_DIR="$(STAGING_DIR_HOST)"
endef
--- /dev/null
+--- a/tools/fiptool/fiptool.c
++++ b/tools/fiptool/fiptool.c
+@@ -318,7 +318,11 @@
+
+ #ifdef BLKGETSIZE64
+ if ((st.st_mode & S_IFBLK) != 0)
++#ifdef __MUSL__
++ if (ioctl(fileno(fp), (int)BLKGETSIZE64, &st_size) == -1)
++#else
+ if (ioctl(fileno(fp), BLKGETSIZE64, &st_size) == -1)
++#endif
+ log_err("ioctl %s", filename);
+ #endif
+