Makefile: use HAS_ USE_ pattern for serial support

Align the usage of serial function with the selection of other
dependencies.

Change-Id: Ica951e76d6362b01f09d23a729a2a6049e7f0b66
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/62196
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72307
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/Makefile b/Makefile
index 655be30..bdc0117 100644
--- a/Makefile
+++ b/Makefile
@@ -98,6 +98,9 @@
 	CONFIG_PONY_SPI \
 	CONFIG_SERPROG \
 
+DEPENDS_ON_SOCKETS := \
+	CONFIG_SERPROG \
+
 DEPENDS_ON_BITBANG_SPI := \
 	CONFIG_DEVELOPERBOX_SPI \
 	CONFIG_INTERNAL_X86 \
@@ -246,6 +249,7 @@
 HAS_LINUX_MTD       := $(call c_compile_test, Makefile.d/linux_mtd_test.c)
 HAS_LINUX_SPI       := $(call c_compile_test, Makefile.d/linux_spi_test.c)
 HAS_LINUX_I2C       := $(call c_compile_test, Makefile.d/linux_i2c_test.c)
+HAS_SERIAL          := $(strip $(if $(filter $(TARGET_OS), DOS libpayload), no, yes))
 EXEC_SUFFIX         := $(strip $(if $(filter $(TARGET_OS), DOS MinGW), .exe))
 
 ifeq ($(TARGET_OS), NetBSD)
@@ -257,8 +261,6 @@
 # DJGPP has odd uint*_t definitions which cause lots of format string warnings.
 override CFLAGS += -Wno-format
 override LDFLAGS += -lgetopt
-# Missing serial support.
-$(call mark_unsupported,$(DEPENDS_ON_SERIAL))
 endif
 
 ifeq ($(TARGET_OS), $(filter $(TARGET_OS), MinGW Cygwin))
@@ -297,8 +299,6 @@
 $(call mark_unsupported,CONFIG_DUMMY)
 # libpayload does not provide the romsize field in struct pci_dev that the atapromise code requires.
 $(call mark_unsupported,CONFIG_ATAPROMISE)
-# Bus Pirate, Serprog and PonyProg are not supported with libpayload (missing serial support).
-$(call mark_unsupported,$(DEPENDS_ON_SERIAL))
 # Dediprog, Developerbox, USB-Blaster, PICkit2, CH341A and FT2232 are not supported with libpayload (missing libusb support).
 $(call mark_unsupported,$(DEPENDS_ON_LIBUSB1) $(DEPENDS_ON_LIBFTDI) $(DEPENDS_ON_LIBJAYLINK))
 endif
@@ -345,6 +345,10 @@
 $(call mark_unsupported,$(DEPENDS_ON_LIBUSB1))
 endif
 
+ifeq ($(HAS_SERIAL), no)
+$(call mark_unsupported, $(DEPENDS_ON_SERIAL))
+endif
+
 ifeq ($(ENDIAN), little)
 FEATURE_FLAGS += -D'__FLASHROM_LITTLE_ENDIAN__=1'
 endif
@@ -606,8 +610,6 @@
 ifeq ($(CONFIG_SERPROG), yes)
 FEATURE_FLAGS += -D'CONFIG_SERPROG=1'
 PROGRAMMER_OBJS += serprog.o
-NEED_SERIAL += CONFIG_SERPROG
-NEED_POSIX_SOCKETS += CONFIG_SERPROG
 endif
 
 ifeq ($(CONFIG_RAYER_SPI), yes)
@@ -618,7 +620,6 @@
 ifeq ($(CONFIG_PONY_SPI), yes)
 FEATURE_FLAGS += -D'CONFIG_PONY_SPI=1'
 PROGRAMMER_OBJS += pony_spi.o
-NEED_SERIAL += CONFIG_PONY_SPI
 endif
 
 ifeq ($(CONFIG_BITBANG_SPI), yes)
@@ -724,7 +725,6 @@
 ifeq ($(CONFIG_BUSPIRATE_SPI), yes)
 FEATURE_FLAGS += -D'CONFIG_BUSPIRATE_SPI=1'
 PROGRAMMER_OBJS += buspirate_spi.o
-NEED_SERIAL += CONFIG_BUSPIRATE_SPI
 endif
 
 ifeq ($(CONFIG_DEDIPROG), yes)
@@ -782,7 +782,8 @@
 PROGRAMMER_OBJS += ni845x_spi.o
 endif
 
-ifneq ($(NEED_SERIAL), )
+USE_SERIAL := $(if $(call filter_deps,$(DEPENDS_ON_SERIAL)),yes,no)
+ifeq ($(USE_SERIAL), yes)
 LIB_OBJS += serial.o
 ifeq ($(TARGET_OS), Linux)
 LIB_OBJS += custom_baud_linux.o
@@ -791,7 +792,8 @@
 endif
 endif
 
-ifneq ($(NEED_POSIX_SOCKETS), )
+USE_SOCKETS := $(if $(call filter_deps,$(DEPENDS_ON_SOCKETS)),yes,no)
+ifeq ($(USE_SOCKETS), yes)
 ifeq ($(TARGET_OS), SunOS)
 override LDFLAGS += -lsocket -lnsl
 endif