Makefile 2.2 KB

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