From nobody Mon Feb 9 16:32:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+88403+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88403+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1649064770; cv=none; d=zohomail.com; s=zohoarc; b=frRqzJKFLNyukdigqjQpk6S2zm52GYypOX4bVZp3lMg+GO2SvcbZbvO/NdRqoMXLWQojAlXqLNSqHwyQCP6kS8JHHNzpaTA2CZDg4XwmM9mX4Njvtz+b4QJ5jBWqziCpwQRWoXErdjgfY+zFt0v0U3tytO+CI8eyf/hTW7BELHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649064770; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=/9Zvj3OiHtmkTRmIgxHwaaR99mxqztmS0xhdOhBxwWE=; b=SzA3EWL+cTOs23+sa8S6SuO+Z1LxgpkGGNSS65VmOyeHhi8QFyyZ+bsehHFVFAret9hTQNh0lKK7kgkulhBcCMwgyqq88vxYD/s3fuU/L4UOBtUTCLgBmSpiYazH/He0AW+RAcXvHVE72EEu7qGwnErJVTJgYGzNKkHshNzH0bI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88403+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1649064769958533.5935563728794; Mon, 4 Apr 2022 02:32:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id k1byYY1788612xIq1fBzvbxY; Mon, 04 Apr 2022 02:32:49 -0700 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web08.33139.1649064767173739748 for ; Mon, 04 Apr 2022 02:32:48 -0700 X-Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-623-ZENJCjBrNce5WXRvBOpW2w-1; Mon, 04 Apr 2022 05:32:43 -0400 X-MC-Unique: ZENJCjBrNce5WXRvBOpW2w-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F8A31C04B7E; Mon, 4 Apr 2022 09:32:37 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.194.10]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D9A1C575E5; Mon, 4 Apr 2022 09:32:31 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id EF20B180060A; Mon, 4 Apr 2022 11:32:29 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Yuwei Chen , Liming Gao , Pawel Polawski , Bob Feng , Oliver Steffen , Rebecca Cran , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 1/3] BaseTools: import compiler check macros from linux kernel Date: Mon, 4 Apr 2022 11:32:27 +0200 Message-Id: <20220404093229.1971782-2-kraxel@redhat.com> In-Reply-To: <20220404093229.1971782-1-kraxel@redhat.com> References: <20220404093229.1971782-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kraxel@redhat.com X-Gm-Message-State: PVJePsZbGlMDVQFl8BavbM6Yx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1649064769; bh=jyg4TiEfJx/Cw8hGcE6ZsuiGFBnORApdmKpxcyYYcYY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=BvpdeH164Wm0X6lzKOALYF+Qv1ZY2HOCSFK4PBP50U2PMwqplnddfLVRXBHGjLSo7j8 MidVeZbpaemlnxJPxnle9MW5oV5bo5ul60VOStO1gXljHmYwyT/GNcXxyZo/J99HBQjue bBFJsQwcqcVVgMT6p64wKr7adNj+TSYB3Zw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1649064771675100007 Content-Type: text/plain; charset="utf-8"; x-default="true" Makefile functions to check for compiler flags supported. Signed-off-by: Gerd Hoffmann --- .../Source/C/Makefiles/compiler.makefile | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 BaseTools/Source/C/Makefiles/compiler.makefile diff --git a/BaseTools/Source/C/Makefiles/compiler.makefile b/BaseTools/Sou= rce/C/Makefiles/compiler.makefile new file mode 100644 index 000000000000..b575391c08d6 --- /dev/null +++ b/BaseTools/Source/C/Makefiles/compiler.makefile @@ -0,0 +1,76 @@ +# SPDX-License-Identifier: GPL-2.0-only + +# copy from linux kernel soure tree (scripts/Makefile.compiler) + +# cc-cross-prefix +# Usage: CROSS_COMPILE :=3D $(call cc-cross-prefix, m68k-linux-gnu- m68k-l= inux-) +# Return first where a gcc is found in PATH. +# If no gcc found in PATH with listed prefixes return nothing +# +# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, = it +# would try to directly execute the shell builtin 'command'. This workarou= nd +# should be kept for a long time since this issue was fixed only after the +# GNU Make 4.2.1 release. +cc-cross-prefix =3D $(firstword $(foreach c, $(1), \ + $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) + +# output directory for tests below +TMPOUT =3D $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ + +# try-run +# Usage: option =3D $(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 =3D $(shell set -e; \ + TMP=3D$(TMPOUT)/tmp; \ + mkdir -p $(TMPOUT); \ + trap "rm -rf $(TMPOUT)" EXIT; \ + if ($(1)) >/dev/null 2>&1; \ + then echo "$(2)"; \ + else echo "$(3)"; \ + fi) + +# as-option +# Usage: cflags-y +=3D $(call as-option,-Wa$(comma)-isa=3Dfoo,) + +as-option =3D $(call try-run,\ + $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2= )) + +# as-instr +# Usage: cflags-y +=3D $(call as-instr,instr,option1,option2) + +as-instr =3D $(call try-run,\ + printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" = -,$(2),$(3)) + +# __cc-option +# Usage: MY_CFLAGS +=3D $(call __cc-option,$(CC),$(MY_CFLAGS),-march=3Dwin= chip-c6,-march=3Di586) +__cc-option =3D $(call try-run,\ + $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) + +# cc-option +# Usage: cflags-y +=3D $(call cc-option,-march=3Dwinchip-c6,-march=3Di586) + +cc-option =3D $(call __cc-option, $(CC),\ + $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2)) + +# cc-option-yn +# Usage: flag :=3D $(call cc-option-yn,-march=3Dwinchip-c6) +cc-option-yn =3D $(call try-run,\ + $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null = -o "$$TMP",y,n) + +# cc-disable-warning +# Usage: cflags-y +=3D $(call cc-disable-warning,unused-but-set-variable) +cc-disable-warning =3D $(call try-run,\ + $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c= /dev/null -o "$$TMP",-Wno-$(strip $(1))) + +# cc-ifversion +# Usage: EXTRA_CFLAGS +=3D $(call cc-ifversion, -lt, 0402, -O1) +cc-ifversion =3D $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $= (3) || echo $(4)) + +# ld-option +# Usage: KBUILD_LDFLAGS +=3D $(call ld-option, -X, -Y) +ld-option =3D $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(= 3)) + +# ld-ifversion +# Usage: $(call ld-ifversion, -ge, 22252, y) +ld-ifversion =3D $(shell [ $(CONFIG_LD_VERSION)0 $(1) $(2)0 ] && echo $(3)= || echo $(4)) --=20 2.35.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#88403): https://edk2.groups.io/g/devel/message/88403 Mute This Topic: https://groups.io/mt/90237793/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-