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: 10821151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63A3A922 for ; Wed, 20 Feb 2019 04:24:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4205A2AC0D for ; Wed, 20 Feb 2019 04:24:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35F74286DB; Wed, 20 Feb 2019 04:24:07 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,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 B7672286DB for ; Wed, 20 Feb 2019 04:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbfBTEYF (ORCPT ); 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-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - $(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(-) 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))/)