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