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 | |
| 43 | define find_dependency |
| 44 | $(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --exists $1 && echo yes || echo no) |
| 45 | endef |
| 46 | |
| 47 | define dependency_cflags |
| 48 | $(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --cflags $1 2>/dev/null) |
| 49 | endef |
| 50 | |
| 51 | define dependency_ldflags |
| 52 | $(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --libs $1 2>/dev/null) |
Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 53 | endef |
Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 54 | |
| 55 | define LIBPCI_TEST |
| 56 | /* Avoid a failing test due to libpci header symbol shadowing breakage */ |
| 57 | #define index shadow_workaround_index |
| 58 | #if !defined PCIUTILS_PCI_H |
| 59 | #include <pci/pci.h> |
| 60 | #else |
| 61 | #include <pciutils/pci.h> |
| 62 | #endif |
| 63 | struct pci_access *pacc; |
| 64 | int main(int argc, char **argv) |
| 65 | { |
| 66 | (void) argc; |
| 67 | (void) argv; |
| 68 | pacc = pci_alloc(); |
| 69 | return 0; |
| 70 | } |
| 71 | endef |
| 72 | export LIBPCI_TEST |
| 73 | |
| 74 | define PCI_GET_DEV_TEST |
| 75 | /* Avoid a failing test due to libpci header symbol shadowing breakage */ |
| 76 | #define index shadow_workaround_index |
| 77 | #if !defined PCIUTILS_PCI_H |
| 78 | #include <pci/pci.h> |
| 79 | #else |
| 80 | #include <pciutils/pci.h> |
| 81 | #endif |
| 82 | struct pci_access *pacc; |
| 83 | struct pci_dev *dev = {0}; |
| 84 | int main(int argc, char **argv) |
| 85 | { |
| 86 | (void) argc; |
| 87 | (void) argv; |
| 88 | pacc = pci_alloc(); |
| 89 | dev = pci_get_dev(pacc, dev->domain, dev->bus, dev->dev, 1); |
| 90 | return 0; |
| 91 | } |
| 92 | endef |
| 93 | export PCI_GET_DEV_TEST |
| 94 | |
| 95 | define LIBUSB1_TEST |
| 96 | #include <stddef.h> |
| 97 | #include <libusb.h> |
| 98 | int main(int argc, char **argv) |
| 99 | { |
| 100 | (void)argc; |
| 101 | (void)argv; |
| 102 | libusb_init(NULL); |
| 103 | return 0; |
| 104 | } |
| 105 | endef |
| 106 | export LIBUSB1_TEST |
| 107 | |
| 108 | define LIBJAYLINK_TEST |
| 109 | #include <stddef.h> |
| 110 | #include <libjaylink/libjaylink.h> |
| 111 | int main(int argc, char **argv) |
| 112 | { |
| 113 | struct jaylink_context *ctx; |
| 114 | |
| 115 | (void)argc; |
| 116 | (void)argv; |
| 117 | |
| 118 | jaylink_init(&ctx); |
| 119 | jaylink_exit(ctx); |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | endef |
| 124 | export LIBJAYLINK_TEST |
| 125 | |
Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 126 | define NI845X_TEST |
| 127 | #include <ni845x.h> |
| 128 | |
| 129 | int main(int argc, char **argv) |
| 130 | { |
| 131 | (void) argc; |
| 132 | (void) argv; |
| 133 | char I2C_Device[256]; |
| 134 | NiHandle Dev_Handle; |
| 135 | uInt32 NumberFound = 0; |
| 136 | ni845xFindDevice(I2C_Device, &Dev_Handle, &NumberFound); |
| 137 | ni845xCloseFindDeviceHandle(Dev_Handle); |
| 138 | return 0; |
| 139 | } |
| 140 | endef |
| 141 | export NI845X_TEST |