Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 1 | # |
| 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 | |
| 16 | define mark_unsupported |
| 17 | $(foreach p,$1, \ |
| 18 | $(if $(filter $($(p)),yes), \ |
| 19 | $(eval UNSUPPORTED_FEATURES += $(p)=yes), \ |
| 20 | $(eval override $(p) := no))) |
| 21 | endef |
| 22 | |
Nico Huber | aded7cc | 2023-03-04 16:06:11 +0100 | [diff] [blame] | 23 | define mark_missing_dep |
| 24 | $(foreach p,$2, \ |
| 25 | $(if $(filter $($(p)),yes), \ |
| 26 | $(eval MISSING_DEPENDENCY += $(1)) \ |
| 27 | $(eval MISSING_DEPENDENCY_$(1) += $(p)=yes))) |
| 28 | $(eval MISSING_DEPENDENCY := $(sort $(MISSING_DEPENDENCY))) |
| 29 | $(eval MISSING_DEPENDENCY_NOTE_$(1) := $(if $(3),$(3),"")) |
| 30 | endef |
| 31 | |
Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 32 | define filter_deps |
| 33 | $(strip $(foreach p,$1, \ |
| 34 | $(if $(filter $($(p)),yes), \ |
| 35 | $(p)))) |
| 36 | endef |
| 37 | |
| 38 | define disable_all |
| 39 | $(foreach p,$1, \ |
| 40 | $(eval override $(p) := no)) |
| 41 | endef |
| 42 | |
Thomas Heijligen | 1e76dc8 | 2021-09-28 15:22:34 +0200 | [diff] [blame] | 43 | # Run the C Preprocessor with file $1 and return the last line, removing quotes. |
| 44 | define c_macro_test |
Thomas Heijligen | 121a5b8 | 2021-10-21 12:58:07 +0200 | [diff] [blame] | 45 | $(strip $(call debug_shell, $(CC) -E $1 | tail -n 1 | tr -d '"')) |
Thomas Heijligen | 1e76dc8 | 2021-09-28 15:22:34 +0200 | [diff] [blame] | 46 | endef |
Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 47 | |
Thomas Heijligen | 121a5b8 | 2021-10-21 12:58:07 +0200 | [diff] [blame] | 48 | define 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) |
| 50 | endef |
| 51 | |
Thomas Heijligen | 9138e3f | 2022-01-31 23:49:44 +0100 | [diff] [blame] | 52 | define 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) |
| 54 | endef |
| 55 | |
Thomas Heijligen | 121a5b8 | 2021-10-21 12:58:07 +0200 | [diff] [blame] | 56 | define find_dependency |
| 57 | $(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --exists $1 && echo yes || echo no) |
| 58 | endef |
| 59 | |
Thomas Heijligen | 7a9daa0 | 2022-08-12 19:52:23 +0200 | [diff] [blame] | 60 | define dependency_version |
| 61 | $(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --modversion $1 2>/dev/null) |
| 62 | endef |
| 63 | |
Thomas Heijligen | 121a5b8 | 2021-10-21 12:58:07 +0200 | [diff] [blame] | 64 | define dependency_cflags |
| 65 | $(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --cflags $1 2>/dev/null) |
| 66 | endef |
| 67 | |
| 68 | define dependency_ldflags |
Thomas Heijligen | facfadb | 2022-01-31 23:27:52 +0100 | [diff] [blame] | 69 | $(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --libs --static $1 2>/dev/null) |
Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 70 | endef |