Imported Upstream version 0.7.8
[platform/upstream/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 # Uncomment to disable dmevents polling support
19 # ENABLE_DMEVENTS_POLL = 0
20
21 ifeq ($(TOPDIR),)
22         TOPDIR  = ..
23 endif
24
25 ifndef LIB
26         ifeq ($(shell test -d /lib64 && echo 1),1)
27                 LIB=lib64
28         else
29                 LIB=lib
30         endif
31 endif
32
33 ifndef RUN
34         ifeq ($(shell test -L /var/run -o ! -d /var/run && echo 1),1)
35                 RUN=run
36         else
37                 RUN=var/run
38         endif
39 endif
40
41 ifndef SYSTEMD
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')
44         endif
45 endif
46
47 ifndef SYSTEMDPATH
48         SYSTEMDPATH=usr/lib
49 endif
50
51 prefix          =
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
71
72 GZIP            = gzip -9 -c
73 RM              = rm -f
74 LN              = ln -sf
75 INSTALL_PROGRAM = install
76
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; \
82         then \
83                 echo "$(1)"; \
84         else \
85                 echo "$(2)"; \
86         fi)
87
88 STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
89 ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)
90
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
97
98 CFLAGS          := $(OPTFLAGS) -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
99                    -MMD -MP $(CFLAGS)
100 BIN_CFLAGS      = -fPIE -DPIE
101 LIB_CFLAGS      = -fPIC
102 SHARED_FLAGS    = -shared
103 LDFLAGS         = -Wl,-z,relro -Wl,-z,now
104 BIN_LDFLAGS     = -pie
105
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 \
109                 found=1; \
110                 status="yes"; \
111         else \
112                 found=0; \
113                 status="no"; \
114         fi; \
115         echo 1>&2 "Checking for $1 in $2 ... $$status"; \
116         echo "$$found" \
117         )
118
119 # Checker whether a file with name $1 exists
120 check_file = $(shell \
121         if [ -f "$1" ]; then \
122                 found=1; \
123                 status="yes"; \
124         else \
125                 found=0; \
126                 status="no"; \
127         fi; \
128         echo 1>&2 "Checking if $1 exists ... $$status"; \
129         echo "$$found" \
130         )
131
132 %.o:    %.c
133         @echo building $@ because of $?
134         $(CC) $(CFLAGS) -c -o $@ $<