18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ciinclude ../scripts/Makefile.include
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_cibindir ?= /usr/bin
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciifeq ($(srctree),)
78c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(CURDIR)))
88c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree)))
98c2ecf20Sopenharmony_ciendif
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci# Do not use make's built-in rules
128c2ecf20Sopenharmony_ci# (this improves performance and avoids hard-to-debug behaviour);
138c2ecf20Sopenharmony_ciMAKEFLAGS += -r
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciCFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ciALL_TARGETS := spidev_test spidev_fdx
188c2ecf20Sopenharmony_ciALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciall: $(ALL_PROGRAMS)
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciexport srctree OUTPUT CC LD CFLAGS
238c2ecf20Sopenharmony_ciinclude $(srctree)/tools/build/Makefile.include
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#
268c2ecf20Sopenharmony_ci# We need the following to be outside of kernel tree
278c2ecf20Sopenharmony_ci#
288c2ecf20Sopenharmony_ci$(OUTPUT)include/linux/spi/spidev.h: ../../include/uapi/linux/spi/spidev.h
298c2ecf20Sopenharmony_ci	mkdir -p $(OUTPUT)include/linux/spi 2>&1 || true
308c2ecf20Sopenharmony_ci	ln -sf $(CURDIR)/../../include/uapi/linux/spi/spidev.h $@
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciprepare: $(OUTPUT)include/linux/spi/spidev.h
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#
358c2ecf20Sopenharmony_ci# spidev_test
368c2ecf20Sopenharmony_ci#
378c2ecf20Sopenharmony_ciSPIDEV_TEST_IN := $(OUTPUT)spidev_test-in.o
388c2ecf20Sopenharmony_ci$(SPIDEV_TEST_IN): prepare FORCE
398c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(build)=spidev_test
408c2ecf20Sopenharmony_ci$(OUTPUT)spidev_test: $(SPIDEV_TEST_IN)
418c2ecf20Sopenharmony_ci	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#
448c2ecf20Sopenharmony_ci# spidev_fdx
458c2ecf20Sopenharmony_ci#
468c2ecf20Sopenharmony_ciSPIDEV_FDX_IN := $(OUTPUT)spidev_fdx-in.o
478c2ecf20Sopenharmony_ci$(SPIDEV_FDX_IN): prepare FORCE
488c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(build)=spidev_fdx
498c2ecf20Sopenharmony_ci$(OUTPUT)spidev_fdx: $(SPIDEV_FDX_IN)
508c2ecf20Sopenharmony_ci	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciclean:
538c2ecf20Sopenharmony_ci	rm -f $(ALL_PROGRAMS)
548c2ecf20Sopenharmony_ci	rm -rf $(OUTPUT)include/
558c2ecf20Sopenharmony_ci	find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete
568c2ecf20Sopenharmony_ci	find $(if $(OUTPUT),$(OUTPUT),.) -name '\.*.o.d' -delete
578c2ecf20Sopenharmony_ci	find $(if $(OUTPUT),$(OUTPUT),.) -name '\.*.o.cmd' -delete
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciinstall: $(ALL_PROGRAMS)
608c2ecf20Sopenharmony_ci	install -d -m 755 $(DESTDIR)$(bindir);		\
618c2ecf20Sopenharmony_ci	for program in $(ALL_PROGRAMS); do		\
628c2ecf20Sopenharmony_ci		install $$program $(DESTDIR)$(bindir);	\
638c2ecf20Sopenharmony_ci	done
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciFORCE:
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci.PHONY: all install clean FORCE prepare
68