From: Simon Glass <sjg@chromium.org>
To: Markus Mayer <mmayer@broadcom.com>
Cc: DTC Mailing List <devicetree-compiler@vger.kernel.org>,
David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH 1/1] Makefile: only use compiler flags when supported
Date: Tue, 8 Oct 2024 19:57:23 -0600 [thread overview]
Message-ID: <CAFLszTg6dapEB3vwu9CicFs==NUCHgpGGbH91kJ-zKCWUcMo6g@mail.gmail.com> (raw)
In-Reply-To: <20241008214134.171436-2-mmayer@broadcom.com>
Hi Markus,
On Tue, 8 Oct 2024 at 15:42, Markus Mayer <mmayer@broadcom.com> wrote:
>
> We need to check if some compiler flags are supported as not all
> compilers may do so. For instance, "-Wsuggest-attribute=format" is
> supported by gcc but not by clang.
>
> Using a compiler option that is not supported will most likely cause the
> build to fail, since we are building with "-Werror" and the compiler will
> issue a warning about the unknown option.
>
> As a result, we only use the option if the compiler understands it.
>
> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
> ---
> Makefile | 25 ++++++++++++++++++++++++-
> 1 file changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/Makefile b/Makefile
> index f1f0ab368cd3..febdca5742c5 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -3,6 +3,26 @@
> # Device Tree Compiler
> #
>
> +# try-run and cc-option were stolen from the Linux kernel
> +TMPOUT = .tmp_$$$$
> +# try-run
> +# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
> +# Exit code chooses option. "$$TMP" serves as a temporary file and is
> +# automatically cleaned up.
> +try-run = $(shell set -e; \
> + TMP=$(TMPOUT)/tmp; \
> + mkdir -p $(TMPOUT); \
> + trap "rm -rf $(TMPOUT)" EXIT; \
> + if ($(1)) >/dev/null 2>&1; \
> + then echo "$(2)"; \
> + else echo "$(3)"; \
> + fi)
> +
> +# cc-option
> +# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
> +cc-option = $(call try-run, \
> + $(CC) -Werror $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
> +
> #
> # Version information will be constructed in this order:
> # DTC_VERSION release version as MAJOR.MINOR.PATCH
> @@ -18,9 +38,12 @@ CONFIG_LOCALVERSION =
> ASSUME_MASK ?= 0
>
> CPPFLAGS = -I libfdt -I . -DFDT_ASSUME_MASK=$(ASSUME_MASK)
> +# Warnings where we need to check they are supported
> +OPT_WARNINGS = $(call cc-option,-Wsuggest-attribute=format)
This is fine, but you should be able to use the existing cc-option in U-Boot
> +# Regular warnings
> WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs -Wsign-compare \
> -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow \
> - -Wsuggest-attribute=format -Wwrite-strings
> + -Wwrite-strings $(OPT_WARNINGS)
> CFLAGS = -g -Os $(SHAREDLIB_CFLAGS) -Werror $(WARNINGS) $(EXTRA_CFLAGS)
>
> BISON = bison
> --
> 2.46.0
>
>
Regards,
Simon
next prev parent reply other threads:[~2024-10-09 1:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-08 21:41 [PATCH 0/1] DTC v1.7.1 Build Error Markus Mayer
2024-10-08 21:41 ` [PATCH 1/1] Makefile: only use compiler flags when supported Markus Mayer
2024-10-09 1:57 ` Simon Glass [this message]
2024-10-09 20:43 ` Markus Mayer
2024-10-09 21:15 ` Simon Glass
2024-10-09 21:18 ` Markus Mayer
2024-10-16 9:32 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFLszTg6dapEB3vwu9CicFs==NUCHgpGGbH91kJ-zKCWUcMo6g@mail.gmail.com' \
--to=sjg@chromium.org \
--cc=david@gibson.dropbear.id.au \
--cc=devicetree-compiler@vger.kernel.org \
--cc=mmayer@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).