a12b46ef315e7b8e2cefb8662d02e615471be0b7
[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
90 OPTFLAGS        = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \
91                   -Werror=implicit-function-declaration -Werror=format-security \
92                   -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered \
93                   -Werror=cast-qual -Werror=discarded-qualifiers \
94                   -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \
95                   --param=ssp-buffer-size=4
96
97 CFLAGS          := $(OPTFLAGS) -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
98                    -MMD -MP $(CFLAGS)
99 BIN_CFLAGS      = -fPIE -DPIE
100 LIB_CFLAGS      = -fPIC
101 SHARED_FLAGS    = -shared
102 LDFLAGS         = -Wl,-z,relro -Wl,-z,now
103 BIN_LDFLAGS     = -pie
104
105 # Check whether a function with name $1 has been declared in header file $2.
106 check_func = $(shell \
107         if grep -Eq "^[^[:blank:]]+[[:blank:]]+$1[[:blank:]]*(.*)*" "$2"; then \
108                 found=1; \
109                 status="yes"; \
110         else \
111                 found=0; \
112                 status="no"; \
113         fi; \
114         echo 1>&2 "Checking for $1 in $2 ... $$status"; \
115         echo "$$found" \
116         )
117
118 # Checker whether a file with name $1 exists
119 check_file = $(shell \
120         if [ -f "$1" ]; then \
121                 found=1; \
122                 status="yes"; \
123         else \
124                 found=0; \
125                 status="no"; \
126         fi; \
127         echo 1>&2 "Checking if $1 exists ... $$status"; \
128         echo "$$found" \
129         )
130
131 %.o:    %.c
132         @echo building $@ because of $?
133         $(CC) $(CFLAGS) -c -o $@ $<