tools/gpio: move to tools buildsystem
[cascardo/linux.git] / tools / gpio / Makefile
1 include ../scripts/Makefile.include
2
3 ifeq ($(srctree),)
4 srctree := $(patsubst %/,%,$(dir $(shell pwd)))
5 srctree := $(patsubst %/,%,$(dir $(srctree)))
6 endif
7
8 # Do not use make's built-in rules
9 # (this improves performance and avoids hard-to-debug behaviour);
10 MAKEFLAGS += -r
11
12 CC = $(CROSS_COMPILE)gcc
13 LD = $(CROSS_COMPILE)ld
14 CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
15
16 ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon
17 ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
18
19 all: $(ALL_PROGRAMS)
20
21 export srctree OUTPUT CC LD CFLAGS
22 include $(srctree)/tools/build/Makefile.include
23
24 #
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
31 prepare: $(OUTPUT)include/linux/gpio.h
32
33 #
34 # lsgpio
35 #
36 LSGPIO_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 #
45 GPIO_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 #
54 GPIO_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
60 clean:
61         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
65 FORCE:
66
67 .PHONY: all clean FORCE prepare