Makefile: Make pkg-config mandatory to find libftdi1

Use `make HAS_LIBFTDI1=yes/no` to override the pkg-config detection and
`CONFIG_LIBFTDI1_CFLAGS` and `CONFIG_LIBFTDI1_LDFLAGS` to set cflags and
ldflags manually.

Change-Id: I41f5186d9f3e063c12c8c6eea888d0b0bf534259
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/58623
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72259
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/Makefile.include b/Makefile.include
index b723e8d..d38552d 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -33,11 +33,23 @@
 
 # Run the C Preprocessor with file $1 and return the last line, removing quotes.
 define c_macro_test
-$(strip $(shell $(CC) -E $1 2>/dev/null | tail -n 1 | tr -d '"'))
+$(strip $(call debug_shell, $(CC) -E $1 | tail -n 1 | tr -d '"'))
 endef
 
-define c_compile_test
-$(shell $(CC) -c -Wall -Werror -o /dev/null $1 2>/dev/null && echo yes || echo no)
+define c_compile_test # $1: files to compile, $2: cflags
+$(call debug_shell, $(CC) -c -Wall -Werror $2 $1 -o /dev/null && echo yes || echo no)
+endef
+
+define find_dependency
+$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --exists $1 && echo yes || echo no)
+endef
+
+define dependency_cflags
+$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --cflags $1 2>/dev/null)
+endef
+
+define dependency_ldflags
+$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --libs $1 2>/dev/null)
 endef
 
 define LIBPCI_TEST
@@ -111,25 +123,6 @@
 endef
 export LIBJAYLINK_TEST
 
-define FTDI_TEST
-#include <stdlib.h>
-#include <ftdi.h>
-struct ftdi_context *ftdic = NULL;
-int main(int argc, char **argv)
-{
-	(void) argc;
-	(void) argv;
-	return ftdi_init(ftdic);
-}
-endef
-export FTDI_TEST
-
-define FTDI_232H_TEST
-#include <ftdi.h>
-enum ftdi_chip_type type = TYPE_232H;
-endef
-export FTDI_232H_TEST
-
 define NI845X_TEST
 #include <ni845x.h>