From patchwork Thu May 9 20:19:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 163758 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1451733ilr; Thu, 9 May 2019 13:19:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqb/6z2Oubfm3hJ9uNwRKYit8fC/WJLfYvKrFBJccXqueNvUWyGaPiYakgu1zEKC+aA3A8 X-Received: by 2002:a65:5003:: with SMTP id f3mr8138252pgo.336.1557433176327; Thu, 09 May 2019 13:19:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557433176; cv=none; d=google.com; s=arc-20160816; b=n/VBiY/1yYrK/XEZn63bgi8Kt5TSM0vXKMf5oHTqMbgmJQWJiyrjgpXlw9PoqsXv7p RTssrDO8owXxVtcvzLgB9o2fh25RdRW7Fcsdxq7m2G5uDHAhgPaOlmts03GrwAJbauAQ eX9tYOQGKPz2UGC05iNuHIe+1kI0QqYzBXPLY5TWgqVBSUaJLqvHRLD0w1GQSalaO2GC pMTudNPMFNaF/Ij2Kz6b3z287l8VoflslVenid0aEcytjPH4fl0vEfRzOoGIxm6wXf9C vPd7eer28Izt453Yyb41Q3Xjunj7tBGgWqmh1SnKviPgeu9j9AMLr8q/4RzXwzii/sLx TG7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=9SJVZdHZDV7vMt7Q88/HKWL/kPExbd/JsbUOjuQz1C4=; b=q7rNGE1Hnan3A2ky4QwG2ou1imdQDSj7pZ2YzmqIJ9M0cvkQ0WTIAAyVM1bfmJvH7Q FHBaAdLz2kE8aYvvM7WeQDXNWIrZwIFADrknnnNNOAmCTEZowlizfBSu126aj2+mLZ08 ngYaGuTeNkh5Xt4MXS950GfuyAti4GuED5Ef3ebutUY0twcrD6/jUexu/3G8FNjVVKki 6Jl8N2E+9zsc3yJpSFQf6AHiIahdxcVQvNLec8izM+wOHT5D1l2ODbA7jKQFC6PtjhG6 E/UB54BVEovRIUeZGPVMKBxSqISVZELpIY/lpwEwnlUH4C0fZn2fOjxI7UtGENJ+MKmo EfDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=J+ogomPB; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si3547982pgo.435.2019.05.09.13.19.36; Thu, 09 May 2019 13:19:36 -0700 (PDT) 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=@google.com header.s=20161025 header.b=J+ogomPB; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727073AbfEIUTd (ORCPT + 30 others); Thu, 9 May 2019 16:19:33 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:46123 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726967AbfEIUTa (ORCPT ); Thu, 9 May 2019 16:19:30 -0400 Received: by mail-pl1-f202.google.com with SMTP id y1so2208192plr.13 for ; Thu, 09 May 2019 13:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=9SJVZdHZDV7vMt7Q88/HKWL/kPExbd/JsbUOjuQz1C4=; b=J+ogomPB45YKyRjFLwwk5dz5jQbrbFwqH8ZsYquGZgo7y9Gh9cGSZa5peLq7SGYIoD UVa7cicag0uG4ZrjPBHYXgqmcOhuLK8mICQWDu5y+sOVvT1IUrZZAo69xt5VZXuI+fOz Ev0HPV6/QfGN5GmovTV136dC4bdCThh9RzPbzrWKbZUaYsL5tqAAbh+MW9Se3uGi5fkA d2WPDV8KotABIkIRHYEvN/PYtIPVtgwU5cVNtvAn/SqSYn2r0Uk0gjCZVgwZdG1KQsoL IOkYf2UlWkxfeOXsFqV0zW26sXCPhObUu7mbMqab23wYxEx/gdWA08yl+nba0lnsC/bD drGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=9SJVZdHZDV7vMt7Q88/HKWL/kPExbd/JsbUOjuQz1C4=; b=GKciKtMeCm+K5Y+PuTyG/suIJF9ZI/b1zvteMbWXPdjK4OmOPjIswCQYOaZa1f0bJf t1186u7duhrLvx/AwY2AmjMi2p22/To16ZMb1BQiUf0tEd1BXB3bLxxiOiWIaCCW1gvG fSbLDYIRKh1lEecatLpEc/fm4lsKOxgMOexX2Ywev+BIESd+xGgIPEx4zRi9LkahftJk YZCbXfJKHiGVOzqiRt/RB2atFxbvakQrCrgot5hX5+3wkPTWHjoW5KHcmr55C7YP4jeY gKx2nMVYPt7IC3w2OfCoI+vbiCtd5A5/YuuYMtbvarRQdvhez7NTDfUIySob0wiVJylA bwXw== X-Gm-Message-State: APjAAAW5rXhxCGLzYyCQYCZcU4WOEXCsbMItFwKdCllwh3GspZQZUAHm hqXJOUYT4+9BDvzaKR6evTeaJP7vKavZyd9fPUk= X-Received: by 2002:a63:8949:: with SMTP id v70mr8548978pgd.196.1557433169453; Thu, 09 May 2019 13:19:29 -0700 (PDT) Date: Thu, 9 May 2019 13:19:21 -0700 Message-Id: <20190509201925.189615-1-ndesaulniers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog Subject: [PATCH] kbuild: add script check for cross compilation utilities From: Nick Desaulniers To: yamada.masahiro@socionext.com Cc: clang-built-linux@googlegroups.com, Nick Desaulniers , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When cross compiling via setting CROSS_COMPILE, if the prefixed tools are not found, then the host utilities are often instead invoked, and produce often difficult to understand errors. This is most commonly the case for developers new to cross compiling the kernel that have yet to install the proper cross compilation toolchain. Rather than charge headlong into a build that will fail obscurely, check that the tools exist before starting to compile, and fail with a friendly error message. Before: $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make CC=clang ... /usr/bin/as: unrecognized option '-EL' clang: error: assembler command failed with exit code 1 (use -v to see invocation) make[2]: *** [../scripts/Makefile.build:279: scripts/mod/empty.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [/linux/Makefile:1118: prepare0] Error 2 make: *** [Makefile:179: sub-make] Error 2 After: $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make CC=clang $CROSS_COMPILE set to arm-linux-gnueabihf-, but unable to find arm-linux-gnueabihf-as. Makefile:522: recipe for target 'outputmakefile' failed make: *** [outputmakefile] Error 1 Signed-off-by: Nick Desaulniers --- Note: this is probably more generally useful, but after a few minutes wrestling with Make errors related to "recipe commences before first target" and "missing separator," I came to understand my hatred of GNU Make. Open to sugguestions for where better to invoke this from the top level Makefile. Makefile | 1 + scripts/check_crosscompile.sh | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100755 scripts/check_crosscompile.sh -- 2.21.0.1020.gf2820cf01a-goog Reviewed-by: Nathan Chancellor diff --git a/Makefile b/Makefile index a61a95b6b38f..774339674b59 100644 --- a/Makefile +++ b/Makefile @@ -519,6 +519,7 @@ endif ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),) ifneq ($(CROSS_COMPILE),) + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/check_crosscompile.sh CLANG_FLAGS := --target=$(notdir $(CROSS_COMPILE:%-=%)) GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR) diff --git a/scripts/check_crosscompile.sh b/scripts/check_crosscompile.sh new file mode 100755 index 000000000000..f4586fbfee18 --- /dev/null +++ b/scripts/check_crosscompile.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# (c) 2019, Nick Desaulniers +function check () { + # Remove trailing commands, for example arch/arm/Makefile may add `-EL`. + utility=$(echo ${1} | awk '{print $1;}') + command -v "${utility}" &> /dev/null + if [[ $? != 0 ]]; then + echo "\$CROSS_COMPILE set to ${CROSS_COMPILE}," \ + "but unable to find ${utility}." + exit 1 + fi +} +utilities=("${AS}" "${LD}" "${CC}" "${AR}" "${NM}" "${STRIP}" "${OBJCOPY}" + "${OBJDUMP}") +for utility in "${utilities[@]}"; do + check "${utility}" +done