Makefile 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #
  2. # Makefile template
  3. #
  4. KERNELDIR ?= ../../../kernel/linux/
  5. ################################################################################
  6. PWD ?= $(shell pwd)
  7. ifeq ($(KERNELRELEASE),)
  8. all:
  9. $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
  10. clean:
  11. $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
  12. else
  13. include $(KBUILD_EXTMOD)/../Makefile.toolchain
  14. include $(KBUILD_EXTMOD)/../Makefile.project
  15. include $(KBUILD_EXTMOD)/Makefile.in
  16. obj-m := $(mods)
  17. # undef xxx-objs if $(xxx-objs) only contain xxx.o (contain only 1 object and the name is matched as target)
  18. # undef_prefix_match(): undefine $(1) if $(1) and $($(1)) have the same prefix
  19. # parameter $(1) is like xxx-objs, which is a name of variable, contaion only one string in it.
  20. undef_prefix_match = $(if $(findstring $(1:-objs=).o,$($(1))),$(1)=)
  21. # find_only_one_obj(): if the number of string in $(1) is only one, then undefine it.
  22. # parameter $(1) is like xxx-objs, which is a name of variable.
  23. find_only_one_obj = $(if $(filter 1,$(words $($(1)))),$(call undef_prefix_match,$(1)))
  24. # check each module (xxx-objs)
  25. # note: if the line begins with a TAB character and doesn't appear
  26. # to be a legal make command (such as a variable assignment)
  27. # Error `commands commence before first target. Stop.' will happen
  28. # so do not use TAB instead of space
  29. $(foreach mod_obj,$(mods:%.o=%-objs),$(eval $(call find_only_one_obj,$(mod_obj))))
  30. endif