Makefiles: Fix function availability checks
authorBart Van Assche <bart.vanassche@sandisk.com>
Fri, 18 Nov 2016 19:52:31 +0000 (11:52 -0800)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Sun, 20 Nov 2016 13:39:15 +0000 (14:39 +0100)
The current implementation of the code that checks for function
presence is not correct because it checks for a prefix match only.
Introduce a function that checks for the exact function name.
Additionally, report whether or not the function has been found.
An example of the output produced by this function if 'make' is
run:

Checking for dm_task_no_flush in /usr/include/libdevmapper.h ... yes
Checking for dm_task_set_cookie in /usr/include/libdevmapper.h ... yes
Checking for udev_monitor_set_receive_buffer_size in /usr/include/libudev.h ... yes
Checking for dm_task_deferred_remove in /usr/include/libdevmapper.h ... yes

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Makefile.inc
kpartx/Makefile
libmultipath/Makefile

index 1cc8f44..e7f4e05 100644 (file)
@@ -69,5 +69,19 @@ OPTFLAGS     = -O2 -g -pipe -Wall -Wextra -Wformat=2 \
 CFLAGS         = $(OPTFLAGS) -fPIC -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\"
 SHARED_FLAGS   = -shared
 
+# Check whether a function with name $1 has been declared in header file $2.
+check_func =                                                                  \
+    $(shell                                                                   \
+       if grep -Eq "^[^[:blank:]]+[[:blank:]]+$1[[:blank:]]*(.*)*" "$2"; then \
+          found=1;                                                            \
+          status="yes";                                                       \
+       else                                                                   \
+          found=0;                                                            \
+          status="no";                                                        \
+       fi;                                                                    \
+       echo 1>&2 "Checking for $1 in $2 ... $$status";                        \
+       echo "$$found"                                                         \
+    )
+
 %.o:   %.c
        $(CC) $(CFLAGS) -c -o $@ $<
index e8a59f2..9441a2b 100644 (file)
@@ -7,9 +7,7 @@ CFLAGS += -I. -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
 
 LIBDEPS += -ldevmapper
 
-LIBDM_API_COOKIE = $(shell grep -Ecs '^[a-z]*[[:space:]]+dm_task_set_cookie' /usr/include/libdevmapper.h)
-
-ifneq ($(strip $(LIBDM_API_COOKIE)),0)
+ifneq ($(call check_func,dm_task_set_cookie,/usr/include/libdevmapper.h),0)
        CFLAGS += -DLIBDM_API_COOKIE
 endif
 
index 495cebe..a11e483 100644 (file)
@@ -20,27 +20,19 @@ ifdef SYSTEMD
        endif
 endif
 
-LIBDM_API_FLUSH = $(shell grep -Ecs '^[a-z]*[[:space:]]+dm_task_no_flush' /usr/include/libdevmapper.h)
-
-ifneq ($(strip $(LIBDM_API_FLUSH)),0)
+ifneq ($(call check_func,dm_task_no_flush,/usr/include/libdevmapper.h),0)
        CFLAGS += -DLIBDM_API_FLUSH -D_GNU_SOURCE
 endif
 
-LIBDM_API_COOKIE = $(shell grep -Ecs '^[a-z]*[[:space:]]+dm_task_set_cookie' /usr/include/libdevmapper.h)
-
-ifneq ($(strip $(LIBDM_API_COOKIE)),0)
+ifneq ($(call check_func,dm_task_set_cookie,/usr/include/libdevmapper.h),0)
        CFLAGS += -DLIBDM_API_COOKIE
 endif
 
-LIBUDEV_API_RECVBUF = $(shell grep -Ecs '^[a-z]*[[:space:]]+udev_monitor_set_receive_buffer_size' /usr/include/libudev.h)
-
-ifneq ($(strip $(LIBUDEV_API_RECVBUF)),0)
+ifneq ($(call check_func,udev_monitor_set_receive_buffer_size,/usr/include/libudev.h),0)
        CFLAGS += -DLIBUDEV_API_RECVBUF
 endif
 
-LIBDM_API_DEFERRED = $(shell grep -Ecs '^[a-z]*[[:space:]]+dm_task_deferred_remove' /usr/include/libdevmapper.h)
-
-ifneq ($(strip $(LIBDM_API_DEFERRED)),0)
+ifneq ($(call check_func,dm_task_deferred_remove,/usr/include/libdevmapper.h),0)
        CFLAGS += -DLIBDM_API_DEFERRED
 endif