Bump to 0.9.7
[platform/upstream/multipath-tools.git] / Makefile.inc
index d4d1e0d..6b45430 100644 (file)
-#
+# -*- Makefile -*-
 # Copyright (C) 2004 Christophe Varoqui, <christophe.varoqui@opensvc.com>
 #
 
 #
-# Allow to force some libraries to be used statically. (Uncomment one of the
-# following lines or define the values when calling make.)
-#
-# WITH_LOCAL_LIBDM     = 1
-# WITH_LOCAL_LIBSYSFS  = 1
-#
 # Uncomment to disable libdmmp support
 # ENABLE_LIBDMMP = 0
 #
 # Uncomment to disable dmevents polling support
 # ENABLE_DMEVENTS_POLL = 0
+#
+# Readline library to use, libedit, libreadline, or empty
+# Caution: Using libreadline may make the multipathd binary undistributable,
+# see https://github.com/opensvc/multipath-tools/issues/36
+READLINE :=
+
+# List of scsi device handler modules to load on boot, e.g.
+# SCSI_DH_MODULES_PRELOAD := scsi_dh_alua scsi_dh_rdac
+SCSI_DH_MODULES_PRELOAD :=
+
+EXTRAVERSION := $(shell rev=$$(git rev-parse --short=7 HEAD 2>/dev/null); echo $${rev:+-g$$rev})
+
+# PKG_CONFIG must be read from the environment to enable compilation
+# in Debian multiarch setups
+PKG_CONFIG     ?= pkg-config
 
 ifeq ($(TOPDIR),)
        TOPDIR  = ..
 endif
-
-ifndef LIB
-       ifeq ($(shell test -d /lib64 && echo 1),1)
-               LIB=lib64
-       else
-               LIB=lib
-       endif
+ifneq ($(CREATE_CONFIG),1)
+include $(TOPDIR)/config.mk
 endif
 
-ifndef RUN
-       ifeq ($(shell test -L /var/run -o ! -d /var/run && echo 1),1)
-               RUN=run
-       else
-               RUN=var/run
-       endif
-endif
+# Paths. All these can be overridden on the "make" command line.
+prefix         :=
+# Prefix for binaries
+exec_prefix    := $(prefix)
+# Prefix for non-essential libraries (libdmmp)
+usr_prefix     := $(if $(prefix),$(prefix),/usr)
+# Prefix for configfuration files (multipath.conf)
+etc_prefix     := $(prefix)
+# Where to install systemd-related files. systemd is usually installed under /usr
+# Note: systemd installations with "split-usr=true" use separate "prefixdir" and
+# "rootprefixdir". Our systemd_prefix corresponds to "prefixdir".
+# In this case, override only unitdir and libudevdir below to use
+# systemd's "rootprefixdir" instead of $(systemd_prefix)
+systemd_prefix  := /usr
 
-ifndef SYSTEMD
-       ifeq ($(shell pkg-config --modversion libsystemd >/dev/null 2>&1 && echo 1), 1)
-               SYSTEMD = $(shell pkg-config --modversion libsystemd)
-       else
-               ifeq ($(shell systemctl --version >/dev/null 2>&1 && echo 1), 1)
-                       SYSTEMD = $(shell systemctl --version 2> /dev/null | \
-                               sed -n 's/systemd \([0-9]*\).*/\1/p')
-               endif
-       endif
-endif
+# Make sure all prefix variables end in "/"
+append-slash = $(1)$(if $(filter %/,$(1)),,/)
+override prefix          := $(call append-slash,$(prefix))
+override exec_prefix     := $(call append-slash,$(exec_prefix))
+override usr_prefix      := $(call append-slash,$(usr_prefix))
+override etc_prefix      := $(call append-slash,$(etc_prefix))
+override systemd_prefix  := $(call append-slash,$(systemd_prefix))
+
+unitdir                := $(systemd_prefix)lib/systemd/system
+tmpfilesdir    := $(systemd_prefix)lib/tmpfiles.d
+modulesloaddir := $(systemd_prefix)lib/modules-load.d
+libudevdir     := $(systemd_prefix)lib/udev
+udevrulesdir   := $(libudevdir)/rules.d
+bindir         := $(exec_prefix)sbin
+mandir         := $(usr_prefix)share/man
+LIB            := $(if $(shell test -d /lib64 && echo 1),lib64,lib)
+syslibdir      := $(prefix)$(LIB)
+usrlibdir      := $(usr_prefix)$(LIB)
+includedir     := $(usr_prefix)include
+pkgconfdir     := $(usrlibdir)/pkgconfig
+plugindir       := $(prefix)$(LIB)/multipath
+configdir       := $(etc_prefix)etc/multipath/conf.d
+configfile      := $(etc_prefix)etc/multipath.conf
+statedir        := $(etc_prefix)etc/multipath
+runtimedir      := $(if $(shell test -L /var/run -o ! -d /var/run && echo 1),/run,/var/run)
+devmapper_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir devmapper),/usr/include)
+libudev_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir libudev),/usr/include)
+kernel_incdir  := /usr/include
 
