File: create-config.mk

package info (click to toggle)
multipath-tools 0.14.3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,088 kB
  • sloc: ansic: 64,885; perl: 1,622; makefile: 742; sh: 732; pascal: 155
file content (194 lines) | stat: -rw-r--r-- 6,368 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Copyright (c) SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

TOPDIR := .
CREATE_CONFIG := 1
include $(TOPDIR)/Makefile.inc

# "make" on some distros will fail on explicit '#' or '\#' in the program text below
__HASH__ := \#

# Check whether a given shell command succeeds
check_cmd = $(shell \
	if $1; then \
		found=1; \
		status="yes"; \
	else \
		found=0; \
		status="no"; \
	fi; \
	echo 1>&2 "Checking $(if $3,$3,command \"$1\") ... $$status"; \
	echo "$$found" \
	)

# Check whether a function with name $1 has been declared in header file $2.
check_func = $(shell \
	if grep -Eq "^(extern[[:blank:]]+)?[^[: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" \
	)

# Check whether a file contains a variable with name $1 in header file $2
check_var = $(shell \
	if grep -Eq "(^|[[: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" \
	)

# Test special behavior of gcc 4.8 with nested initializers
# gcc 4.8 compiles blacklist.c only with -Wno-missing-field-initializers
TEST_MISSING_INITIALIZERS = $(shell \
	echo 'struct A {int a, b;}; struct B {struct A a; int b;} b = {.a.a=1};' | \
		$(CC) -c -Werror -Wmissing-field-initializers -o /dev/null -xc - >/dev/null 2>&1 \
	|| echo -Wno-missing-field-initializers)

# gcc 4.8.4 and certain versions of liburcu fail to compile this with -Werror=type-limits
TEST_URCU_TYPE_LIMITS = $(shell \
	echo -e '$(__HASH__)include <urcu/uatomic.h>\nint main() { int z=8; return uatomic_sub_return(&z, 1); }' | \
		$(CC) -c -Werror=type-limits -o /dev/null -xc - 2>/dev/null  \
	|| echo -Wno-type-limits )

