From patchwork Wed Feb 20 04:23:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 158754 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4467990jaa; Tue, 19 Feb 2019 20:24:09 -0800 (PST) X-Google-Smtp-Source: AHgI3IYzVJ4CSSAYbPGh/GhzDO1ggLgHWdI9D+eJkoPDGtoWDu2qDEkDHr9h/31lRSXyNTYjhsl+ X-Received: by 2002:a17:902:850a:: with SMTP id bj10mr12162836plb.91.1550636648988; Tue, 19 Feb 2019 20:24:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550636648; cv=none; d=google.com; s=arc-20160816; b=Fy6rxhBSeXgp5XNa+mtgOROkO4wJjBL5Pt62pGk8QIK/57n9TROnsYrZCZsawq9Hif GgRkRx2ScImww10H/ZbgL5O2Sn5iXoJd4fN4q0iyPYWhchwDYqQbyLxZS7c8+PjHeHLy CAOnyNRqN/2oQNmUPt7lQ/ZdU08yTWe/1KGbQYNrt2X4SO3KSjD5vEAwDrf8cjXN4iQ0 CBpQydVonbl9PQpQk0WZyxRZBLRSYT31p0psCrGbPitgYqylP2wTeKCsRUPZvyU6t7Fd ope8JE79LGrSNK2rOJgB9ciUQndhsDVgJMEtw9XtCzPln6lfMR3OfQBVfSgjctfxQndy 4v4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=CalrtVHXcO2JrNtJtgEYVmX+OuO2Eqf+H4VMUdwBRg0=; b=c82JVyS7XWxLmGKGY5ls+Hll6qiHYOYvpiOJMxRAT1OdEav+I03hPg42AipnAnyUyf uJX9DP8ES4j0Lq+SXBvH5e2H2/4VRgwPvA8ostlMnU+37H0brL4IFRb2b4/1lE6gMtIe HkkRCZtYZq6iYwMcpkXc6T9HwN8By52FWJ4O89wBzS3UCBJ7s0BgNvgmurC8wKv1E410 +Bn5cYikKhCbmdHn+XT3zRpQYH7+vn7vn299dJHpuo76lRpBIf4X3sH673FOl8+XO6tz SrP+N5J2H2m1EmSdcNpM3dOaY6yI6wMDnGM31DlzqXXJmJEbiqb0DFynv4/o7FbYFQr3 jA2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=GTdHyPEb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg3si18402454plb.363.2019.02.19.20.24.07; Tue, 19 Feb 2019 20:24:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=GTdHyPEb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729180AbfBTEYF (ORCPT + 32 others); Tue, 19 Feb 2019 23:24:05 -0500 Received: from conuserg-07.nifty.com ([210.131.2.74]:26323 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727035AbfBTEYF (ORCPT ); Tue, 19 Feb 2019 23:24:05 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id x1K4NxgV027325; Wed, 20 Feb 2019 13:23:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com x1K4NxgV027325 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1550636640; bh=CalrtVHXcO2JrNtJtgEYVmX+OuO2Eqf+H4VMUdwBRg0=; h=From:To:Cc:Subject:Date:From; b=GTdHyPEbaX4qaOEI5AcPNYxHOxrzYQZ9KmTu4UXc9sHIzHDzJZ0HCfAliKQzrtQ77 PAh9lqUfJeN7RJOswBMZzC5YivWaoZq1zexg4Uoq+Te2gr89kIcPv54PQXwstCfNu1 DrZikJavjw9ywWIV21zcFkWqOAgHmh9xcCVgt3JVJqGmQT4xGSjnqNV64dpP7ybG7t qkUtEqgY3x8/XE82orhylu4aKKLn3mEKjDNZ/mTmAGqP2qXLutGhAfYhoBlkWbgltv jgSZ6x2vxpFollL03blrQEK+i/GNKtjpyrjsrwOWvp8oaZNamrIYAxy1gZSj13uDJv FkW8G2yoE33bA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH] kbuild: refactor cc-cross-prefix implementation Date: Wed, 20 Feb 2019 13:23:56 +0900 Message-Id: <1550636636-25367-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org - $(word 1, ) is equivalent to $(firstword, ) - hardcode "gcc" instead of $(CC) - minimize the shell script part A little more notes since $(filter-out -%, ...) is not clear. arch/mips/Makefile passes prefixes depending on the configuration. CROSS_COMPILE := $(call cc-cross-prefix, $(tool-archpref)-linux- \ $(tool-archpref)-linux-gnu- $(tool-archpref)-unknown-linux-gnu-) In the Kconfig stage (e.g. when you run 'make defconfig'), neither CONFIG_32BIT nor CONFIG_64BIT is defined. So, $(tool-archpref) is empty. As a result, "-linux -linux-gnu- -unknown-linux-gnu" is passed into cc-cross-prefix. The command 'which' assumes arguments starting with a hyphen as command options, then emits the following messages: Illegal option -l Illegal option -l Illegal option -u I think it is wrong to define CROSS_COMPILE depending on the CONFIG options since you need to feed $(CC) to Kconfig, but it is how MIPS Makefile currently works. Anyway, it would not hurt to filter-out invalid strings beforehand. Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index d93250b..c1e15a4 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -71,14 +71,10 @@ endef # cc-cross-prefix # Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-) -# Return first prefix where a prefix$(CC) is found in PATH. -# If no $(CC) found in PATH with listed prefixes return nothing -cc-cross-prefix = \ - $(word 1, $(foreach c,$(1), \ - $(shell set -e; \ - if (which $(strip $(c))$(CC)) > /dev/null 2>&1 ; then \ - echo $(c); \ - fi))) +# Return first where a gcc is found in PATH. +# If no gcc found in PATH with listed prefixes return nothing +cc-cross-prefix = $(firstword $(foreach c, $(filter-out -%, $(1)), \ + $(if $(shell which $(c)gcc), $(c)))) # output directory for tests below TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/)