summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-07-27 21:58:32 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-07-27 21:58:32 +0200
commit9d6769235a7827ff3208c8c5245e18fc06d5d008 (patch)
tree2da0ed956b0a282b52bce5b5becde266203f6ad1 /scripts
parentd0dee07167826c6b6b1e85d8ef861e386bd0b300 (diff)
parentc008d836d8f47a75c9394137f44298771fce5001 (diff)
downloadbarebox-9d6769235a7827ff3208c8c5245e18fc06d5d008.tar.gz
barebox-9d6769235a7827ff3208c8c5245e18fc06d5d008.tar.xz
Merge branch 'for-next/kbuild'
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile29
-rw-r--r--scripts/Makefile.build6
-rw-r--r--scripts/Makefile.clean2
-rw-r--r--scripts/Makefile.userprogs45
-rw-r--r--scripts/bareboxcrc32-target.c1
-rw-r--r--scripts/bareboxenv-target.c1
-rw-r--r--scripts/bareboximd-target.c1
-rw-r--r--scripts/kernel-install-target.c1
8 files changed, 66 insertions, 20 deletions
diff --git a/scripts/Makefile b/scripts/Makefile
index f3b9aece9e..75e68822d1 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -35,30 +35,21 @@ HOSTCFLAGS_omap4_usbboot.o = `pkg-config --cflags libusb-1.0`
HOSTLDLIBS_omap4_usbboot = -lpthread `pkg-config --libs libusb-1.0`
hostprogs-$(CONFIG_OMAP4_HOSTTOOL_USBBOOT) += omap4_usbboot
+userprogs-$(CONFIG_BAREBOXENV_TARGET) += bareboxenv-target
+userprogs-$(CONFIG_KERNEL_INSTALL_TARGET) += kernel-install-target
+userprogs-$(CONFIG_BAREBOXCRC32_TARGET) += bareboxcrc32-target
+userprogs-$(CONFIG_IMD_TARGET) += bareboximd-target
+
+userccflags += -I $(srctree)/$(src)/include
+
+userprogs := $(userprogs-y)
+always-y := $(hostprogs-y) $(hostprogs-m) $(userprogs-y)
+
subdir-y += mod
subdir-y += imx
subdir-$(CONFIG_X86) += setupmbr
subdir-$(CONFIG_DTC) += dtc
subdir-$(CONFIG_ARCH_TEGRA) += tegra
-targetprogs-$(CONFIG_BAREBOXENV_TARGET) += bareboxenv-target
-targetprogs-$(CONFIG_KERNEL_INSTALL_TARGET) += kernel-install-target
-targetprogs-$(CONFIG_BAREBOXCRC32_TARGET) += bareboxcrc32-target
-targetprogs-$(CONFIG_IMD_TARGET) += bareboximd-target
-
# Let clean descend into subdirs
subdir- += basic kconfig setupmbr
-
-quiet_cmd_csingle = CC $@
- cmd_csingle = $(CC) -Wp,-MD,$(depfile) $(TARGETCFLAGS) $(KBUILD_CFLAGS) -o $@ $<
-
-__targetprogs := $(sort $(targetprogs-y) $(targetprogs-m))
-target-csingle := $(foreach m,$(__targetprogs),$(if $($(m)-objs),,$(m)))
-__targetprogs := $(addprefix $(obj)/,$(__targetprogs))
-target-csingle := $(addprefix $(obj)/,$(target-csingle))
-TARGETCFLAGS += -I$(srctree)/scripts/include/
-
-always := $(hostprogs-y) $(hostprogs-m) $(targetprogs-y)
-
-$(target-csingle): %-target: %.c FORCE
- $(call if_changed_dep,csingle)
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)
diff --git a/scripts/bareboxcrc32-target.c b/scripts/bareboxcrc32-target.c
new file mode 100644
index 0000000000..6c09c9f763
--- /dev/null
+++ b/scripts/bareboxcrc32-target.c
@@ -0,0 +1 @@
+#include "bareboxcrc32.c"
diff --git a/scripts/bareboxenv-target.c b/scripts/bareboxenv-target.c
new file mode 100644
index 0000000000..caf1759205
--- /dev/null
+++ b/scripts/bareboxenv-target.c
@@ -0,0 +1 @@
+#include "bareboxenv.c"
diff --git a/scripts/bareboximd-target.c b/scripts/bareboximd-target.c
new file mode 100644
index 0000000000..903adee53d
--- /dev/null
+++ b/scripts/bareboximd-target.c
@@ -0,0 +1 @@
+#include "bareboximd.c"
diff --git a/scripts/kernel-install-target.c b/scripts/kernel-install-target.c
new file mode 100644
index 0000000000..845a96d29b
--- /dev/null
+++ b/scripts/kernel-install-target.c
@@ -0,0 +1 @@
+#include "kernel-install.c"