Makefile.target 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # SPDX-License-Identifier: GPL-2.0
  2. # ==========================================================================
  3. # Building binaries on the host system
  4. # Binaries are not used during the compilation of the kernel, and intended
  5. # to be build for target board, target board can be host of course. Added to
  6. # build binaries to run not on host system.
  7. #
  8. # Sample syntax
  9. # tprogs-y := xsk_example
  10. # Will compile xsk_example.c and create an executable named xsk_example
  11. #
  12. # tprogs-y := xdpsock
  13. # xdpsock-objs := xdpsock_1.o xdpsock_2.o
  14. # Will compile xdpsock_1.c and xdpsock_2.c, and then link the executable
  15. # xdpsock, based on xdpsock_1.o and xdpsock_2.o
  16. #
  17. # Derived from scripts/Makefile.host
  18. #
  19. __tprogs := $(sort $(tprogs-y))
  20. # C code
  21. # Executables compiled from a single .c file
  22. tprog-csingle := $(foreach m,$(__tprogs), \
  23. $(if $($(m)-objs),,$(m)))
  24. # C executables linked based on several .o files
  25. tprog-cmulti := $(foreach m,$(__tprogs),\
  26. $(if $($(m)-objs),$(m)))
  27. # Object (.o) files compiled from .c files
  28. tprog-cobjs := $(sort $(foreach m,$(__tprogs),$($(m)-objs)))
  29. tprog-csingle := $(addprefix $(obj)/,$(tprog-csingle))
  30. tprog-cmulti := $(addprefix $(obj)/,$(tprog-cmulti))
  31. tprog-cobjs := $(addprefix $(obj)/,$(tprog-cobjs))
  32. #####
  33. # Handle options to gcc. Support building with separate output directory
  34. _tprogc_flags = $(TPROGS_CFLAGS) \
  35. $(TPROGCFLAGS_$(basetarget).o)
  36. # $(objtree)/$(obj) for including generated headers from checkin source files
  37. ifeq ($(KBUILD_EXTMOD),)
  38. ifdef building_out_of_srctree
  39. _tprogc_flags += -I $(objtree)/$(obj)
  40. endif
  41. endif
  42. tprogc_flags = -Wp,-MD,$(depfile) $(_tprogc_flags)
  43. # Create executable from a single .c file
  44. # tprog-csingle -> Executable
  45. quiet_cmd_tprog-csingle = CC $@
  46. cmd_tprog-csingle = $(CC) $(tprogc_flags) $(TPROGS_LDFLAGS) -o $@ $< \
  47. $(TPROGS_LDLIBS) $(TPROGLDLIBS_$(@F))
  48. $(tprog-csingle): $(obj)/%: $(src)/%.c FORCE
  49. $(call if_changed_dep,tprog-csingle)
  50. # Link an executable based on list of .o files, all plain c
  51. # tprog-cmulti -> executable
  52. quiet_cmd_tprog-cmulti = LD $@
  53. cmd_tprog-cmulti = $(CC) $(tprogc_flags) $(TPROGS_LDFLAGS) -o $@ \
  54. $(addprefix $(obj)/,$($(@F)-objs)) \
  55. $(TPROGS_LDLIBS) $(TPROGLDLIBS_$(@F))
  56. $(tprog-cmulti): $(tprog-cobjs) FORCE
  57. $(call if_changed,tprog-cmulti)
  58. $(call multi_depend, $(tprog-cmulti), , -objs)
  59. # Create .o file from a single .c file
  60. # tprog-cobjs -> .o
  61. quiet_cmd_tprog-cobjs = CC $@
  62. cmd_tprog-cobjs = $(CC) $(tprogc_flags) -c -o $@ $<
  63. $(tprog-cobjs): $(obj)/%.o: $(src)/%.c FORCE
  64. $(call if_changed_dep,tprog-cobjs)