blob: 7c168b91645d759362456ec9ba94f0bc06493232 [file] [log] [blame]
Thomas Heijligen90fa8152021-09-25 13:39:42 +02001#
2# This file is part of the flashrom project.
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; version 2 of the License.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13
14# Here are functions and macros defined for the Makefile
15
16define mark_unsupported
17$(foreach p,$1, \
18 $(if $(filter $($(p)),yes), \
19 $(eval UNSUPPORTED_FEATURES += $(p)=yes), \
20 $(eval override $(p) := no)))
21endef
22
23define filter_deps
24$(strip $(foreach p,$1, \
25 $(if $(filter $($(p)),yes), \
26 $(p))))
27endef
28
29define disable_all
30$(foreach p,$1, \
31 $(eval override $(p) := no))
32endef
33
Thomas Heijligen1e76dc82021-09-28 15:22:34 +020034# Run the C Preprocessor with file $1 and return the last line, removing quotes.
35define c_macro_test
Thomas Heijligen121a5b82021-10-21 12:58:07 +020036$(strip $(call debug_shell, $(CC) -E $1 | tail -n 1 | tr -d '"'))
Thomas Heijligen1e76dc82021-09-28 15:22:34 +020037endef
Thomas Heijligen90fa8152021-09-25 13:39:42 +020038
Thomas Heijligen121a5b82021-10-21 12:58:07 +020039define c_compile_test # $1: files to compile, $2: cflags
40$(call debug_shell, $(CC) -c -Wall -Werror $2 $1 -o /dev/null && echo yes || echo no)
41endef
42
Thomas Heijligen9138e3f2022-01-31 23:49:44 +010043define c_link_test # $1: file to compile and link, $2: cflags, $3: ldflags
44$(call debug_shell, $(CC) -Wall -Werror $2 $1 $3 -o /dev/null && echo yes || echo no)
45endef
46
Thomas Heijligen121a5b82021-10-21 12:58:07 +020047define find_dependency
48$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --exists $1 && echo yes || echo no)
49endef
50
51define dependency_cflags
52$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --cflags $1 2>/dev/null)
53endef
54
55define dependency_ldflags
Thomas Heijligenfacfadb2022-01-31 23:27:52 +010056$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --libs --static $1 2>/dev/null)
Thomas Heijligen90fa8152021-09-25 13:39:42 +020057endef