-ifndef SYSTEMDPATH
-       SYSTEMDPATH=usr/lib
+ifeq ($(V),)
+Q              := @
+# make's "Entering directory" messages are confusing in parallel mode
+#MAKEFLAGS     = --no-print-directory
 endif
 
-prefix         =
-exec_prefix    = $(prefix)
-usr_prefix     = $(prefix)
-bindir         = $(exec_prefix)/sbin
-libudevdir     = $(prefix)/$(SYSTEMDPATH)/udev
-udevrulesdir   = $(libudevdir)/rules.d
-multipathdir   = $(TOPDIR)/libmultipath
-man8dir                = $(prefix)/usr/share/man/man8
-man5dir                = $(prefix)/usr/share/man/man5
-man3dir                = $(prefix)/usr/share/man/man3
-syslibdir      = $(prefix)/$(LIB)
-usrlibdir      = $(usr_prefix)/$(LIB)
-libdir         = $(prefix)/$(LIB)/multipath
-unitdir                = $(prefix)/$(SYSTEMDPATH)/systemd/system
-mpathpersistdir        = $(TOPDIR)/libmpathpersist
-mpathcmddir    = $(TOPDIR)/libmpathcmd
-thirdpartydir  = $(TOPDIR)/third-party
-libdmmpdir     = $(TOPDIR)/libdmmp
-nvmedir                = $(TOPDIR)/libmultipath/nvme
-includedir     = $(prefix)/usr/include
-pkgconfdir     = $(usrlibdir)/pkgconfig
-
-GZIP           = gzip -9 -c
-RM             = rm -f
-LN             = ln -sf
-INSTALL_PROGRAM        = install
-
-# $(call TEST_CC_OPTION,option,fallback)
-# Test if the C compiler supports the option.
-# Evaluates to "option" if yes, and "fallback" otherwise.
-TEST_CC_OPTION = $(shell \
-       if echo 'int main(void){return 0;}' | \
-               $(CC) -o /dev/null -c -Werror "$(1)" -xc - >/dev/null 2>&1; \
-       then \
-               echo "$(1)"; \
-       else \
-               echo "$(2)"; \
-       fi)
-
-STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
-ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)
-WNOCLOBBERED := $(call TEST_CC_OPTION,-Wno-clobbered,)
-
-OPTFLAGS       = -O2 -g -pipe -Werror -Wall -Wextra -Wformat=2 -Werror=implicit-int \
+GZIP_PROG      := gzip -9 -c
+RM             := rm -f
+LN             := ln -sf
+INSTALL_PROGRAM        := install
+
+ORIG_CPPFLAGS    := $(CPPFLAGS)
+ORIG_CFLAGS      := $(CFLAGS)
+ORIG_LDFLAGS     := $(LDFLAGS)
+
+SYSTEMD_CPPFLAGS := $(if $(SYSTEMD),-DUSE_SYSTEMD=$(SYSTEMD))
+SYSTEMD_LIBDEPS := $(if $(SYSTEMD),$(if $(shell test $(SYSTEMD) -gt 209 && echo 1),-lsystemd,-lsystemd-daemon))
+MODPROBE_UNIT := $(shell test "0$(SYSTEMD)" -lt 245 2>/dev/null || \
+                       echo "modprobe@dm_multipath.service")
+
+OPTFLAGS       := -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
+WARNFLAGS      := -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implicit-int \
                  -Werror=implicit-function-declaration -Werror=format-security \
