xref: /kernel/linux/linux-6.6/tools/gpio/Makefile (revision 62306a36)
162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ciinclude ../scripts/Makefile.include
362306a36Sopenharmony_ci
462306a36Sopenharmony_cibindir ?= /usr/bin
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci# This will work when gpio is built in tools env. where srctree
762306a36Sopenharmony_ci# isn't set and when invoked from selftests build, where srctree
862306a36Sopenharmony_ci# is set to ".". building_out_of_srctree is undefined for in srctree
962306a36Sopenharmony_ci# builds
1062306a36Sopenharmony_ciifndef building_out_of_srctree
1162306a36Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(CURDIR)))
1262306a36Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree)))
1362306a36Sopenharmony_ciendif
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci# Do not use make's built-in rules
1662306a36Sopenharmony_ci# (this improves performance and avoids hard-to-debug behaviour);
1762306a36Sopenharmony_ciMAKEFLAGS += -r
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cioverride CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ciALL_TARGETS := lsgpio gpio-hammer gpio-event-mon gpio-watch
2262306a36Sopenharmony_ciALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciall: $(ALL_PROGRAMS)
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciexport srctree OUTPUT CC LD CFLAGS
2762306a36Sopenharmony_ciinclude $(srctree)/tools/build/Makefile.include
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#
3062306a36Sopenharmony_ci# We need the following to be outside of kernel tree
3162306a36Sopenharmony_ci#
3262306a36Sopenharmony_ci$(OUTPUT)include/linux/gpio.h: ../../include/uapi/linux/gpio.h
3362306a36Sopenharmony_ci	mkdir -p $(OUTPUT)include/linux 2>&1 || true
3462306a36Sopenharmony_ci	ln -sf $(CURDIR)/../../include/uapi/linux/gpio.h $@
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ciprepare: $(OUTPUT)include/linux/gpio.h
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ciGPIO_UTILS_IN := $(OUTPUT)gpio-utils-in.o
3962306a36Sopenharmony_ci$(GPIO_UTILS_IN): prepare FORCE
4062306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=gpio-utils
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#
4362306a36Sopenharmony_ci# lsgpio
4462306a36Sopenharmony_ci#
4562306a36Sopenharmony_ciLSGPIO_IN := $(OUTPUT)lsgpio-in.o
4662306a36Sopenharmony_ci$(LSGPIO_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o
4762306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=lsgpio
4862306a36Sopenharmony_ci$(OUTPUT)lsgpio: $(LSGPIO_IN)
4962306a36Sopenharmony_ci	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#
5262306a36Sopenharmony_ci# gpio-hammer
5362306a36Sopenharmony_ci#
5462306a36Sopenharmony_ciGPIO_HAMMER_IN := $(OUTPUT)gpio-hammer-in.o
5562306a36Sopenharmony_ci$(GPIO_HAMMER_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o
5662306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=gpio-hammer
5762306a36Sopenharmony_ci$(OUTPUT)gpio-hammer: $(GPIO_HAMMER_IN)
5862306a36Sopenharmony_ci	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#
6162306a36Sopenharmony_ci# gpio-event-mon
6262306a36Sopenharmony_ci#
6362306a36Sopenharmony_ciGPIO_EVENT_MON_IN := $(OUTPUT)gpio-event-mon-in.o
6462306a36Sopenharmony_ci$(GPIO_EVENT_MON_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o
6562306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=gpio-event-mon
6662306a36Sopenharmony_ci$(OUTPUT)gpio-event-mon: $(GPIO_EVENT_MON_IN)
6762306a36Sopenharmony_ci	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#
7062306a36Sopenharmony_ci# gpio-watch
7162306a36Sopenharmony_ci#
7262306a36Sopenharmony_ciGPIO_WATCH_IN := $(OUTPUT)gpio-watch-in.o
7362306a36Sopenharmony_ci$(GPIO_WATCH_IN): prepare FORCE
7462306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=gpio-watch
7562306a36Sopenharmony_ci$(OUTPUT)gpio-watch: $(GPIO_WATCH_IN)
7662306a36Sopenharmony_ci	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ciclean:
7962306a36Sopenharmony_ci	rm -f $(ALL_PROGRAMS)
8062306a36Sopenharmony_ci	rm -f $(OUTPUT)include/linux/gpio.h
8162306a36Sopenharmony_ci	find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ciinstall: $(ALL_PROGRAMS)
8462306a36Sopenharmony_ci	install -d -m 755 $(DESTDIR)$(bindir);		\
8562306a36Sopenharmony_ci	for program in $(ALL_PROGRAMS); do		\
8662306a36Sopenharmony_ci		install $$program $(DESTDIR)$(bindir);	\
8762306a36Sopenharmony_ci	done
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciFORCE:
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci.PHONY: all install clean FORCE prepare
92