* [PATCH 1/3] kbuild: add -Wmissing-prototypes and -std=gnu89 to KBUILD_HOSTCFLAGS
@ 2020-06-23 3:07 Masahiro Yamada
2020-06-23 3:07 ` [PATCH 2/3] kbuild: add infrastructure to build userspace programs Masahiro Yamada
2020-06-23 3:07 ` [PATCH 3/3] scripts: use 'userprogs' to build programs for target Masahiro Yamada
0 siblings, 2 replies; 4+ messages in thread
From: Masahiro Yamada @ 2020-06-23 3:07 UTC (permalink / raw)
To: barebox; +Cc: Masahiro Yamada
Align with Linux kernel.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index da01ca5b0..a4aac3db4 100644
--- a/Makefile
+++ b/Makefile
@@ -363,8 +363,8 @@ HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
HOSTCC = gcc
HOSTCXX = g++
-KBUILD_HOSTCFLAGS := -Wall -Wstrict-prototypes -O2 \
- -fomit-frame-pointer $(HOST_LFS_CFLAGS) \
+KBUILD_HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
+ -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \
$(HOSTCFLAGS)
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
--
2.25.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] kbuild: add infrastructure to build userspace programs
2020-06-23 3:07 [PATCH 1/3] kbuild: add -Wmissing-prototypes and -std=gnu89 to KBUILD_HOSTCFLAGS Masahiro Yamada
@ 2020-06-23 3:07 ` Masahiro Yamada
2020-06-23 11:14 ` Sascha Hauer
2020-06-23 3:07 ` [PATCH 3/3] scripts: use 'userprogs' to build programs for target Masahiro Yamada
1 sibling, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2020-06-23 3:07 UTC (permalink / raw)
To: barebox; +Cc: Masahiro Yamada
Import Linux commit 7f3a59db274c3e3d884c785e363a054110f1c266
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
Makefile | 13 ++++++++---
scripts/Makefile.build | 6 +++++
scripts/Makefile.clean | 2 +-
scripts/Makefile.userprogs | 45 ++++++++++++++++++++++++++++++++++++++
4 files changed, 62 insertions(+), 4 deletions(-)
create mode 100644 scripts/Makefile.userprogs
diff --git a/Makefile b/Makefile
index a4aac3db4..0da032532 100644
--- a/Makefile
+++ b/Makefile
@@ -363,9 +363,12 @@ HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
HOSTCC = gcc
HOSTCXX = g++
-KBUILD_HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
- -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \
- $(HOSTCFLAGS)
+
+export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
+ -O2 -fomit-frame-pointer -std=gnu89
+export KBUILD_USERLDFLAGS :=
+
+KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
@@ -608,6 +611,10 @@ KBUILD_CFLAGS += $(call cc-option, -fno-delete-null-pointer-checks,)
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
+# Align the bit size of userspace programs with the kernel
+KBUILD_USERCFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS))
+KBUILD_USERLDFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS))
+
# arch Makefile may override CC so keep this after arch Makefile is included
NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
CHECKFLAGS += $(NOSTDINC_FLAGS)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 00f627791..a3dfe261a 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 6e6c9ef7c..97fd2ef48 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 000000000..fb4152973
--- /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)
--
2.25.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] scripts: use 'userprogs' to build programs for target
2020-06-23 3:07 [PATCH 1/3] kbuild: add -Wmissing-prototypes and -std=gnu89 to KBUILD_HOSTCFLAGS Masahiro Yamada
2020-06-23 3:07 ` [PATCH 2/3] kbuild: add infrastructure to build userspace programs Masahiro Yamada
@ 2020-06-23 3:07 ` Masahiro Yamada
1 sibling, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2020-06-23 3:07 UTC (permalink / raw)
To: barebox; +Cc: Masahiro Yamada
Use 'userprogs' syntax to build standalone programs for the target
architecture (i.e. the same architecture as the barebox).
This changes the compiler flags passed to the target programs.
Previously, it used $(KBUILD_CFLAGS), which contains the same compiler
flags as used for the barebox space.
Going forward, it will use $(KBUILD_USERCFLAGS), which contains smaller
set of compiler flags because there is no need to add low-level options
for userspace builds.
The shortlog will be annotated with [U].
CC [U] scripts/bareboxenv-target
CC [U] scripts/kernel-install-target
CC [U] scripts/bareboxcrc32-target
CC [U] scripts/bareboximd-target
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/Makefile | 29 ++++++++++-------------------
scripts/bareboxcrc32-target.c | 1 +
scripts/bareboxenv-target.c | 1 +
scripts/bareboximd-target.c | 1 +
scripts/kernel-install-target.c | 1 +
5 files changed, 14 insertions(+), 19 deletions(-)
create mode 100644 scripts/bareboxcrc32-target.c
create mode 100644 scripts/bareboxenv-target.c
create mode 100644 scripts/bareboximd-target.c
create mode 100644 scripts/kernel-install-target.c
diff --git a/scripts/Makefile b/scripts/Makefile
index f3b9aece9..75e68822d 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/bareboxcrc32-target.c b/scripts/bareboxcrc32-target.c
new file mode 100644
index 000000000..6c09c9f76
--- /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 000000000..caf175920
--- /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 000000000..903adee53
--- /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 000000000..845a96d29
--- /dev/null
+++ b/scripts/kernel-install-target.c
@@ -0,0 +1 @@
+#include "kernel-install.c"
--
2.25.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/3] kbuild: add infrastructure to build userspace programs
2020-06-23 3:07 ` [PATCH 2/3] kbuild: add infrastructure to build userspace programs Masahiro Yamada
@ 2020-06-23 11:14 ` Sascha Hauer
0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2020-06-23 11:14 UTC (permalink / raw)
To: Masahiro Yamada; +Cc: barebox
On Tue, Jun 23, 2020 at 12:07:01PM +0900, Masahiro Yamada wrote:
> Import Linux commit 7f3a59db274c3e3d884c785e363a054110f1c266
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
>
Very nice. Building userspace programs always was kind of a hack.
Applied, thanks
Sascha
> Makefile | 13 ++++++++---
> scripts/Makefile.build | 6 +++++
> scripts/Makefile.clean | 2 +-
> scripts/Makefile.userprogs | 45 ++++++++++++++++++++++++++++++++++++++
> 4 files changed, 62 insertions(+), 4 deletions(-)
> create mode 100644 scripts/Makefile.userprogs
>
> diff --git a/Makefile b/Makefile
> index a4aac3db4..0da032532 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -363,9 +363,12 @@ HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
>
> HOSTCC = gcc
> HOSTCXX = g++
> -KBUILD_HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
> - -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \
> - $(HOSTCFLAGS)
> +
> +export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> + -O2 -fomit-frame-pointer -std=gnu89
> +export KBUILD_USERLDFLAGS :=
> +
> +KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
> KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
> KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
> @@ -608,6 +611,10 @@ KBUILD_CFLAGS += $(call cc-option, -fno-delete-null-pointer-checks,)
>
> KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
>
> +# Align the bit size of userspace programs with the kernel
> +KBUILD_USERCFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS))
> +KBUILD_USERLDFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS))
> +
> # arch Makefile may override CC so keep this after arch Makefile is included
> NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
> CHECKFLAGS += $(NOSTDINC_FLAGS)
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 00f627791..a3dfe261a 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 6e6c9ef7c..97fd2ef48 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 000000000..fb4152973
> --- /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)
> --
> 2.25.1
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-23 11:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 3:07 [PATCH 1/3] kbuild: add -Wmissing-prototypes and -std=gnu89 to KBUILD_HOSTCFLAGS Masahiro Yamada
2020-06-23 3:07 ` [PATCH 2/3] kbuild: add infrastructure to build userspace programs Masahiro Yamada
2020-06-23 11:14 ` Sascha Hauer
2020-06-23 3:07 ` [PATCH 3/3] scripts: use 'userprogs' to build programs for target Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox