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 | |
| 23 | define filter_deps |
| 24 | $(strip $(foreach p,$1, \ |
| 25 | $(if $(filter $($(p)),yes), \ |
| 26 | $(p)))) |
| 27 | endef |
| 28 | |
| 29 | define disable_all |
| 30 | $(foreach p,$1, \ |
| 31 | $(eval override $(p) := no)) |
| 32 | endef |
| 33 | |
Thomas Heijligen | 1e76dc8 | 2021-09-28 15:22:34 +0200 | [diff] [blame] | 34 | # Run the C Preprocessor with file $1 and return the last line, removing quotes. |
| 35 | define c_macro_test |
Thomas Heijligen | 121a5b8 | 2021-10-21 12:58:07 +0200 | [diff] [blame] | 36 | $(strip $(call debug_shell, $(CC) -E $1 | tail -n 1 | tr -d '"')) |
Thomas Heijligen | 1e76dc8 | 2021-09-28 15:22:34 +0200 | [diff] [blame] | 37 | endef |
Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 38 | |
Thomas Heijligen | 121a5b8 | 2021-10-21 12:58:07 +0200 | [diff] [blame] | 39 | define 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) |
| 41 | endef |
| 42 | |
Thomas Heijligen | 9138e3f | 2022-01-31 23:49:44 +0100 | [diff] [blame] | 43 | define 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) |
| 45 | endef |
| 46 | |
Thomas Heijligen | 121a5b8 | 2021-10-21 12:58:07 +0200 | [diff] [blame] | 47 | define find_dependency |
| 48 | $(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --exists $1 && echo yes || echo no) |
| 49 | endef |
| 50 | |
| 51 | define dependency_cflags |
| 52 | $(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --cflags $1 2>/dev/null) |
| 53 | endef |
| 54 | |
| 55 | define dependency_ldflags |
Thomas Heijligen | facfadb | 2022-01-31 23:27:52 +0100 | [diff] [blame] | 56 | $(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] | 57 | endef |