162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci#
362306a36Sopenharmony_ci# Build userspace programs for the target system
462306a36Sopenharmony_ci#
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci# Executables compiled from a single .c file
762306a36Sopenharmony_ciuser-csingle	:= $(foreach m, $(userprogs), $(if $($(m)-objs),,$(m)))
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci# Executables linked based on several .o files
1062306a36Sopenharmony_ciuser-cmulti	:= $(foreach m, $(userprogs), $(if $($(m)-objs),$(m)))
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci# Objects compiled from .c files
1362306a36Sopenharmony_ciuser-cobjs	:= $(sort $(foreach m, $(userprogs), $($(m)-objs)))
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciuser-csingle	:= $(addprefix $(obj)/, $(user-csingle))
1662306a36Sopenharmony_ciuser-cmulti	:= $(addprefix $(obj)/, $(user-cmulti))
1762306a36Sopenharmony_ciuser-cobjs	:= $(addprefix $(obj)/, $(user-cobjs))
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ciuser_ccflags	= -Wp,-MMD,$(depfile) $(KBUILD_USERCFLAGS) $(userccflags) \
2062306a36Sopenharmony_ci			$($(target-stem)-userccflags)
2162306a36Sopenharmony_ciuser_ldflags	= $(KBUILD_USERLDFLAGS) $(userldflags) $($(target-stem)-userldflags)
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci# Create an executable from a single .c file
2462306a36Sopenharmony_ciquiet_cmd_user_cc_c = CC [U]  $@
2562306a36Sopenharmony_ci      cmd_user_cc_c = $(CC) $(user_ccflags) $(user_ldflags) -o $@ $< \
2662306a36Sopenharmony_ci		      $($(target-stem)-userldlibs)
2762306a36Sopenharmony_ci$(user-csingle): $(obj)/%: $(src)/%.c FORCE
2862306a36Sopenharmony_ci	$(call if_changed_dep,user_cc_c)
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci# Link an executable based on list of .o files
3162306a36Sopenharmony_ciquiet_cmd_user_ld = LD [U]  $@
3262306a36Sopenharmony_ci      cmd_user_ld = $(CC) $(user_ldflags) -o $@ \
3362306a36Sopenharmony_ci		    $(addprefix $(obj)/, $($(target-stem)-objs)) \
3462306a36Sopenharmony_ci		    $($(target-stem)-userldlibs)
3562306a36Sopenharmony_ci$(user-cmulti): FORCE
3662306a36Sopenharmony_ci	$(call if_changed,user_ld)
3762306a36Sopenharmony_ci$(call multi_depend, $(user-cmulti), , -objs)
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci# Create .o file from a .c file
4062306a36Sopenharmony_ciquiet_cmd_user_cc_o_c = CC [U]  $@
4162306a36Sopenharmony_ci      cmd_user_cc_o_c = $(CC) $(user_ccflags) -c -o $@ $<
4262306a36Sopenharmony_ci$(user-cobjs): $(obj)/%.o: $(src)/%.c FORCE
4362306a36Sopenharmony_ci	$(call if_changed_dep,user_cc_o_c)
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_citargets += $(user-csingle) $(user-cmulti) $(user-cobjs)
46