multipath-tools: fix compilation with gcc < 4.9
[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 RADOS support (e.g. if rados headers are missing).
13 # ENABLE_RADOS = 0
14 #
15 # Uncomment to disable libdmmp support
16 # ENABLE_LIBDMMP = 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 bindir          = $(exec_prefix)/sbin
51 libudevdir      = $(prefix)/$(SYSTEMDPATH)/udev
52 udevrulesdir    = $(libudevdir)/rules.d
53 multipathdir    = $(TOPDIR)/libmultipath
54 man8dir         = $(prefix)/usr/share/man/man8
55 man5dir         = $(prefix)/usr/share/man/man5
56 man3dir         = $(prefix)/usr/share/man/man3
57 syslibdir       = $(prefix)/$(LIB)
58 libdir          = $(prefix)/$(LIB)/multipath
59 unitdir         = $(prefix)/$(SYSTEMDPATH)/systemd/system
60 mpathpersistdir = $(TOPDIR)/libmpathpersist
61 mpathcmddir     = $(TOPDIR)/libmpathcmd
62 thirdpartydir   = $(TOPDIR)/third-party
63 libdmmpdir      = $(TOPDIR)/libdmmp
64 includedir      = $(prefix)/usr/include
65 pkgconfdir      = $(prefix)/$(LIB)/pkgconfig
66
67 GZIP            = gzip -9 -c
68 RM              = rm -f
69 LN              = ln -sf
70 INSTALL_PROGRAM = install
71
72 # $(call TEST_CC_OPTION,option,fallback)
73 # Test if the C compiler supports the option.
74 # Evaluates to "option" if yes, and "fallback" otherwise.
75 TEST_CC_OPTION = $(shell \
76         if echo 'int main(void){return 0;}' | $(CC) -o /dev/null -c "$(1)" -xc - &>/dev/null; \
77         then \
78                 echo "$(1)"; \
79         else \
80                 echo "$(2)"; \
81         fi)
82
83 STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
84
85 OPTFLAGS        = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \
86                   -Werror=implicit-function-declaration -Werror=format-security \
87                   -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered \
88                   -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \
89                   --param=ssp-buffer-size=4
90
91 CFLAGS          = $(OPTFLAGS) -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\"
92 BIN_CFLAGS      = -fPIE -DPIE
93 LIB_CFLAGS      = -fPIC
94 SHARED_FLAGS    = -shared
95 LDFLAGS         = -Wl,-z,relro -Wl,-z,now
96 BIN_LDFLAGS     = -pie
97
98 # Check whether a function with name $1 has been declared in header file $2.
99 check_func =                                                                   \
100     $(shell                                                                    \
101         if grep -Eq "^[^[:blank:]]+[[:blank:]]+$1[[:blank:]]*(.*)*" "$2"; then \
102            found=1;                                                            \
103            status="yes";                                                       \
104         else                                                                   \
105            found=0;                                                            \
106            status="no";                                                        \
107         fi;                                                                    \
108         echo 1>&2 "Checking for $1 in $2 ... $$status";                        \
109         echo "$$found"                                                         \
110     )
111
112 %.o:    %.c
113         $(CC) $(CFLAGS) -c -o $@ $<