-                 $(WNOCLOBBERED) \
-                 -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
-                 $(STACKPROT) --param=ssp-buffer-size=4
-CPPFLAGS       := -Wp,-D_FORTIFY_SOURCE=2 
-CFLAGS         := $(OPTFLAGS) -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
-                  -MMD -MP $(CFLAGS)
-BIN_CFLAGS     = -fPIE -DPIE
-LIB_CFLAGS     = -fPIC
-SHARED_FLAGS   = -shared
-LDFLAGS                = -Wl,-z,relro -Wl,-z,now
-BIN_LDFLAGS    = -pie
-
-# Check whether a function with name $1 has been declared in header file $2.
-check_func = $(shell \
-       if grep -Eq "^[^[:blank:]]+[[:blank:]]+$1[[:blank:]]*(.*)*" "$2"; then \
-               found=1; \
-               status="yes"; \
-       else \
-               found=0; \
-               status="no"; \
-       fi; \
-       echo 1>&2 "Checking for $1 in $2 ... $$status"; \
-       echo "$$found" \
-       )
-
-# Checker whether a file with name $1 exists
-check_file = $(shell \
-       if [ -f "$1" ]; then \
-               found=1; \
-               status="yes"; \
-       else \
-               found=0; \
-               status="no"; \
-       fi; \
-       echo 1>&2 "Checking if $1 exists ... $$status"; \
-       echo "$$found" \
-       )
+                 $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) $(W_URCU_TYPE_LIMITS)
+CPPFLAGS       := $(FORTIFY_OPT) $(CPPFLAGS) $(D_URCU_VERSION) \
+                  -DBIN_DIR=\"$(bindir)\" -DMULTIPATH_DIR=\"$(plugindir)\" \
+                  -DRUNTIME_DIR=\"$(runtimedir)\" -DCONFIG_DIR=\"$(configdir)\" \
+                  -DDEFAULT_CONFIGFILE=\"$(configfile)\" -DSTATE_DIR=\"$(statedir)\" \
+                  -DEXTRAVERSION=\"$(EXTRAVERSION)\" -MMD -MP
+CFLAGS         := --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe
+BIN_CFLAGS     := -fPIE -DPIE
+LIB_CFLAGS     := -fPIC
+SHARED_FLAGS   := -shared
+LDFLAGS                := $(LDFLAGS) -Wl,-z,relro -Wl,-z,now -Wl,-z,defs
+BIN_LDFLAGS    := -pie
+
+# Source code directories. Don't modify.
+
+multipathdir   := $(TOPDIR)/libmultipath
+daemondir      := $(TOPDIR)/multipathd
+mpathutildir   := $(TOPDIR)/libmpathutil
+mpathpersistdir        := $(TOPDIR)/libmpathpersist
+mpathcmddir    := $(TOPDIR)/libmpathcmd
+mpathvaliddir  := $(TOPDIR)/libmpathvalid
+thirdpartydir  := $(TOPDIR)/third-party
+libdmmpdir     := $(TOPDIR)/libdmmp
+nvmedir                := $(TOPDIR)/libmultipath/nvme
+
+# Common code for libraries - library Makefiles just set DEVLIB
+# SONAME defaults to 0 (we use version scripts)
+SONAME := 0
+LIBS = $(DEVLIB).$(SONAME)
+VERSION_SCRIPT = $(DEVLIB:%.so=%.version)
+NV_VERSION_SCRIPT = $(DEVLIB:%.so=%-nv.version)
 
 %.o:   %.c
        @echo building $@ because of $?
-       $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+       $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+
+%.abi:  %.so.0
+       $(Q)abidw $< >$@
+
+%.abi:  %.so
+       $(Q)abidw $< >$@
+
+%-nv.version:  %.version
+       @echo creating $@ from $<
+       @printf 'NOVERSION {\nglobal:\n' >$@
+       @grep -P '^[ \t]+[a-zA-Z_][a-zA-Z0-9_]*;' $< >>$@
+       @printf 'local:\n\t*;\n};\n' >>$@
+
+%:     %.in
+       @echo creating $@
+       $(Q)sed 's:@CONFIGFILE@:'$(configfile)':g;s:@CONFIGDIR@:'$(configdir)':g;s:@STATE_DIR@:'$(statedir)':g;s:@RUNTIME_DIR@:'$(runtimedir)':g;s/@MODPROBE_UNIT@/'$(MODPROBE_UNIT)'/g' $< >$@