Makefile 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. include ../scripts/Makefile.include
  2. bindir ?= /usr/bin
  3. ifeq ($(srctree),)
  4. srctree := $(patsubst %/,%,$(dir $(shell pwd)))
  5. srctree := $(patsubst %/,%,$(dir $(srctree)))
  6. endif
  7. # Do not use make's built-in rules
  8. # (this improves performance and avoids hard-to-debug behaviour);
  9. MAKEFLAGS += -r
  10. CC = $(CROSS_COMPILE)gcc
  11. LD = $(CROSS_COMPILE)ld
  12. CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
  13. ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon
  14. ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
  15. all: $(ALL_PROGRAMS)
  16. export srctree OUTPUT CC LD CFLAGS
  17. include $(srctree)/tools/build/Makefile.include
  18. #
  19. # We need the following to be outside of kernel tree
  20. #
  21. $(OUTPUT)include/linux/gpio.h: ../../include/uapi/linux/gpio.h
  22. mkdir -p $(OUTPUT)include/linux 2>&1 || true
  23. ln -sf $(CURDIR)/../../include/uapi/linux/gpio.h $@
  24. prepare: $(OUTPUT)include/linux/gpio.h
  25. #
  26. # lsgpio
  27. #
  28. LSGPIO_IN := $(OUTPUT)lsgpio-in.o
  29. $(LSGPIO_IN): prepare FORCE
  30. $(Q)$(MAKE) $(build)=lsgpio
  31. $(OUTPUT)lsgpio: $(LSGPIO_IN)
  32. $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
  33. #
  34. # gpio-hammer
  35. #
  36. GPIO_HAMMER_IN := $(OUTPUT)gpio-hammer-in.o
  37. $(GPIO_HAMMER_IN): prepare FORCE
  38. $(Q)$(MAKE) $(build)=gpio-hammer
  39. $(OUTPUT)gpio-hammer: $(GPIO_HAMMER_IN)
  40. $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
  41. #
  42. # gpio-event-mon
  43. #
  44. GPIO_EVENT_MON_IN := $(OUTPUT)gpio-event-mon-in.o
  45. $(GPIO_EVENT_MON_IN): prepare FORCE
  46. $(Q)$(MAKE) $(build)=gpio-event-mon
  47. $(OUTPUT)gpio-event-mon: $(GPIO_EVENT_MON_IN)
  48. $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
  49. clean:
  50. rm -f $(ALL_PROGRAMS)
  51. rm -f $(OUTPUT)include/linux/gpio.h
  52. find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
  53. install: $(ALL_PROGRAMS)
  54. install -d -m 755 $(DESTDIR)$(bindir); \
  55. for program in $(ALL_PROGRAMS); do \
  56. install $$program $(DESTDIR)$(bindir); \
  57. done
  58. FORCE:
  59. .PHONY: all install clean FORCE prepare