Makefile 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # SPDX-License-Identifier: GPL-2.0
  2. include ../scripts/Makefile.include
  3. bindir ?= /usr/bin
  4. ifeq ($(srctree),)
  5. srctree := $(patsubst %/,%,$(dir $(CURDIR)))
  6. srctree := $(patsubst %/,%,$(dir $(srctree)))
  7. endif
  8. # Do not use make's built-in rules
  9. # (this improves performance and avoids hard-to-debug behaviour);
  10. MAKEFLAGS += -r
  11. override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include \
  12. -I$(srctree)/tools/include
  13. ALL_TARGETS := counter_example counter_watch_events
  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/counter.h: ../../include/uapi/linux/counter.h
  22. mkdir -p $(OUTPUT)include/linux 2>&1 || true
  23. ln -sf $(CURDIR)/../../include/uapi/linux/counter.h $@
  24. prepare: $(OUTPUT)include/linux/counter.h
  25. COUNTER_EXAMPLE := $(OUTPUT)counter_example.o
  26. $(COUNTER_EXAMPLE): prepare FORCE
  27. $(Q)$(MAKE) $(build)=counter_example
  28. $(OUTPUT)counter_example: $(COUNTER_EXAMPLE)
  29. $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
  30. COUNTER_WATCH_EVENTS := $(OUTPUT)counter_watch_events.o
  31. $(COUNTER_WATCH_EVENTS): prepare FORCE
  32. $(Q)$(MAKE) $(build)=counter_watch_events
  33. $(OUTPUT)counter_watch_events: $(COUNTER_WATCH_EVENTS)
  34. $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
  35. clean:
  36. rm -f $(ALL_PROGRAMS)
  37. rm -rf $(OUTPUT)include/linux/counter.h
  38. rm -df $(OUTPUT)include/linux
  39. rm -df $(OUTPUT)include
  40. find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
  41. find $(or $(OUTPUT),.) -name '\.*.o.cmd' -delete
  42. install: $(ALL_PROGRAMS)
  43. install -d -m 755 $(DESTDIR)$(bindir); \
  44. for program in $(ALL_PROGRAMS); do \
  45. install $$program $(DESTDIR)$(bindir); \
  46. done
  47. FORCE:
  48. .PHONY: all install clean FORCE prepare