at commit c03c1a14
| 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | include ../scripts/Makefile.include |
| 3 | |
| 4 | bindir ?= /usr/bin |
| 5 | |
| 6 | # This will work when gpio is built in tools env. where srctree |
| 7 | # isn't set and when invoked from selftests build, where srctree |
| 8 | # is set to ".". building_out_of_srctree is undefined for in srctree |
| 9 | # builds |
| 10 | ifeq ($(srctree),) |
| 11 | update_srctree := 1 |
| 12 | endif |
| 13 | ifndef building_out_of_srctree |
| 14 | update_srctree := 1 |
| 15 | endif |
| 16 | ifeq ($(update_srctree),1) |
| 17 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 18 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 19 | endif |
| 20 | |
| 21 | # Do not use make's built-in rules |
| 22 | # (this improves performance and avoids hard-to-debug behaviour); |
| 23 | MAKEFLAGS += -r |
| 24 | |
| 25 | override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include |
| 26 | |
| 27 | ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon gpio-watch |
| 28 | ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS)) |
| 29 | |
| 30 | all: $(ALL_PROGRAMS) |
| 31 | |
| 32 | export srctree OUTPUT CC LD CFLAGS |
| 33 | include $(srctree)/tools/build/Makefile.include |
| 34 | |
| 35 | # |
| 36 | # We need the following to be outside of kernel tree |
| 37 | # |
| 38 | $(OUTPUT)include/linux/gpio.h: ../../include/uapi/linux/gpio.h |
| 39 | mkdir -p $(OUTPUT)include/linux 2>&1 || true |
| 40 | ln -sf $(CURDIR)/../../include/uapi/linux/gpio.h $@ |
| 41 | |
| 42 | prepare: $(OUTPUT)include/linux/gpio.h |
| 43 | |
| 44 | GPIO_UTILS_IN := $(OUTPUT)gpio-utils-in.o |
| 45 | $(GPIO_UTILS_IN): prepare FORCE |
| 46 | $(Q)$(MAKE) $(build)=gpio-utils |
| 47 | |
| 48 | # |
| 49 | # lsgpio |
| 50 | # |
| 51 | LSGPIO_IN := $(OUTPUT)lsgpio-in.o |
| 52 | $(LSGPIO_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o |
| 53 | $(Q)$(MAKE) $(build)=lsgpio |
| 54 | $(OUTPUT)lsgpio: $(LSGPIO_IN) |
| 55 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ |
| 56 | |
| 57 | # |
| 58 | # gpio-hammer |
| 59 | # |
| 60 | GPIO_HAMMER_IN := $(OUTPUT)gpio-hammer-in.o |
| 61 | $(GPIO_HAMMER_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o |
| 62 | $(Q)$(MAKE) $(build)=gpio-hammer |
| 63 | $(OUTPUT)gpio-hammer: $(GPIO_HAMMER_IN) |
| 64 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ |
| 65 | |
| 66 | # |
| 67 | # gpio-event-mon |
| 68 | # |
| 69 | GPIO_EVENT_MON_IN := $(OUTPUT)gpio-event-mon-in.o |
| 70 | $(GPIO_EVENT_MON_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o |
| 71 | $(Q)$(MAKE) $(build)=gpio-event-mon |
| 72 | $(OUTPUT)gpio-event-mon: $(GPIO_EVENT_MON_IN) |
| 73 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ |
| 74 | |
| 75 | # |
| 76 | # gpio-watch |
| 77 | # |
| 78 | GPIO_WATCH_IN := $(OUTPUT)gpio-watch-in.o |
| 79 | $(GPIO_WATCH_IN): prepare FORCE |
| 80 | $(Q)$(MAKE) $(build)=gpio-watch |
| 81 | $(OUTPUT)gpio-watch: $(GPIO_WATCH_IN) |
| 82 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ |
| 83 | |
| 84 | clean: |
| 85 | rm -f $(ALL_PROGRAMS) |
| 86 | rm -rf $(OUTPUT)include |
| 87 | find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete -o -name '\.*.cmd' -delete |
| 88 | |
| 89 | install: $(ALL_PROGRAMS) |
| 90 | install -d -m 755 $(DESTDIR)$(bindir); \ |
| 91 | for program in $(ALL_PROGRAMS); do \ |
| 92 | install $$program $(DESTDIR)$(bindir); \ |
| 93 | done |
| 94 | |
| 95 | FORCE: |
| 96 | |
| 97 | .PHONY: all install clean FORCE prepare |