aboutsummaryrefslogtreecommitdiff
path: root/scripts/Makefile.userprogs
blob: f3a7e1ef3753b54303718fae97f4b3c9d4eac07c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# SPDX-License-Identifier: GPL-2.0-only
#
# Build userspace programs for the target system
#

# Executables compiled from a single .c file
user-csingle	:= $(foreach m, $(userprogs), $(if $($(m)-objs),,$(m)))

# Executables linked based on several .o files
user-cmulti	:= $(foreach m, $(userprogs), $(if $($(m)-objs),$(m)))

# Objects compiled from .c files
user-cobjs	:= $(sort $(foreach m, $(userprogs), $($(m)-objs)))

user-csingle	:= $(addprefix $(obj)/, $(user-csingle))
user-cmulti	:= $(addprefix $(obj)/, $(user-cmulti))
user-cobjs	:= $(addprefix $(obj)/, $(user-cobjs))

user_ccflags	= -Wp,-MMD,$(depfile) $(KBUILD_USERCFLAGS) $(userccflags) \
			$($(target-stem)-userccflags)
user_ldflags	= $(KBUILD_USERLDFLAGS) $(userldflags) $($(target-stem)-userldflags)
user_ldlibs	= $(userldlibs) $($(target-stem)-userldlibs)

# Create an executable from a single .c file
quiet_cmd_user_cc_c = CC [U]  $@
      cmd_user_cc_c = $(CC) $(user_ccflags) $(user_ldflags) -o $@ $< \
		      $(user_ldlibs)
$(user-csingle): $(obj)/%: $(src)/%.c FORCE
	$(call if_changed_dep,user_cc_c)

# Link an executable based on list of .o files
quiet_cmd_user_ld = LD [U]  $@
      cmd_user_ld = $(CC) $(user_ldflags) -o $@ \
		    $(addprefix $(obj)/, $($(target-stem)-objs)) $(user_ldlibs)
$(user-cmulti): FORCE
	$(call if_changed,user_ld)
$(call multi_depend, $(user-cmulti), , -objs)

# Create .o file from a .c file
quiet_cmd_user_cc_o_c = CC [U]  $@
      cmd_user_cc_o_c = $(CC) $(user_ccflags) -c -o $@ $<
$(user-cobjs): $(obj)/%.o: $(src)/%.c FORCE
	$(call if_changed_dep,user_cc_o_c)

targets += $(user-csingle) $(user-cmulti) $(user-cobjs)