blob: 1bca4f3a833233a37a6c9838fa4c8895d96d0149 [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
Nico Huberaded7cc2023-03-04 16:06:11 +010023define mark_missing_dep
24$(foreach p,$2, \
25 $(if $(filter $($(p)),yes), \
26 $(eval MISSING_DEPENDENCY += $(1)) \
Nico Huber6272eb62023-03-16 22:59:50 +000027 $(eval MISSING_DEPENDENCY_$(1) += $(p)=yes))) \
28$(eval MISSING_DEPENDENCY := $(sort $(MISSING_DEPENDENCY))) \
Nico Huberaded7cc2023-03-04 16:06:11 +010029$(eval MISSING_DEPENDENCY_NOTE_$(1) := $(if $(3),$(3),""))
30endef
31
Thomas Heijligen90fa8152021-09-25 13:39:42 +020032define filter_deps
33$(strip $(foreach p,$1, \
34 $(if $(filter $($(p)),yes), \
35 $(p))))
36endef
37
38define disable_all
39$(foreach p,$1, \
40 $(eval override $(p) := no))
41endef
42
Thomas Heijligen1e76dc82021-09-28 15:22:34 +020043# Run the C Preprocessor with file $1 and return the last line, removing quotes.
44define c_macro_test
Thomas Heijligen121a5b82021-10-21 12:58:07 +020045$(strip $(call debug_shell, $(CC) -E $1 | tail -n 1 | tr -d '"'))
Thomas Heijligen1e76dc82021-09-28 15:22:34 +020046endef
Thomas Heijligen90fa8152021-09-25 13:39:42 +020047
Thomas Heijligen121a5b82021-10-21 12:58:07 +020048define c_compile_test # $1: files to compile, $2: cflags
49$(call debug_shell, $(CC) -c -Wall -Werror $2 $1 -o /dev/null && echo yes || echo no)
50endef
51
Thomas Heijligen9138e3f2022-01-31 23:49:44 +010052define c_link_test # $1: file to compile and link, $2: cflags, $3: ldflags
53$(call debug_shell, $(CC) -Wall -Werror $2 $1 $3 -o /dev/null && echo yes || echo no)
54endef
55
Thomas Heijligen121a5b82021-10-21 12:58:07 +020056define find_dependency
57$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --exists $1 && echo yes || echo no)
58endef
59
Thomas Heijligen7a9daa02022-08-12 19:52:23 +020060define dependency_version
61$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --modversion $1 2>/dev/null)
62endef
63
Thomas Heijligen121a5b82021-10-21 12:58:07 +020064define dependency_cflags
65$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --cflags $1 2>/dev/null)
66endef
67
68define dependency_ldflags
Thomas Heijligenfacfadb2022-01-31 23:27:52 +010069$(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 +020070endef