xref: /linux/tools/gpio/Makefile (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
28674cea8SAndy Shevchenkoinclude ../scripts/Makefile.include
38674cea8SAndy Shevchenko
453499109SAndy Shevchenkobindir ?= /usr/bin
553499109SAndy Shevchenko
64a6a6f5cSShuah Khan# This will work when gpio is built in tools env. where srctree
74a6a6f5cSShuah Khan# isn't set and when invoked from selftests build, where srctree
84a6a6f5cSShuah Khan# is set to ".". building_out_of_srctree is undefined for in srctree
94a6a6f5cSShuah Khan# builds
104a6a6f5cSShuah Khanifndef building_out_of_srctree
11e19b7ceeSUwe Kleine-Königsrctree := $(patsubst %/,%,$(dir $(CURDIR)))
128674cea8SAndy Shevchenkosrctree := $(patsubst %/,%,$(dir $(srctree)))
138674cea8SAndy Shevchenkoendif
148674cea8SAndy Shevchenko
158674cea8SAndy Shevchenko# Do not use make's built-in rules
168674cea8SAndy Shevchenko# (this improves performance and avoids hard-to-debug behaviour);
178674cea8SAndy ShevchenkoMAKEFLAGS += -r
188674cea8SAndy Shevchenko
194ccc98a4SJiri Olsaoverride CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
206d591c46SLinus Walleij
2133f0c47bSBartosz GolaszewskiALL_TARGETS := lsgpio gpio-hammer gpio-event-mon gpio-watch
228674cea8SAndy ShevchenkoALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
236d591c46SLinus Walleij
248674cea8SAndy Shevchenkoall: $(ALL_PROGRAMS)
256d591c46SLinus Walleij
268674cea8SAndy Shevchenkoexport srctree OUTPUT CC LD CFLAGS
278674cea8SAndy Shevchenkoinclude $(srctree)/tools/build/Makefile.include
286d591c46SLinus Walleij
298674cea8SAndy Shevchenko#
308674cea8SAndy Shevchenko# We need the following to be outside of kernel tree
318674cea8SAndy Shevchenko#
328674cea8SAndy Shevchenko$(OUTPUT)include/linux/gpio.h: ../../include/uapi/linux/gpio.h
338674cea8SAndy Shevchenko	mkdir -p $(OUTPUT)include/linux 2>&1 || true
348674cea8SAndy Shevchenko	ln -sf $(CURDIR)/../../include/uapi/linux/gpio.h $@
358674cea8SAndy Shevchenko
368674cea8SAndy Shevchenkoprepare: $(OUTPUT)include/linux/gpio.h
378674cea8SAndy Shevchenko
3882f04bfeSAnssi HannulaGPIO_UTILS_IN := $(OUTPUT)gpio-utils-in.o
390161a94eSLaura Abbott$(GPIO_UTILS_IN): prepare FORCE
400161a94eSLaura Abbott	$(Q)$(MAKE) $(build)=gpio-utils
410161a94eSLaura Abbott
428674cea8SAndy Shevchenko#
438674cea8SAndy Shevchenko# lsgpio
448674cea8SAndy Shevchenko#
458674cea8SAndy ShevchenkoLSGPIO_IN := $(OUTPUT)lsgpio-in.o
460161a94eSLaura Abbott$(LSGPIO_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o
478674cea8SAndy Shevchenko	$(Q)$(MAKE) $(build)=lsgpio
488674cea8SAndy Shevchenko$(OUTPUT)lsgpio: $(LSGPIO_IN)
498674cea8SAndy Shevchenko	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
508674cea8SAndy Shevchenko
518674cea8SAndy Shevchenko#
528674cea8SAndy Shevchenko# gpio-hammer
538674cea8SAndy Shevchenko#
548674cea8SAndy ShevchenkoGPIO_HAMMER_IN := $(OUTPUT)gpio-hammer-in.o
550161a94eSLaura Abbott$(GPIO_HAMMER_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o
568674cea8SAndy Shevchenko	$(Q)$(MAKE) $(build)=gpio-hammer
578674cea8SAndy Shevchenko$(OUTPUT)gpio-hammer: $(GPIO_HAMMER_IN)
588674cea8SAndy Shevchenko	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
598674cea8SAndy Shevchenko
608674cea8SAndy Shevchenko#
618674cea8SAndy Shevchenko# gpio-event-mon
628674cea8SAndy Shevchenko#
638674cea8SAndy ShevchenkoGPIO_EVENT_MON_IN := $(OUTPUT)gpio-event-mon-in.o
640161a94eSLaura Abbott$(GPIO_EVENT_MON_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o
658674cea8SAndy Shevchenko	$(Q)$(MAKE) $(build)=gpio-event-mon
668674cea8SAndy Shevchenko$(OUTPUT)gpio-event-mon: $(GPIO_EVENT_MON_IN)
678674cea8SAndy Shevchenko	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
688674cea8SAndy Shevchenko
6933f0c47bSBartosz Golaszewski#
7033f0c47bSBartosz Golaszewski# gpio-watch
7133f0c47bSBartosz Golaszewski#
7233f0c47bSBartosz GolaszewskiGPIO_WATCH_IN := $(OUTPUT)gpio-watch-in.o
7333f0c47bSBartosz Golaszewski$(GPIO_WATCH_IN): prepare FORCE
7433f0c47bSBartosz Golaszewski	$(Q)$(MAKE) $(build)=gpio-watch
7533f0c47bSBartosz Golaszewski$(OUTPUT)gpio-watch: $(GPIO_WATCH_IN)
7633f0c47bSBartosz Golaszewski	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
7733f0c47bSBartosz Golaszewski
786d591c46SLinus Walleijclean:
798674cea8SAndy Shevchenko	rm -f $(ALL_PROGRAMS)
808674cea8SAndy Shevchenko	rm -f $(OUTPUT)include/linux/gpio.h
81*931a36c4Szhangjiao	find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete -o -name '\.*.cmd' -delete
828674cea8SAndy Shevchenko
8353499109SAndy Shevchenkoinstall: $(ALL_PROGRAMS)
8453499109SAndy Shevchenko	install -d -m 755 $(DESTDIR)$(bindir);		\
8553499109SAndy Shevchenko	for program in $(ALL_PROGRAMS); do		\
8653499109SAndy Shevchenko		install $$program $(DESTDIR)$(bindir);	\
8753499109SAndy Shevchenko	done
8853499109SAndy Shevchenko
898674cea8SAndy ShevchenkoFORCE:
908674cea8SAndy Shevchenko
9153499109SAndy Shevchenko.PHONY: all install clean FORCE prepare
92