From 49901079d4567e58fe8c143909d121ec354c87f0 Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Thu, 24 Jun 2021 10:04:10 +0200 Subject: [PATCH] common.mak: Introduce user-defined function check_header_prereq() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new user-defined function allows to check for C headers in make's conditional statements. Example: ifeq ($(call check_header_prereq,"systemd/sd-daemon.h"),yes) $(warning "systemd support enabled") else $(warning "systemd support disabled") endif Signed-off-by: Alexander Egorenkov Acked-by: Jan Höppner Signed-off-by: Jan Höppner --- common.mak | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common.mak b/common.mak index e6fd2778..8ddb571a 100644 --- a/common.mak +++ b/common.mak @@ -111,6 +111,20 @@ ifeq ("${ASAN}","1") DEFAULT_LDFLAGS += -fsanitize=address endif +# +# Check for header prerequisite +# +# $1: Name of include file to check +# $2: Additional compiler & linker options (optional) +# +# Returns "yes" on success and nothing otherwise +# +define check_header_prereq +$(shell printf "#include <%s>\n int main(void) {return 0;}" $1 | \ + ( $(CC) $(filter-out --coverage, $(ALL_CFLAGS)) $(ALL_CPPFLAGS) \ + $2 -o /dev/null -xc - ) >/dev/null 2>&1 && echo -n yes) +endef + # # Check for build dependency #