2 # Copyright (C) 2004 Christophe Varoqui, <christophe.varoqui@opensvc.com>
6 # Allow to force some libraries to be used statically. (Uncomment one of the
7 # following lines or define the values when calling make.)
10 # WITH_LOCAL_LIBSYSFS = 1
12 # Uncomment to disable RADOS support (e.g. if rados headers are missing).
15 # Uncomment to disable libdmmp support
18 # Uncomment to disable dmevents polling support
19 # ENABLE_DMEVENTS_POLL = 0
26 ifeq ($(shell test -d /lib64 && echo 1),1)
34 ifeq ($(shell test -L /var/run -o ! -d /var/run && echo 1),1)
42 ifeq ($(shell systemctl --version > /dev/null 2>&1 && echo 1), 1)
43 SYSTEMD = $(shell systemctl --version 2> /dev/null | sed -n 's/systemd \([0-9]*\)/\1/p')
52 exec_prefix = $(prefix)
53 usr_prefix = $(prefix)
54 bindir = $(exec_prefix)/sbin
55 libudevdir = $(prefix)/$(SYSTEMDPATH)/udev
56 udevrulesdir = $(libudevdir)/rules.d
57 multipathdir = $(TOPDIR)/libmultipath
58 man8dir = $(prefix)/usr/share/man/man8
59 man5dir = $(prefix)/usr/share/man/man5
60 man3dir = $(prefix)/usr/share/man/man3
61 syslibdir = $(prefix)/$(LIB)
62 usrlibdir = $(usr_prefix)/$(LIB)
63 libdir = $(prefix)/$(LIB)/multipath
64 unitdir = $(prefix)/$(SYSTEMDPATH)/systemd/system
65 mpathpersistdir = $(TOPDIR)/libmpathpersist
66 mpathcmddir = $(TOPDIR)/libmpathcmd
67 thirdpartydir = $(TOPDIR)/third-party
68 libdmmpdir = $(TOPDIR)/libdmmp
69 includedir = $(prefix)/usr/include
70 pkgconfdir = $(usrlibdir)/pkgconfig
75 INSTALL_PROGRAM = install
77 # $(call TEST_CC_OPTION,option,fallback)
78 # Test if the C compiler supports the option.
79 # Evaluates to "option" if yes, and "fallback" otherwise.
80 TEST_CC_OPTION = $(shell \
81 if echo 'int main(void){return 0;}' | $(CC) -o /dev/null -c "$(1)" -xc - >/dev/null 2>&1; \
88 STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
89 ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)
91 OPTFLAGS = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \
92 -Werror=implicit-function-declaration -Werror=format-security \
93 -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered \
94 -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
95 -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \
96 --param=ssp-buffer-size=4
98 CFLAGS := $(OPTFLAGS) -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
100 BIN_CFLAGS = -fPIE -DPIE
102 SHARED_FLAGS = -shared
103 LDFLAGS = -Wl,-z,relro -Wl,-z,now
106 # Check whether a function with name $1 has been declared in header file $2.
107 check_func = $(shell \
108 if grep -Eq "^[^[:blank:]]+[[:blank:]]+$1[[:blank:]]*(.*)*" "$2"; then \
115 echo 1>&2 "Checking for $1 in $2 ... $$status"; \
119 # Checker whether a file with name $1 exists
120 check_file = $(shell \
121 if [ -f "$1" ]; then \
128 echo 1>&2 "Checking if $1 exists ... $$status"; \
133 @echo building $@ because of $?
134 $(CC) $(CFLAGS) -c -o $@ $<