libmultipath: fix marginal paths queueing errors
[multipath-tools/.git] / Makefile.inc
1 #
2 # Copyright (C) 2004 Christophe Varoqui, <christophe.varoqui@opensvc.com>
3 #
4
5 #
6 # Allow to force some libraries to be used statically. (Uncomment one of the
7 # following lines or define the values when calling make.)
8 #
9 # WITH_LOCAL_LIBDM      = 1
10 # WITH_LOCAL_LIBSYSFS   = 1
11 #
12 # Uncomment to disable libdmmp support
13 # ENABLE_LIBDMMP = 0
14 #
15 # Uncomment to disable dmevents polling support
16 # ENABLE_DMEVENTS_POLL = 0
17
18 ifeq ($(TOPDIR),)
19         TOPDIR  = ..
20 endif
21
22 ifndef LIB
23         ifeq ($(shell test -d /lib64 && echo 1),1)
24                 LIB=lib64
25         else
26                 LIB=lib
27         endif
28 endif
29
30 ifndef RUN
31         ifeq ($(shell test -L /var/run -o ! -d /var/run && echo 1),1)
32                 RUN=run
33         else
34                 RUN=var/run
35         endif
36 endif
37
38 ifndef SYSTEMD
39         ifeq ($(shell systemctl --version > /dev/null 2>&1 && echo 1), 1)
40                 SYSTEMD = $(shell systemctl --version 2> /dev/null |  sed -n 's/systemd \([0-9]*\)/\1/p')
41         endif
42 endif
43
44 ifndef SYSTEMDPATH
45         SYSTEMDPATH=usr/lib
46 endif
47
48 prefix          =
49 exec_prefix     = $(prefix)
50 usr_prefix      = $(prefix)
51 bindir          = $(exec_prefix)/sbin
52 libudevdir      = $(prefix)/$(SYSTEMDPATH)/udev
53 udevrulesdir    = $(libudevdir)/rules.d
54 multipathdir    = $(TOPDIR)/libmultipath
55 man8dir         = $(prefix)/usr/share/man/man8
56 man5dir         = $(prefix)/usr/share/man/man5
57 man3dir         = $(prefix)/usr/share/man/man3
58 syslibdir       = $(prefix)/$(LIB)
59 usrlibdir       = $(usr_prefix)/$(LIB)
60 libdir          = $(prefix)/$(LIB)/multipath
61 unitdir         = $(prefix)/$(SYSTEMDPATH)/systemd/system
62 mpathpersistdir = $(TOPDIR)/libmpathpersist
63 mpathcmddir     = $(TOPDIR)/libmpathcmd
64 thirdpartydir   = $(TOPDIR)/third-party
65 libdmmpdir      = $(TOPDIR)/libdmmp
66 nvmedir         = $(TOPDIR)/libmultipath/nvme
67 includedir      = $(prefix)/usr/include
68 pkgconfdir      = $(usrlibdir)/pkgconfig
69
70 GZIP            = gzip -9 -c
71 RM              = rm -f
72 LN              = ln -sf
73 INSTALL_PROGRAM = install
74
75 # $(call TEST_CC_OPTION,option,fallback)
76 # Test if the C compiler supports the option.
77 # Evaluates to "option" if yes, and "fallback" otherwise.
78 TEST_CC_OPTION = $(shell \
79         if echo 'int main(void){return 0;}' | $(CC) -o /dev/null -c "$(1)" -xc - >/dev/null 2>&1; \
80         then \
81                 echo "$(1)"; \
82         else \
83                 echo "$(2)"; \
84         fi)
85
86 STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
87 ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)
88
89 OPTFLAGS        = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \
90                   -Werror=implicit-function-declaration -Werror=format-security \
91                   -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered \
92                   -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
93                   -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \
94                   --param=ssp-buffer-size=4
95
96 CFLAGS          := $(OPTFLAGS) -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
97                    -MMD -MP $(CFLAGS)
98 BIN_CFLAGS      = -fPIE -DPIE
99 LIB_CFLAGS      = -fPIC
100 SHARED_FLAGS    = -shared
101 LDFLAGS         = -Wl,-z,relro -Wl,-z,now
102 BIN_LDFLAGS     = -pie
103
104 # Check whether a function with name $1 has been declared in header file $2.
105 check_func = $(shell \
106         if grep -Eq "^[^[:blank:]]+[[:blank:]]+$1[[:blank:]]*(.*)*" "$2"; then \
107                 found=1; \
108                 status="yes"; \
109         else \
110                 found=0; \
111                 status="no"; \
112         fi; \
113         echo 1>&2 "Checking for $1 in $2 ... $$status"; \
114         echo "$$found" \
115         )
116
117 # Checker whether a file with name $1 exists
118 check_file = $(shell \
119         if [ -f "$1" ]; then \
120                 found=1; \
121                 status="yes"; \
122         else \
123                 found=0; \
124                 status="no"; \
125         fi; \
126         echo 1>&2 "Checking if $1 exists ... $$status"; \
127         echo "$$found" \
128         )
129
130 %.o:    %.c
131         @echo building $@ because of $?
132         $(CC) $(CFLAGS) -c -o $@ $<