blob: 5a82f15d0071f4f57433b6de870e70b985846da8 [file] [log] [blame]
Andy Shevchenko8674cea2016-06-19 23:41:11 +03001include ../scripts/Makefile.include
2
3ifeq ($(srctree),)
4srctree := $(patsubst %/,%,$(dir $(shell pwd)))
5srctree := $(patsubst %/,%,$(dir $(srctree)))
6endif
7
8# Do not use make's built-in rules
9# (this improves performance and avoids hard-to-debug behaviour);
10MAKEFLAGS += -r
11
Linus Walleij6d591c42015-10-21 15:45:54 +020012CC = $(CROSS_COMPILE)gcc
Andy Shevchenko8674cea2016-06-19 23:41:11 +030013LD = $(CROSS_COMPILE)ld
14CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
Linus Walleij6d591c42015-10-21 15:45:54 +020015
Andy Shevchenko8674cea2016-06-19 23:41:11 +030016ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon
17ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
Linus Walleij6d591c42015-10-21 15:45:54 +020018
Andy Shevchenko8674cea2016-06-19 23:41:11 +030019all: $(ALL_PROGRAMS)
Linus Walleij6d591c42015-10-21 15:45:54 +020020
Andy Shevchenko8674cea2016-06-19 23:41:11 +030021export srctree OUTPUT CC LD CFLAGS
22include $(srctree)/tools/build/Makefile.include
Linus Walleij6d591c42015-10-21 15:45:54 +020023
Andy Shevchenko8674cea2016-06-19 23:41:11 +030024#
25# We need the following to be outside of kernel tree
26#
27$(OUTPUT)include/linux/gpio.h: ../../include/uapi/linux/gpio.h
28 mkdir -p $(OUTPUT)include/linux 2>&1 || true
29 ln -sf $(CURDIR)/../../include/uapi/linux/gpio.h $@
30
31prepare: $(OUTPUT)include/linux/gpio.h
32
33#
34# lsgpio
35#
36LSGPIO_IN := $(OUTPUT)lsgpio-in.o
37$(LSGPIO_IN): prepare FORCE
38 $(Q)$(MAKE) $(build)=lsgpio
39$(OUTPUT)lsgpio: $(LSGPIO_IN)
40 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
41
42#
43# gpio-hammer
44#
45GPIO_HAMMER_IN := $(OUTPUT)gpio-hammer-in.o
46$(GPIO_HAMMER_IN): prepare FORCE
47 $(Q)$(MAKE) $(build)=gpio-hammer
48$(OUTPUT)gpio-hammer: $(GPIO_HAMMER_IN)
49 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
50
51#
52# gpio-event-mon
53#
54GPIO_EVENT_MON_IN := $(OUTPUT)gpio-event-mon-in.o
55$(GPIO_EVENT_MON_IN): prepare FORCE
56 $(Q)$(MAKE) $(build)=gpio-event-mon
57$(OUTPUT)gpio-event-mon: $(GPIO_EVENT_MON_IN)
58 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
59
Linus Walleij6d591c42015-10-21 15:45:54 +020060clean:
Andy Shevchenko8674cea2016-06-19 23:41:11 +030061 rm -f $(ALL_PROGRAMS)
62 rm -f $(OUTPUT)include/linux/gpio.h
63 find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
64
65FORCE:
66
67.PHONY: all clean FORCE prepare