Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Andy Shevchenko | 8674cea | 2016-06-19 23:41:11 +0300 | [diff] [blame] | 2 | include ../scripts/Makefile.include |
| 3 | |
Andy Shevchenko | 5349910 | 2016-06-19 23:41:12 +0300 | [diff] [blame] | 4 | bindir ?= /usr/bin |
| 5 | |
Andy Shevchenko | 8674cea | 2016-06-19 23:41:11 +0300 | [diff] [blame] | 6 | ifeq ($(srctree),) |
Uwe Kleine-König | e19b7ce | 2016-11-22 09:30:26 +0100 | [diff] [blame] | 7 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
Andy Shevchenko | 8674cea | 2016-06-19 23:41:11 +0300 | [diff] [blame] | 8 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 9 | endif |
| 10 | |
| 11 | # Do not use make's built-in rules |
| 12 | # (this improves performance and avoids hard-to-debug behaviour); |
| 13 | MAKEFLAGS += -r |
| 14 | |
Linus Walleij | 6d591c4 | 2015-10-21 15:45:54 +0200 | [diff] [blame] | 15 | CC = $(CROSS_COMPILE)gcc |
Andy Shevchenko | 8674cea | 2016-06-19 23:41:11 +0300 | [diff] [blame] | 16 | LD = $(CROSS_COMPILE)ld |
| 17 | CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include |
Linus Walleij | 6d591c4 | 2015-10-21 15:45:54 +0200 | [diff] [blame] | 18 | |
Andy Shevchenko | 8674cea | 2016-06-19 23:41:11 +0300 | [diff] [blame] | 19 | ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon |
| 20 | ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS)) |
Linus Walleij | 6d591c4 | 2015-10-21 15:45:54 +0200 | [diff] [blame] | 21 | |
Andy Shevchenko | 8674cea | 2016-06-19 23:41:11 +0300 | [diff] [blame] | 22 | all: $(ALL_PROGRAMS) |
Linus Walleij | 6d591c4 | 2015-10-21 15:45:54 +0200 | [diff] [blame] | 23 | |
Andy Shevchenko | 8674cea | 2016-06-19 23:41:11 +0300 | [diff] [blame] | 24 | export srctree OUTPUT CC LD CFLAGS |
| 25 | include $(srctree)/tools/build/Makefile.include |
Linus Walleij | 6d591c4 | 2015-10-21 15:45:54 +0200 | [diff] [blame] | 26 | |
Andy Shevchenko | 8674cea | 2016-06-19 23:41:11 +0300 | [diff] [blame] | 27 | # |
| 28 | # We need the following to be outside of kernel tree |
| 29 | # |
| 30 | $(OUTPUT)include/linux/gpio.h: ../../include/uapi/linux/gpio.h |
| 31 | mkdir -p $(OUTPUT)include/linux 2>&1 || true |
| 32 | ln -sf $(CURDIR)/../../include/uapi/linux/gpio.h $@ |
| 33 | |
| 34 | prepare: $(OUTPUT)include/linux/gpio.h |
| 35 | |
| 36 | # |
| 37 | # lsgpio |
| 38 | # |
| 39 | LSGPIO_IN := $(OUTPUT)lsgpio-in.o |
| 40 | $(LSGPIO_IN): prepare FORCE |
| 41 | $(Q)$(MAKE) $(build)=lsgpio |
| 42 | $(OUTPUT)lsgpio: $(LSGPIO_IN) |
| 43 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ |
| 44 | |
| 45 | # |
| 46 | # gpio-hammer |
| 47 | # |
| 48 | GPIO_HAMMER_IN := $(OUTPUT)gpio-hammer-in.o |
| 49 | $(GPIO_HAMMER_IN): prepare FORCE |
| 50 | $(Q)$(MAKE) $(build)=gpio-hammer |
| 51 | $(OUTPUT)gpio-hammer: $(GPIO_HAMMER_IN) |
| 52 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ |
| 53 | |
| 54 | # |
| 55 | # gpio-event-mon |
| 56 | # |
| 57 | GPIO_EVENT_MON_IN := $(OUTPUT)gpio-event-mon-in.o |
| 58 | $(GPIO_EVENT_MON_IN): prepare FORCE |
| 59 | $(Q)$(MAKE) $(build)=gpio-event-mon |
| 60 | $(OUTPUT)gpio-event-mon: $(GPIO_EVENT_MON_IN) |
| 61 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ |
| 62 | |
Linus Walleij | 6d591c4 | 2015-10-21 15:45:54 +0200 | [diff] [blame] | 63 | clean: |
Andy Shevchenko | 8674cea | 2016-06-19 23:41:11 +0300 | [diff] [blame] | 64 | rm -f $(ALL_PROGRAMS) |
| 65 | rm -f $(OUTPUT)include/linux/gpio.h |
| 66 | find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete |
| 67 | |
Andy Shevchenko | 5349910 | 2016-06-19 23:41:12 +0300 | [diff] [blame] | 68 | install: $(ALL_PROGRAMS) |
| 69 | install -d -m 755 $(DESTDIR)$(bindir); \ |
| 70 | for program in $(ALL_PROGRAMS); do \ |
| 71 | install $$program $(DESTDIR)$(bindir); \ |
| 72 | done |
| 73 | |
Andy Shevchenko | 8674cea | 2016-06-19 23:41:11 +0300 | [diff] [blame] | 74 | FORCE: |
| 75 | |
Andy Shevchenko | 5349910 | 2016-06-19 23:41:12 +0300 | [diff] [blame] | 76 | .PHONY: all install clean FORCE prepare |