genvif: Allow usb_pd_policy.c only in baseboard
Update rules for util/genvif to allow usb_pd_policy.c to be present
in just baseboard, or just board, or both.
BRANCH=none
TEST=make -j buildall
@@ -39,19 +39,23 @@ ec_parse_panicinfo-objs=ec_parse_panicinfo.o ec_panicinfo.o
ifeq ($(CONFIG_USB_POWER_DELIVERY),y)
build-util-bin+=genvif
build-util-art+=$(BOARD)_vif.txt
-$(out)/util/genvif: $(out)/util/usb_pd_policy.o board/$(BOARD)/board.h \
+
+# usb_pd_policy.c can be in baseboard, or board, or both.
+genvif-pd-srcs=$(sort $(wildcard $(BASEDIR)/usb_pd_policy.c \
+ board/$(BOARD)/usb_pd_policy.c))
+genvif-pd-objs=$(genvif-pd-srcs:%.c=$(out)/util/%.o)
+deps-$(CONFIG_USB_POWER_DELIVERY) += $(genvif-pd-objs:%.o=%.o.d)
+
+$(out)/util/genvif: $(genvif-pd-objs) board/$(BOARD)/board.h \
include/usb_pd.h include/usb_pd_tcpm.h
-$(out)/util/genvif: BUILD_LDFLAGS+=$(out)/util/usb_pd_policy.o -flto
+$(out)/util/genvif: BUILD_LDFLAGS+=$(genvif-pd-objs) -flto
STANDALONE_FLAGS=-ffreestanding -fno-builtin -nostdinc \
-Ibuiltin/ -D"__keep= " -DVIF_BUILD
-# If baseboard is defined, include its usb_pd_policy; otherwise,
-# $(BASEDIR) will alias to `board/$(BOARD)` and includes same board file twice.
-$(out)/util/usb_pd_policy.o: $(BASEDIR)/usb_pd_policy.c \
- board/$(BOARD)/usb_pd_policy.c
+$(out)/util/%/usb_pd_policy.o: %/usb_pd_policy.c
+ -@ mkdir -p $(@D)
$(call quiet,c_to_vif,BUILDCC)
-deps-$(CONFIG_USB_POWER_DELIVERY) += $(out)/util/usb_pd_policy.o.d
endif # CONFIG_USB_POWER_DELIVERY
ifneq ($(CONFIG_TOUCHPAD_HASH_FW),)
