summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMasahiro Yamada <masahiroy@kernel.org>2020-06-23 12:07:01 +0900
committerSascha Hauer <s.hauer@pengutronix.de>2020-06-23 12:18:04 +0200
commitcca129e716fef156831ee26a624d2d0a0550ba8c (patch)
treef305ae175806abd30065b1f7284ec9614169db9f /scripts
parentbc4840e98b94e4e78f76b761293d965edcfb094d (diff)
downloadbarebox-cca129e716fef156831ee26a624d2d0a0550ba8c.tar.gz
barebox-cca129e716fef156831ee26a624d2d0a0550ba8c.tar.xz
kbuild: add infrastructure to build userspace programs
Import Linux commit 7f3a59db274c3e3d884c785e363a054110f1c266 Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.build6
-rw-r--r--scripts/Makefile.clean2
-rw-r--r--scripts/Makefile.userprogs45
3 files changed, 52 insertions, 1 deletions
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 00f627791a..a3dfe261af 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -49,6 +49,12 @@ ifneq ($(hostprogs)$(hostprogs-y)$(hostprogs-m),)
include scripts/Makefile.host
endif
+# Do not include userprogs rules unless needed.
+userprogs := $(sort $(userprogs))
+ifneq ($(userprogs),)
+include scripts/Makefile.userprogs
+endif
+
ifndef obj
$(warning kbuild: Makefile.build is included improperly)
endif
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 6e6c9ef7c6..97fd2ef48c 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -37,7 +37,7 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
__clean-files := $(extra-y) $(extra-m) $(extra-) \
$(always) $(always-y) $(always-m) $(always-) $(targets) $(clean-files) \
- $(hostprogs) $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
+ $(hostprogs) $(hostprogs-y) $(hostprogs-m) $(hostprogs-) $(userprogs)
# as clean-files is given relative to the current directory, this adds
# a $(obj) prefix, except for absolute paths
diff --git a/scripts/Makefile.userprogs b/scripts/Makefile.userprogs
new file mode 100644
index 0000000000..fb41529733
--- /dev/null
+++ b/scripts/Makefile.userprogs
@@ -0,0 +1,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)
+
+# 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 $@ $< \
+ $($(target-stem)-userldlibs)
+$(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)) \
+ $($(target-stem)-userldlibs)
+$(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)