Makefile.userprogs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Build userspace programs for the target system
  4. #
  5. # Executables compiled from a single .c file
  6. user-csingle := $(foreach m, $(userprogs), $(if $($(m)-objs),,$(m)))
  7. # Executables linked based on several .o files
  8. user-cmulti := $(foreach m, $(userprogs), $(if $($(m)-objs),$(m)))
  9. # Objects compiled from .c files
  10. user-cobjs := $(sort $(foreach m, $(userprogs), $($(m)-objs)))
  11. user-csingle := $(addprefix $(obj)/, $(user-csingle))
  12. user-cmulti := $(addprefix $(obj)/, $(user-cmulti))
  13. user-cobjs := $(addprefix $(obj)/, $(user-cobjs))
  14. user_ccflags = -Wp,-MMD,$(depfile) $(KBUILD_USERCFLAGS) $(userccflags) \
  15. $($(target-stem)-userccflags)
  16. user_ldflags = $(KBUILD_USERLDFLAGS) $(userldflags) $($(target-stem)-userldflags)
  17. # Create an executable from a single .c file
  18. quiet_cmd_user_cc_c = CC [U] $@
  19. cmd_user_cc_c = $(CC) $(user_ccflags) $(user_ldflags) -o $@ $< \
  20. $($(target-stem)-userldlibs)
  21. $(user-csingle): $(obj)/%: $(src)/%.c FORCE
  22. $(call if_changed_dep,user_cc_c)
  23. # Link an executable based on list of .o files
  24. quiet_cmd_user_ld = LD [U] $@
  25. cmd_user_ld = $(CC) $(user_ldflags) -o $@ \
  26. $(addprefix $(obj)/, $($(target-stem)-objs)) \
  27. $($(target-stem)-userldlibs)
  28. $(user-cmulti): FORCE
  29. $(call if_changed,user_ld)
  30. $(call multi_depend, $(user-cmulti), , -objs)
  31. # Create .o file from a .c file
  32. quiet_cmd_user_cc_o_c = CC [U] $@
  33. cmd_user_cc_o_c = $(CC) $(user_ccflags) -c -o $@ $<
  34. $(user-cobjs): $(obj)/%.o: $(src)/%.c FORCE
  35. $(call if_changed_dep,user_cc_o_c)
  36. targets += $(user-csingle) $(user-cmulti) $(user-cobjs)