From patchwork Fri Jul 21 21:56:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 9857719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 66B3F60392 for ; Fri, 21 Jul 2017 21:57:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E3D7285B6 for ; Fri, 21 Jul 2017 21:57:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FC47285BB; Fri, 21 Jul 2017 21:57:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9171285B6 for ; Fri, 21 Jul 2017 21:57:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753527AbdGUV53 (ORCPT ); Fri, 21 Jul 2017 17:57:29 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:34521 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752780AbdGUV52 (ORCPT ); Fri, 21 Jul 2017 17:57:28 -0400 Received: by mail-pg0-f45.google.com with SMTP id 123so33605412pgj.1 for ; Fri, 21 Jul 2017 14:57:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=w/F4tiDoC8njpx5q/zJsdoWtonXgJa+Wek8drcKFABg=; b=haPOW68lT7bc/p/qrFIDYup/046YMK8xW4jYBwJ0XDRCAz+c8qr0137nPQ82IZWjlV HC3bYTl0uSVS4HJkbl360gw1IaT1kheXLsoPH2QQB2j9BYGhgIEzosXtzrAUQ2GF5JV4 5cFqYwYN/H86WmX+iMFtP1XxLZyc0BCSu5AMOPBKkHm6o5yd6mXnOq4UdGJrLJ9gGUt+ tnPhUfJYv4jvhvJdmiJuFUu+Mzny3oCi8zQJ/Dl/yIYelYnHBhWL9iIixUA/AOZorKGQ kksj3TmIGK6Ks2hMPNNQ1C1Z8cjGx6BLa7xNuQ0FWSB2sPxySmOUqutKrAaPfsmEXAgS h+UQ== X-Gm-Message-State: AIVw110+CPXoFRIzVlN8Gh2xqYUxwkyftrMxS1Y9sii+s9HcYDUJ0lMv aqem/fDtn26nl9Yj X-Received: by 10.99.109.140 with SMTP id i134mr8722111pgc.368.1500674247886; Fri, 21 Jul 2017 14:57:27 -0700 (PDT) Received: from mka.mtv.corp.google.com ([172.22.64.162]) by smtp.gmail.com with ESMTPSA id z16sm10303463pgc.90.2017.07.21.14.57.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Jul 2017 14:57:27 -0700 (PDT) From: Matthias Kaehlcke To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Masahiro Yamada , Michal Marek Cc: x86@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, dianders@chromium.org, Michael Davidson , Greg Hackmann , Nick Desaulniers , Stephen Hines , Kees Cook , Arnd Bergmann , Bernhard.Rosenkranzer@linaro.org, Matthias Kaehlcke Subject: [PATCH 1/2] kbuild: Add macros cc-option-3 and __cc-option-3 Date: Fri, 21 Jul 2017 14:56:56 -0700 Message-Id: <20170721215657.81631-1-mka@chromium.org> X-Mailer: git-send-email 2.14.0.rc0.284.gd933b75aa4-goog Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The macro cc-option receives two parameters (the second may be empty). It returns the first parameter if it is a valid compiler option, otherwise the second one. It is not evaluated if the second parameter is a valid compiler option. This seems to be fine in virtually all cases, however there are scenarios where the second paramater needs to be evaluated too, and an empty value (or a third option) should be returned if it is not valid. The macro cc-option-3 receives three parameters and returns parameter 1 or 2 (in this order) if one of them is found to be a valid compiler option, and otherwise paramater 3. The macro __cc-option-3 works analogously. Signed-off-by: Matthias Kaehlcke --- scripts/Kbuild.include | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index dd8e2dde0b34..dc83635f2317 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -113,6 +113,11 @@ as-instr = $(call try-run,\ __cc-option = $(call try-run,\ $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) +# __cc-option-3 +# Usage: MY_CFLAGS += $(call __cc-option-3,$(CC),$(MY_CFLAGS),\ +# -mpreferred-stack-boundary=2,-mstack-alignment=4,) +__cc-option-3 = $(call __cc-option,$(1),$(2),$(3),$(call __cc-option,$(1),$(2),$(4),$(5))) + # Do not attempt to build with gcc plugins during cc-option tests. # (And this uses delayed resolution so the flags will be up to date.) CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) @@ -123,6 +128,10 @@ CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) cc-option = $(call __cc-option, $(CC),\ $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2)) +# cc-option-3 +# Usage: cflags-y += $(call cc-option-3,-mpreferred-stack-boundary=3,-mstack-alignment=8,) +cc-option-3 = $(call cc-option,$(1),$(call cc-option,$(2),$(3))) + # hostcc-option # Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586) hostcc-option = $(call __cc-option, $(HOSTCC),\