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 |
| 36 | $(strip $(shell $(CC) -E $1 2>/dev/null | tail -n 1 | tr -d '"')) |
| 37 | endef |
Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 38 | |
Thomas Heijligen | 323ad35 | 2021-10-26 11:26:32 +0200 | [diff] [blame^] | 39 | define c_compile_test |
| 40 | $(shell $(CC) -c -Wall -Werror -o /dev/null $1 2>/dev/null && echo yes || echo no) |
Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 41 | endef |
Thomas Heijligen | 90fa815 | 2021-09-25 13:39:42 +0200 | [diff] [blame] | 42 | |
| 43 | define LIBPCI_TEST |
| 44 | /* Avoid a failing test due to libpci header symbol shadowing breakage */ |
| 45 | #define index shadow_workaround_index |
| 46 | #if !defined PCIUTILS_PCI_H |
| 47 | #include <pci/pci.h> |
| 48 | #else |
| 49 | #include <pciutils/pci.h> |
| 50 | #endif |
| 51 | struct pci_access *pacc; |
| 52 | int main(int argc, char **argv) |
| 53 | { |
| 54 | (void) argc; |
| 55 | (void) argv; |
| 56 | pacc = pci_alloc(); |
| 57 | return 0; |
| 58 | } |
| 59 | endef |
| 60 | export LIBPCI_TEST |
| 61 | |
| 62 | define PCI_GET_DEV_TEST |
| 63 | /* Avoid a failing test due to libpci header symbol shadowing breakage */ |
| 64 | #define index shadow_workaround_index |
| 65 | #if !defined PCIUTILS_PCI_H |
| 66 | #include <pci/pci.h> |
| 67 | #else |
| 68 | #include <pciutils/pci.h> |
| 69 | #endif |
| 70 | struct pci_access *pacc; |
| 71 | struct pci_dev *dev = {0}; |
| 72 | int main(int argc, char **argv) |
| 73 | { |
| 74 | (void) argc; |
| 75 | (void) argv; |
| 76 | pacc = pci_alloc(); |
| 77 | dev = pci_get_dev(pacc, dev->domain, dev->bus, dev->dev, 1); |
| 78 | return 0; |
| 79 | } |
| 80 | endef |
| 81 | export PCI_GET_DEV_TEST |
| 82 | |
| 83 | define LIBUSB1_TEST |
| 84 | #include <stddef.h> |
| 85 | #include <libusb.h> |
| 86 | int main(int argc, char **argv) |
| 87 | { |
| 88 | (void)argc; |
| 89 | (void)argv; |
| 90 | libusb_init(NULL); |
| 91 | return 0; |
| 92 | } |
| 93 | endef |
| 94 | export LIBUSB1_TEST |
| 95 | |
| 96 | define LIBJAYLINK_TEST |
| 97 | #include <stddef.h> |
| 98 | #include <libjaylink/libjaylink.h> |
| 99 | int main(int argc, char **argv) |
| 100 | { |
| 101 | struct jaylink_context *ctx; |
| 102 | |
| 103 | (void)argc; |
| 104 | (void)argv; |
| 105 | |
| 106 | jaylink_init(&ctx); |
| 107 | jaylink_exit(ctx); |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | endef |
| 112 | export LIBJAYLINK_TEST |
| 113 | |
| 114 | define FTDI_TEST |
| 115 | #include <stdlib.h> |
| 116 | #include <ftdi.h> |
| 117 | struct ftdi_context *ftdic = NULL; |
| 118 | int main(int argc, char **argv) |
| 119 | { |
| 120 | (void) argc; |
| 121 | (void) argv; |
| 122 | return ftdi_init(ftdic); |
| 123 | } |
| 124 | endef |
| 125 | export FTDI_TEST |
| 126 | |
| 127 | define FTDI_232H_TEST |
| 128 | #include <ftdi.h> |
| 129 | enum ftdi_chip_type type = TYPE_232H; |
| 130 | endef |
| 131 | export FTDI_232H_TEST |
| 132 | |
| 133 | define UTSNAME_TEST |
| 134 | #include <sys/utsname.h> |
| 135 | struct utsname osinfo; |
| 136 | int main(int argc, char **argv) |
| 137 | { |
| 138 | (void) argc; |
| 139 | (void) argv; |
| 140 | uname (&osinfo); |
| 141 | return 0; |
| 142 | } |
| 143 | endef |
| 144 | export UTSNAME_TEST |
| 145 | |
| 146 | define LINUX_MTD_TEST |
| 147 | #include <mtd/mtd-user.h> |
| 148 | |
| 149 | int main(int argc, char **argv) |
| 150 | { |
| 151 | (void) argc; |
| 152 | (void) argv; |
| 153 | return 0; |
| 154 | } |
| 155 | endef |
| 156 | export LINUX_MTD_TEST |
| 157 | |
| 158 | define LINUX_SPI_TEST |
| 159 | #include <linux/types.h> |
| 160 | #include <linux/spi/spidev.h> |
| 161 | |
| 162 | int main(int argc, char **argv) |
| 163 | { |
| 164 | (void) argc; |
| 165 | (void) argv; |
| 166 | return 0; |
| 167 | } |
| 168 | endef |
| 169 | export LINUX_SPI_TEST |
| 170 | |
| 171 | define LINUX_I2C_TEST |
| 172 | #include <linux/i2c-dev.h> |
| 173 | #include <linux/i2c.h> |
| 174 | |
| 175 | int main(int argc, char **argv) |
| 176 | { |
| 177 | (void) argc; |
| 178 | (void) argv; |
| 179 | return 0; |
| 180 | } |
| 181 | endef |
| 182 | export LINUX_I2C_TEST |
| 183 | |
| 184 | define CLOCK_GETTIME_TEST |
| 185 | #include <time.h> |
| 186 | |
| 187 | int main(int argc, char **argv) |
| 188 | { |
| 189 | struct timespec res; |
| 190 | clock_gettime(CLOCK_REALTIME, &res); |
| 191 | return 0; |
| 192 | } |
| 193 | endef |
| 194 | export CLOCK_GETTIME_TEST |
| 195 | |
| 196 | define NI845X_TEST |
| 197 | #include <ni845x.h> |
| 198 | |
| 199 | int main(int argc, char **argv) |
| 200 | { |
| 201 | (void) argc; |
| 202 | (void) argv; |
| 203 | char I2C_Device[256]; |
| 204 | NiHandle Dev_Handle; |
| 205 | uInt32 NumberFound = 0; |
| 206 | ni845xFindDevice(I2C_Device, &Dev_Handle, &NumberFound); |
| 207 | ni845xCloseFindDeviceHandle(Dev_Handle); |
| 208 | return 0; |
| 209 | } |
| 210 | endef |
| 211 | export NI845X_TEST |