# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_TYPEC)		+= typec.o
typec-y				:= class.o mux.o bus.o pd.o retimer.o
typec-$(CONFIG_ACPI)		+= port-mapper.o
obj-$(CONFIG_TYPEC)		+= altmodes/
obj-$(CONFIG_TYPEC_TCPM)	+= tcpm/
obj-$(CONFIG_TYPEC_UCSI)	+= ucsi/
obj-$(CONFIG_TYPEC_TPS6598X)	+= tipd/
obj-$(CONFIG_TYPEC_ANX7411)	+= anx7411-drv.o
anx7411-drv-y			+= anx7411.o
obj-$(CONFIG_TYPEC_PHYTIUM_RS)	+= role-switch-phytium.o
obj-$(CONFIG_TYPEC_HD3SS3220)	+= hd3ss3220-drv.o
hd3ss3220-drv-y			+= hd3ss3220.o
obj-$(CONFIG_TYPEC_STUSB160X) 	+= stusb160x-drv.o
stusb160x-drv-y			+= stusb160x.o
obj-$(CONFIG_TYPEC_RT1719)	+= rt1719-drv.o
rt1719-drv-y			+= rt1719.o
obj-$(CONFIG_TYPEC_WUSB3801)	+= wusb3801-drv.o
wusb3801-drv-y			+= wusb3801.o
obj-$(CONFIG_TYPEC_RTS5453)	+= rts5453-drv.o
rts5453-drv-y			+= rts5453.o
obj-$(CONFIG_TYPEC)		+= mux/

# Option B: Link Rust only when built-in (=y), avoiding symbol pollution during module build.
# (hd3ss3220_drv <-> rts5453_drv)
ifdef CONFIG_RUST_DRIVERS
RUST_DRV := usb/typec
include $(srctree)/drivers/rust/templates/kbuild-rust-driver.mk

# Build Rust objects separately for each driver (CARGO_FEATURES=driver_name), only reference C symbols of that driver
define rust_typec_one
$(obj)/rust/typec_$(1)_rust.o: FORCE
	$$(Q)mkdir -p $$(dir $$@)
	$$(Q)OBJTREE=$$(abspath $$(objtree)) OBJ=$$(abspath $$(obj)) OUTPUT_FILE=$$(abspath $$@).__rust_tmp CARGO_FEATURES=$(1) CROSS_COMPILE="$$(CROSS_COMPILE)" $$(RUST_BUILD_SH)
	$$(Q)if [ ! -f $$@ ] || ! cmp -s $$@.__rust_tmp $$@; then \
		mv $$@.__rust_tmp $$@; \
	else \
		rm -f $$@.__rust_tmp; \
	fi
	$$(Q)echo 'savedcmd_$$@ := rust-build $$(RUST_BUILD_SH)' > $$(dir $$@).$$(notdir $$@).cmd
OBJECT_FILES_NON_STANDARD_typec_$(1)_rust.o := y
endef
$(foreach _d,hd3ss3220 rts5453 anx7411 stusb160x rt1719 wusb3801,$(eval $(call rust_typec_one,$(_d))))

ifneq ($(CONFIG_TYPEC_ANX7411),)
anx7411-drv-y += rust/typec_anx7411_rust.o
endif
ifneq ($(CONFIG_TYPEC_STUSB160X),)
stusb160x-drv-y += rust/typec_stusb160x_rust.o
endif
ifneq ($(CONFIG_TYPEC_RT1719),)
rt1719-drv-y += rust/typec_rt1719_rust.o
endif
ifneq ($(CONFIG_TYPEC_WUSB3801),)
wusb3801-drv-y += rust/typec_wusb3801_rust.o
endif
ifneq ($(CONFIG_TYPEC_HD3SS3220),)
hd3ss3220-drv-y += rust/typec_hd3ss3220_rust.o
endif
ifneq ($(CONFIG_TYPEC_RTS5453),)
rts5453-drv-y += rust/typec_rts5453_rust.o
endif
endif
