Imported Upstream version 0.8.5
[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 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 pkg-config --modversion libsystemd >/dev/null 2>&1 && echo 1), 1)
40                 SYSTEMD = $(shell pkg-config --modversion libsystemd | awk '{print $$1}')
41         else
42                 ifeq ($(shell systemctl --version >/dev/null 2>&1 && echo 1), 1)
43                         SYSTEMD = $(shell systemctl --version 2> /dev/null | \
44                                 sed -n 's/systemd \([0-9]*\).*/\1/p')
45                 endif
46         endif
47 endif
48
49 ifndef SYSTEMDPATH
50         SYSTEMDPATH=usr/lib
51 endif
52
53 prefix          =
54 exec_prefix     = $(prefix)
55 usr_prefix      = $(prefix)
56 bindir          = $(exec_prefix)/sbin
57 libudevdir      = $(prefix)/$(SYSTEMDPATH)/udev
58 udevrulesdir    = $(libudevdir)/rules.d
59 multipathdir    = $(TOPDIR)/libmultipath
60 man8dir         = $(prefix)/usr/share/man/man8
61 man5dir         = $(prefix)/usr/share/man/man5
62 man3dir         = $(prefix)/usr/share/man/man3
63 syslibdir       = $(prefix)/$(LIB)
64 usrlibdir       = $(usr_prefix)/$(LIB)
65 libdir          = $(prefix)/$(LIB)/multipath
66 unitdir         = $(prefix)/$(SYSTEMDPATH)/systemd/system
67 mpathpersistdir = $(TOPDIR)/libmpathpersist
68 mpathcmddir     = $(TOPDIR)/libmpathcmd
69 thirdpartydir   = $(TOPDIR)/third-party
70 libdmmpdir      = $(TOPDIR)/libdmmp
71 nvmedir         = $(TOPDIR)/libmultipath/nvme
72 includedir      = $(prefix)/usr/include
73 pkgconfdir      = $(usrlibdir)/pkgconfig
74
75 GZIP            = gzip -9 -c
76 RM              = rm -f
77 LN              = ln -sf
78 INSTALL_PROGRAM = install
79
80 # $(call TEST_CC_OPTION,option,fallback)
81 # Test if the C compiler supports the option.
82 # Evaluates to "option" if yes, and "fallback" otherwise.
83 TEST_CC_OPTION = $(shell \
84         if echo 'int main(void){return 0;}' | \
85                 $(CC) -o /dev/null -c -Werror "$(1)" -xc - >/dev/null 2>&1; \
86         then \
87                 echo "$(1)"; \
88         else \
89                 echo "$(2)"; \
90         fi)
91
92 STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
93 ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)
94 WNOCLOBBERED := $(call TEST_CC_OPTION,-Wno-clobbered -Wno-error=clobbered,)
95
96 OPTFLAGS        := -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
97 WARNFLAGS       := -Werror -Wall -Wextra -Wformat=2 -Werror=implicit-int \
98                   -Werror=implicit-function-declaration -Werror=format-security \
99                   $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS)
100 CPPFLAGS        := -Wp,-D_FORTIFY_SOURCE=2 
101 CFLAGS          := --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe \
102                    -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
103                    -MMD -MP
104 BIN_CFLAGS      = -fPIE -DPIE
105 LIB_CFLAGS      = -fPIC
106 SHARED_FLAGS    = -shared
107 LDFLAGS         := $(LDFLAGS) -Wl,-z,relro -Wl,-z,now
108 BIN_LDFLAGS     = -pie
109
110 # Check whether a function with name $1 has been declared in header file $2.
111 check_func = $(shell \
112         if grep -Eq "^[^[:blank:]]+[[:blank:]]+$1[[:blank:]]*(.*)*" "$2"; then \
113                 found=1; \
114                 status="yes"; \
115         else \
116                 found=0; \
117                 status="no"; \
118         fi; \
119         echo 1>&2 "Checking for $1 in $2 ... $$status"; \
120         echo "$$found" \
121         )
122
123 # Checker whether a file with name $1 exists
124 check_file = $(shell \
125         if [ -f "$1" ]; then \
126                 found=1; \
127                 status="yes"; \
128         else \
129                 found=0; \
130                 status="no"; \
131         fi; \
132         echo 1>&2 "Checking if $1 exists ... $$status"; \
133         echo "$$found" \
134         )
135
136 %.o:    %.c
137         @echo building $@ because of $?
138         $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<