URCU_VERSION = $(shell \
	$(PKG_CONFIG) --modversion liburcu 2>/dev/null | \
			awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')

CMOCKA_VERSION = $(shell \
	($(PKG_CONFIG) --modversion cmocka 2>/dev/null || echo "1.1.0" ) | \
			awk -F. '{ printf("-DCMOCKA_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')

DEFINES :=

ifneq ($(call check_func,dm_task_no_flush,$(devmapper_incdir)/libdevmapper.h),0)
	DEFINES += LIBDM_API_FLUSH
endif

ifneq ($(call check_func,dm_task_get_errno,$(devmapper_incdir)/libdevmapper.h),0)
	DEFINES += LIBDM_API_GET_ERRNO
endif

ifneq ($(call check_func,dm_task_set_cookie,$(devmapper_incdir)/libdevmapper.h),0)
	DEFINES += LIBDM_API_COOKIE
endif

ifneq ($(call check_func,udev_monitor_set_receive_buffer_size,$(libudev_incdir)/libudev.h),0)
	DEFINES += LIBUDEV_API_RECVBUF
endif

ifneq ($(call check_func,dm_task_deferred_remove,$(devmapper_incdir)/libdevmapper.h),0)
	DEFINES += LIBDM_API_DEFERRED
endif

ifneq ($(call check_func,dm_hold_control_dev,$(devmapper_incdir)/libdevmapper.h),0)
	DEFINES += LIBDM_API_HOLD_CONTROL
endif

ifneq ($(call check_var,ELS_DTAG_LNK_INTEGRITY,$(kernel_incdir)/scsi/fc/fc_els.h),0)
	DEFINES += FPIN_EVENT_HANDLER
	FPIN_SUPPORT = 1
endif

libmount_h := $(shell $(PKG_CONFIG) --variable=includedir mount)/libmount/libmount.h
ifneq ($(call check_func,mnt_unref_cache,$(libmount_h)),0)
	DEFINES += LIBMOUNT_HAS_MNT_UNREF_CACHE
endif

ifneq ($(call check_func,mnt_table_parse_swaps,$(libmount_h)),0)
	DEFINES += LIBMOUNT_SUPPORTS_SWAP
endif

ifneq ($(call check_file,$(kernel_incdir)/linux/nvme_ioctl.h),0)
	ANA_SUPPORT := 1
endif

ENABLE_LIBDMMP := $(call check_cmd,$(PKG_CONFIG) --exists json-c)

ifeq ($(ENABLE_DMEVENTS_POLL),0)
	DEFINES += -DNO_DMEVENTS_POLL
endif

SYSTEMD := $(strip $(or $(shell $(PKG_CONFIG) --modversion libsystemd 2>/dev/null | awk '{print $$1}'), \
			$(shell systemctl --version 2>/dev/null | sed -n 's/systemd \([0-9]*\).*/\1/p')))


# $(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)

# Check if _DFORTIFY_SOURCE=3 is supported.
# On some distros (e.g. Debian Buster) it will be falsely reported as supported
# but it doesn't seem to make a difference wrt the compilation result.
FORTIFY_OPT :=

# Check is you can compile with the urcu.h header, using the C99 standard.
# If urcu/config-<arch>.h defines CONFIG_RCU_USE_ATOMIC_BUILTINS, then anything
# including urcu.h must be compiled with at least the C11 standard. See:
# https://github.com/urcu/userspace-rcu/commit/89280d020bf064d1055c360fb9974f128051043f
C_STD := $(shell \
	if printf '$(__HASH__)include <urcu.h>\nint main(void) { return 0; }\n' | $(CC) -o /dev/null -c -xc -std=gnu99 - 2>/dev/null; \
	then \
		echo "gnu99"; \
	else \
		echo "gnu11"; \
	fi)

STACKPROT :=

all:	$(TOPDIR)/config.mk

$(multipathdir)/autoconfig.h:
	@echo creating $@
	@echo '#ifndef AUTOCONFIG_H_INCLUDED' >$@
	@echo '#define AUTOCONFIG_H_INCLUDED' >>$@
	@for x in $(DEFINES); do echo "#define $$x" >>$@; done
	@echo '#endif' >>$@

$(TOPDIR)/config.mk:	$(multipathdir)/autoconfig.h
	@echo creating $@
	@echo "FPIN_SUPPORT := $(FPIN_SUPPORT)" >$@
	@echo "FORTIFY_OPT := $(FORTIFY_OPT)" >>$@
	@echo "D_URCU_VERSION := $(call URCU_VERSION)" >>$@
	@echo "D_CMOCKA_VERSION := $(call CMOCKA_VERSION)" >>$@
	@echo "SYSTEMD := $(SYSTEMD)" >>$@
	@echo "ANA_SUPPORT := $(ANA_SUPPORT)" >>$@
	@echo "STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)" >>$@
	@echo "ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)" >>$@
	@echo "WNOCLOBBERED := $(call TEST_CC_OPTION,-Wno-clobbered -Wno-error=clobbered,)" >>$@
	@echo "WFORMATOVERFLOW := $(call TEST_CC_OPTION,-Wformat-overflow=2,)" >>$@
	@echo "WSTRINGOP_TRUNCATION := $(call TEST_CC_OPTION,-Wstringop-truncation)" >>$@
	@echo "W_MISSING_INITIALIZERS := $(call TEST_MISSING_INITIALIZERS)" >>$@
	@echo "W_URCU_TYPE_LIMITS := $(call TEST_URCU_TYPE_LIMITS)" >>$@
	@echo "ENABLE_LIBDMMP := $(ENABLE_LIBDMMP)" >>$@
	@echo "C_STD := $(C_STD)" >>$@