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