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