License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2019-07-20 16:27:40 +00:00
|
|
|
|
|
|
|
# LEX
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
quiet_cmd_flex = LEX $@
|
|
|
|
cmd_flex = $(LEX) -o$@ -L $<
|
|
|
|
|
|
|
|
$(obj)/%.lex.c: $(src)/%.l FORCE
|
|
|
|
$(call if_changed,flex)
|
|
|
|
|
|
|
|
# YACC
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
quiet_cmd_bison = YACC $(basename $@).[ch]
|
|
|
|
cmd_bison = $(YACC) -o $(basename $@).c --defines=$(basename $@).h -t -l $<
|
|
|
|
|
|
|
|
$(obj)/%.tab.c $(obj)/%.tab.h: $(src)/%.y FORCE
|
|
|
|
$(call if_changed,bison)
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
# ==========================================================================
|
|
|
|
# Building binaries on the host system
|
|
|
|
# Binaries are used during the compilation of the kernel, for example
|
|
|
|
# to preprocess a data file.
|
|
|
|
#
|
2008-02-18 09:48:20 +00:00
|
|
|
# Both C and C++ are supported, but preferred language is C for such utilities.
|
2021-07-03 14:42:57 +00:00
|
|
|
# Rust is also supported, but it may only be used in scenarios where a Rust
|
|
|
|
# toolchain is required to be available (e.g. when `CONFIG_RUST` is enabled).
|
2005-04-16 22:20:36 +00:00
|
|
|
#
|
2019-06-12 17:52:48 +00:00
|
|
|
# Sample syntax (see Documentation/kbuild/makefiles.rst for reference)
|
2020-02-01 16:49:24 +00:00
|
|
|
# hostprogs := bin2hex
|
2005-04-16 22:20:36 +00:00
|
|
|
# Will compile bin2hex.c and create an executable named bin2hex
|
|
|
|
#
|
2020-02-01 16:49:24 +00:00
|
|
|
# hostprogs := lxdialog
|
2005-04-16 22:20:36 +00:00
|
|
|
# lxdialog-objs := checklist.o lxdialog.o
|
|
|
|
# Will compile lxdialog.c and checklist.c, and then link the executable
|
|
|
|
# lxdialog, based on checklist.o and lxdialog.o
|
|
|
|
#
|
2020-02-01 16:49:24 +00:00
|
|
|
# hostprogs := qconf
|
2005-04-16 22:20:36 +00:00
|
|
|
# qconf-cxxobjs := qconf.o
|
|
|
|
# qconf-objs := menu.o
|
|
|
|
# Will compile qconf as a C++ program, and menu as a C program.
|
|
|
|
# They are linked as C++ code to the executable qconf
|
2021-07-03 14:42:57 +00:00
|
|
|
#
|
|
|
|
# hostprogs := target
|
|
|
|
# target-rust := y
|
|
|
|
# Will compile `target` as a Rust program, using `target.rs` as the crate root.
|
|
|
|
# The crate may consist of several source files.
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
# C code
|
|
|
|
# Executables compiled from a single .c file
|
2020-07-29 03:15:37 +00:00
|
|
|
host-csingle := $(foreach m,$(hostprogs), \
|
2021-07-03 14:42:57 +00:00
|
|
|
$(if $($(m)-objs)$($(m)-cxxobjs)$($(m)-rust),,$(m)))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
# C executables linked based on several .o files
|
2020-07-29 03:15:37 +00:00
|
|
|
host-cmulti := $(foreach m,$(hostprogs),\
|
2021-07-03 14:42:57 +00:00
|
|
|
$(if $($(m)-cxxobjs)$($(m)-rust),,$(if $($(m)-objs),$(m))))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
# Object (.o) files compiled from .c files
|
2020-07-29 03:15:37 +00:00
|
|
|
host-cobjs := $(sort $(foreach m,$(hostprogs),$($(m)-objs)))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
# C++ code
|
2014-07-16 07:12:19 +00:00
|
|
|
# C++ executables compiled from at least one .cc file
|
2005-04-16 22:20:36 +00:00
|
|
|
# and zero or more .c files
|
2020-07-29 03:15:37 +00:00
|
|
|
host-cxxmulti := $(foreach m,$(hostprogs),$(if $($(m)-cxxobjs),$(m)))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
# C++ Object (.o) files compiled from .cc files
|
|
|
|
host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
|
|
|
|
|
2021-07-03 14:42:57 +00:00
|
|
|
# Rust code
|
|
|
|
# Executables compiled from a single Rust crate (which may consist of
|
|
|
|
# one or more .rs files)
|
|
|
|
host-rust := $(foreach m,$(hostprogs),$(if $($(m)-rust),$(m)))
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
host-csingle := $(addprefix $(obj)/,$(host-csingle))
|
|
|
|
host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
|
|
|
|
host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
|
|
|
|
host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
|
|
|
|
host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
|
2021-07-03 14:42:57 +00:00
|
|
|
host-rust := $(addprefix $(obj)/,$(host-rust))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#####
|
|
|
|
# Handle options to gcc. Support building with separate output directory
|
|
|
|
|
2023-01-07 09:18:14 +00:00
|
|
|
hostc_flags = -Wp,-MMD,$(depfile) \
|
|
|
|
$(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
|
kbuild: change *FLAGS_<basetarget>.o to take the path relative to $(obj)
Kbuild provides per-file compiler flag addition/removal:
CFLAGS_<basetarget>.o
CFLAGS_REMOVE_<basetarget>.o
AFLAGS_<basetarget>.o
AFLAGS_REMOVE_<basetarget>.o
CPPFLAGS_<basetarget>.lds
HOSTCFLAGS_<basetarget>.o
HOSTCXXFLAGS_<basetarget>.o
The <basetarget> is the filename of the target with its directory and
suffix stripped.
This syntax comes into a trouble when two files with the same basename
appear in one Makefile, for example:
obj-y += foo.o
obj-y += dir/foo.o
CFLAGS_foo.o := <some-flags>
Here, the <some-flags> applies to both foo.o and dir/foo.o
The real world problem is:
scripts/kconfig/util.c
scripts/kconfig/lxdialog/util.c
Both files are compiled into scripts/kconfig/mconf, but only the
latter should be given with the ncurses flags.
It is more sensible to use the relative path to the Makefile, like this:
obj-y += foo.o
CFLAGS_foo.o := <some-flags>
obj-y += dir/foo.o
CFLAGS_dir/foo.o := <other-flags>
At first, I attempted to replace $(basetarget) with $*. The $* variable
is replaced with the stem ('%') part in a pattern rule. This works with
most of cases, but does not for explicit rules.
For example, arch/ia64/lib/Makefile reuses rule_as_o_S in its own
explicit rules, so $* will be empty, resulting in ignoring the per-file
AFLAGS.
I introduced a new variable, target-stem, which can be used also from
explicit rules.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Marc Zyngier <maz@kernel.org>
2019-08-30 04:34:01 +00:00
|
|
|
$(HOSTCFLAGS_$(target-stem).o)
|
2023-01-07 09:18:14 +00:00
|
|
|
hostcxx_flags = -Wp,-MMD,$(depfile) \
|
|
|
|
$(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
|
kbuild: change *FLAGS_<basetarget>.o to take the path relative to $(obj)
Kbuild provides per-file compiler flag addition/removal:
CFLAGS_<basetarget>.o
CFLAGS_REMOVE_<basetarget>.o
AFLAGS_<basetarget>.o
AFLAGS_REMOVE_<basetarget>.o
CPPFLAGS_<basetarget>.lds
HOSTCFLAGS_<basetarget>.o
HOSTCXXFLAGS_<basetarget>.o
The <basetarget> is the filename of the target with its directory and
suffix stripped.
This syntax comes into a trouble when two files with the same basename
appear in one Makefile, for example:
obj-y += foo.o
obj-y += dir/foo.o
CFLAGS_foo.o := <some-flags>
Here, the <some-flags> applies to both foo.o and dir/foo.o
The real world problem is:
scripts/kconfig/util.c
scripts/kconfig/lxdialog/util.c
Both files are compiled into scripts/kconfig/mconf, but only the
latter should be given with the ncurses flags.
It is more sensible to use the relative path to the Makefile, like this:
obj-y += foo.o
CFLAGS_foo.o := <some-flags>
obj-y += dir/foo.o
CFLAGS_dir/foo.o := <other-flags>
At first, I attempted to replace $(basetarget) with $*. The $* variable
is replaced with the stem ('%') part in a pattern rule. This works with
most of cases, but does not for explicit rules.
For example, arch/ia64/lib/Makefile reuses rule_as_o_S in its own
explicit rules, so $* will be empty, resulting in ignoring the per-file
AFLAGS.
I introduced a new variable, target-stem, which can be used also from
explicit rules.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Marc Zyngier <maz@kernel.org>
2019-08-30 04:34:01 +00:00
|
|
|
$(HOSTCXXFLAGS_$(target-stem).o)
|
2023-07-23 14:21:28 +00:00
|
|
|
|
|
|
|
# `--out-dir` is required to avoid temporaries being created by `rustc` in the
|
|
|
|
# current working directory, which may be not accessible in the out-of-tree
|
|
|
|
# modules case.
|
|
|
|
hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \
|
2023-10-05 21:39:58 +00:00
|
|
|
-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
|
|
|
|
-Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
|
kbuild: specify output names separately for each emission type from rustc
In Kbuild, two different rules must not write to the same file, but
it happens when compiling rust source files.
For example, set CONFIG_SAMPLE_RUST_MINIMAL=m and run the following:
$ make -j$(nproc) samples/rust/rust_minimal.o samples/rust/rust_minimal.rsi \
samples/rust/rust_minimal.s samples/rust/rust_minimal.ll
[snip]
RUSTC [M] samples/rust/rust_minimal.o
RUSTC [M] samples/rust/rust_minimal.rsi
RUSTC [M] samples/rust/rust_minimal.s
RUSTC [M] samples/rust/rust_minimal.ll
mv: cannot stat 'samples/rust/rust_minimal.d': No such file or directory
make[3]: *** [scripts/Makefile.build:334: samples/rust/rust_minimal.ll] Error 1
make[3]: *** Waiting for unfinished jobs....
mv: cannot stat 'samples/rust/rust_minimal.d': No such file or directory
make[3]: *** [scripts/Makefile.build:309: samples/rust/rust_minimal.o] Error 1
mv: cannot stat 'samples/rust/rust_minimal.d': No such file or directory
make[3]: *** [scripts/Makefile.build:326: samples/rust/rust_minimal.s] Error 1
make[2]: *** [scripts/Makefile.build:504: samples/rust] Error 2
make[1]: *** [scripts/Makefile.build:504: samples] Error 2
make: *** [Makefile:2008: .] Error 2
The reason for the error is that 4 threads running in parallel renames
the same file, samples/rust/rust_minimal.d.
This does not happen when compiling C or assembly files because
-Wp,-MMD,$(depfile) explicitly specifies the dependency filepath.
$(depfile) is a unique path for each target.
Currently, rustc is only given --out-dir and --emit=<list-of-types>
So, all the rust build rules output the dep-info into the default
<CRATE_NAME>.d, which causes the path conflict.
Fortunately, the --emit option is able to specify the output path
individually, with the form --emit=<type>=<path>.
Add --emit=dep-info=$(depfile) to the common part. Also, remove the
redundant --out-dir because the output path is specified for each type.
The code gets much cleaner because we do not need to rename *.d files.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-01-07 09:18:15 +00:00
|
|
|
$(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
|
2023-01-07 09:18:14 +00:00
|
|
|
$(HOSTRUSTFLAGS_$(target-stem))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2019-05-13 06:22:17 +00:00
|
|
|
# $(objtree)/$(obj) for including generated headers from checkin source files
|
2019-01-16 02:56:40 +00:00
|
|
|
ifeq ($(KBUILD_EXTMOD),)
|
2019-07-06 03:07:12 +00:00
|
|
|
ifdef building_out_of_srctree
|
2023-01-07 09:18:14 +00:00
|
|
|
hostc_flags += -I $(objtree)/$(obj)
|
|
|
|
hostcxx_flags += -I $(objtree)/$(obj)
|
2005-04-16 22:20:36 +00:00
|
|
|
endif
|
2019-01-16 02:56:40 +00:00
|
|
|
endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#####
|
|
|
|
# Compile programs on the host
|
|
|
|
|
|
|
|
# Create executable from a single .c file
|
|
|
|
# host-csingle -> Executable
|
|
|
|
quiet_cmd_host-csingle = HOSTCC $@
|
2018-07-10 00:46:00 +00:00
|
|
|
cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
|
kbuild: change *FLAGS_<basetarget>.o to take the path relative to $(obj)
Kbuild provides per-file compiler flag addition/removal:
CFLAGS_<basetarget>.o
CFLAGS_REMOVE_<basetarget>.o
AFLAGS_<basetarget>.o
AFLAGS_REMOVE_<basetarget>.o
CPPFLAGS_<basetarget>.lds
HOSTCFLAGS_<basetarget>.o
HOSTCXXFLAGS_<basetarget>.o
The <basetarget> is the filename of the target with its directory and
suffix stripped.
This syntax comes into a trouble when two files with the same basename
appear in one Makefile, for example:
obj-y += foo.o
obj-y += dir/foo.o
CFLAGS_foo.o := <some-flags>
Here, the <some-flags> applies to both foo.o and dir/foo.o
The real world problem is:
scripts/kconfig/util.c
scripts/kconfig/lxdialog/util.c
Both files are compiled into scripts/kconfig/mconf, but only the
latter should be given with the ncurses flags.
It is more sensible to use the relative path to the Makefile, like this:
obj-y += foo.o
CFLAGS_foo.o := <some-flags>
obj-y += dir/foo.o
CFLAGS_dir/foo.o := <other-flags>
At first, I attempted to replace $(basetarget) with $*. The $* variable
is replaced with the stem ('%') part in a pattern rule. This works with
most of cases, but does not for explicit rules.
For example, arch/ia64/lib/Makefile reuses rule_as_o_S in its own
explicit rules, so $* will be empty, resulting in ignoring the per-file
AFLAGS.
I introduced a new variable, target-stem, which can be used also from
explicit rules.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Marc Zyngier <maz@kernel.org>
2019-08-30 04:34:01 +00:00
|
|
|
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
|
kbuild: use $(obj)/ instead of $(src)/ for common pattern rules
Kbuild conventionally uses $(obj)/ for generated files, and $(src)/ for
checked-in source files. It is merely a convention without any functional
difference. In fact, $(obj) and $(src) are exactly the same, as defined
in scripts/Makefile.build:
src := $(obj)
Before changing the semantics of $(src) in the next commit, this commit
replaces $(obj)/ with $(src)/ in pattern rules where the prerequisite
might be a generated file.
C, assembly, Rust, and DTS files are sometimes generated by tools, so
they could be either generated files or real sources. The $(obj)/ prefix
works for both cases with the help of VPATH.
As mentioned above, $(obj) and $(src) are the same at this point, hence
this commit has no functional change.
I did not modify scripts/Makefile.userprogs because there is no use
case where userspace C files are generated.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
2024-04-27 14:55:01 +00:00
|
|
|
$(host-csingle): $(obj)/%: $(obj)/%.c FORCE
|
2005-04-16 22:20:36 +00:00
|
|
|
$(call if_changed_dep,host-csingle)
|
|
|
|
|
|
|
|
# Link an executable based on list of .o files, all plain c
|
|
|
|
# host-cmulti -> executable
|
|
|
|
quiet_cmd_host-cmulti = HOSTLD $@
|
2018-07-10 00:46:00 +00:00
|
|
|
cmd_host-cmulti = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \
|
kbuild: change *FLAGS_<basetarget>.o to take the path relative to $(obj)
Kbuild provides per-file compiler flag addition/removal:
CFLAGS_<basetarget>.o
CFLAGS_REMOVE_<basetarget>.o
AFLAGS_<basetarget>.o
AFLAGS_REMOVE_<basetarget>.o
CPPFLAGS_<basetarget>.lds
HOSTCFLAGS_<basetarget>.o
HOSTCXXFLAGS_<basetarget>.o
The <basetarget> is the filename of the target with its directory and
suffix stripped.
This syntax comes into a trouble when two files with the same basename
appear in one Makefile, for example:
obj-y += foo.o
obj-y += dir/foo.o
CFLAGS_foo.o := <some-flags>
Here, the <some-flags> applies to both foo.o and dir/foo.o
The real world problem is:
scripts/kconfig/util.c
scripts/kconfig/lxdialog/util.c
Both files are compiled into scripts/kconfig/mconf, but only the
latter should be given with the ncurses flags.
It is more sensible to use the relative path to the Makefile, like this:
obj-y += foo.o
CFLAGS_foo.o := <some-flags>
obj-y += dir/foo.o
CFLAGS_dir/foo.o := <other-flags>
At first, I attempted to replace $(basetarget) with $*. The $* variable
is replaced with the stem ('%') part in a pattern rule. This works with
most of cases, but does not for explicit rules.
For example, arch/ia64/lib/Makefile reuses rule_as_o_S in its own
explicit rules, so $* will be empty, resulting in ignoring the per-file
AFLAGS.
I introduced a new variable, target-stem, which can be used also from
explicit rules.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Marc Zyngier <maz@kernel.org>
2019-08-30 04:34:01 +00:00
|
|
|
$(addprefix $(obj)/, $($(target-stem)-objs)) \
|
|
|
|
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
|
2014-08-19 07:34:21 +00:00
|
|
|
$(host-cmulti): FORCE
|
2005-04-16 22:20:36 +00:00
|
|
|
$(call if_changed,host-cmulti)
|
2014-08-19 07:34:21 +00:00
|
|
|
$(call multi_depend, $(host-cmulti), , -objs)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
# Create .o file from a single .c file
|
|
|
|
# host-cobjs -> .o
|
|
|
|
quiet_cmd_host-cobjs = HOSTCC $@
|
|
|
|
cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $<
|
kbuild: use $(obj)/ instead of $(src)/ for common pattern rules
Kbuild conventionally uses $(obj)/ for generated files, and $(src)/ for
checked-in source files. It is merely a convention without any functional
difference. In fact, $(obj) and $(src) are exactly the same, as defined
in scripts/Makefile.build:
src := $(obj)
Before changing the semantics of $(src) in the next commit, this commit
replaces $(obj)/ with $(src)/ in pattern rules where the prerequisite
might be a generated file.
C, assembly, Rust, and DTS files are sometimes generated by tools, so
they could be either generated files or real sources. The $(obj)/ prefix
works for both cases with the help of VPATH.
As mentioned above, $(obj) and $(src) are the same at this point, hence
this commit has no functional change.
I did not modify scripts/Makefile.userprogs because there is no use
case where userspace C files are generated.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
2024-04-27 14:55:01 +00:00
|
|
|
$(host-cobjs): $(obj)/%.o: $(obj)/%.c FORCE
|
2005-04-16 22:20:36 +00:00
|
|
|
$(call if_changed_dep,host-cobjs)
|
|
|
|
|
|
|
|
# Link an executable based on list of .o files, a mixture of .c and .cc
|
|
|
|
# host-cxxmulti -> executable
|
|
|
|
quiet_cmd_host-cxxmulti = HOSTLD $@
|
2018-07-10 00:46:00 +00:00
|
|
|
cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \
|
2005-04-16 22:20:36 +00:00
|
|
|
$(foreach o,objs cxxobjs,\
|
kbuild: change *FLAGS_<basetarget>.o to take the path relative to $(obj)
Kbuild provides per-file compiler flag addition/removal:
CFLAGS_<basetarget>.o
CFLAGS_REMOVE_<basetarget>.o
AFLAGS_<basetarget>.o
AFLAGS_REMOVE_<basetarget>.o
CPPFLAGS_<basetarget>.lds
HOSTCFLAGS_<basetarget>.o
HOSTCXXFLAGS_<basetarget>.o
The <basetarget> is the filename of the target with its directory and
suffix stripped.
This syntax comes into a trouble when two files with the same basename
appear in one Makefile, for example:
obj-y += foo.o
obj-y += dir/foo.o
CFLAGS_foo.o := <some-flags>
Here, the <some-flags> applies to both foo.o and dir/foo.o
The real world problem is:
scripts/kconfig/util.c
scripts/kconfig/lxdialog/util.c
Both files are compiled into scripts/kconfig/mconf, but only the
latter should be given with the ncurses flags.
It is more sensible to use the relative path to the Makefile, like this:
obj-y += foo.o
CFLAGS_foo.o := <some-flags>
obj-y += dir/foo.o
CFLAGS_dir/foo.o := <other-flags>
At first, I attempted to replace $(basetarget) with $*. The $* variable
is replaced with the stem ('%') part in a pattern rule. This works with
most of cases, but does not for explicit rules.
For example, arch/ia64/lib/Makefile reuses rule_as_o_S in its own
explicit rules, so $* will be empty, resulting in ignoring the per-file
AFLAGS.
I introduced a new variable, target-stem, which can be used also from
explicit rules.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Marc Zyngier <maz@kernel.org>
2019-08-30 04:34:01 +00:00
|
|
|
$(addprefix $(obj)/, $($(target-stem)-$(o)))) \
|
|
|
|
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
|
2014-08-19 07:34:21 +00:00
|
|
|
$(host-cxxmulti): FORCE
|
2005-04-16 22:20:36 +00:00
|
|
|
$(call if_changed,host-cxxmulti)
|
2014-08-19 07:34:21 +00:00
|
|
|
$(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
# Create .o file from a single .cc (C++) file
|
|
|
|
quiet_cmd_host-cxxobjs = HOSTCXX $@
|
|
|
|
cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
|
2024-06-24 11:12:14 +00:00
|
|
|
$(host-cxxobjs): $(obj)/%.o: $(obj)/%.cc FORCE
|
2005-04-16 22:20:36 +00:00
|
|
|
$(call if_changed_dep,host-cxxobjs)
|
|
|
|
|
2021-07-03 14:42:57 +00:00
|
|
|
# Create executable from a single Rust crate (which may consist of
|
|
|
|
# one or more `.rs` files)
|
|
|
|
# host-rust -> Executable
|
|
|
|
quiet_cmd_host-rust = HOSTRUSTC $@
|
|
|
|
cmd_host-rust = \
|
2023-01-07 09:18:17 +00:00
|
|
|
$(HOSTRUSTC) $(hostrust_flags) --emit=link=$@ $<
|
2021-07-03 14:42:57 +00:00
|
|
|
$(host-rust): $(obj)/%: $(src)/%.rs FORCE
|
kbuild: mark `rustc` (and others) invocations as recursive
`rustc` (like Cargo) may take advantage of the jobserver at any time
(e.g. for backend parallelism, or eventually frontend too). In the kernel,
we call `rustc` with `-Ccodegen-units=1` (and `-Zthreads` is 1 so far),
so we do not expect parallelism. However, in the upcoming Rust 1.76.0, a
warning is emitted by `rustc` [1] when it cannot connect to the jobserver
it was passed (in many cases, but not all: compiling and `--print sysroot`
do, but `--version` does not). And given GNU Make always passes
the jobserver in the environment variable (even when a line is deemed
non-recursive), `rustc` will end up complaining about it (in particular
in Make 4.3 where there is only the simple pipe jobserver style).
One solution is to remove the jobserver from `MAKEFLAGS`. However, we
can mark the lines with calls to `rustc` (and Cargo) as recursive, which
looks simpler. This is being documented as a recommendation in `rustc`
[2] and allows us to be ready for the time we may use parallelism inside
`rustc` (potentially now, if a user passes `-Zthreads`). Thus do so.
Similarly, do the same for `rustdoc` and `cargo` calls.
Finally, there is one case that the solution does not cover, which is the
`$(shell ...)` call we have. Thus, for that one, set an empty `MAKEFLAGS`
environment variable.
Link: https://github.com/rust-lang/rust/issues/120515 [1]
Acked-by: Masahiro Yamada <masahiroy@kernel.org>
Link: https://github.com/rust-lang/rust/pull/121564 [2]
Link: https://lore.kernel.org/r/20240217002638.57373-1-ojeda@kernel.org
[ Reworded to add link to PR documenting the recommendation. ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-02-17 00:26:37 +00:00
|
|
|
+$(call if_changed_dep,host-rust)
|
2021-07-03 14:42:57 +00:00
|
|
|
|
2020-07-29 03:15:36 +00:00
|
|
|
targets += $(host-csingle) $(host-cmulti) $(host-cobjs) \
|
2021-07-03 14:42:57 +00:00
|
|
|
$(host-cxxmulti) $(host-cxxobjs) $(host-rust)
|