Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp938617yba; Mon, 1 Apr 2019 21:49:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1Z5d4ErBYaL0Yb0V47oAPzXgZm5A/sf93DqjI4YQbAIgIKNZw+k9zPkOcNXzedzX2onMK X-Received: by 2002:a17:902:e391:: with SMTP id ch17mr8992591plb.196.1554180571603; Mon, 01 Apr 2019 21:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554180571; cv=none; d=google.com; s=arc-20160816; b=zPmSBOkn6wTWM3J3ByKPzNHRtgjSERW5p2luUdxm38VvneUNIpAi/XDlM3YVZYJ8vi t4Pt2cF6OsmkDGT8t1W7m0XJ8BisrLggwFjPNhwL/3w9fZTVfsEjr2h9oLLWP7R7RlLa //2L+LfHpY3vVBIMs6U6Sd4e3JzJ+jK41kBDLrLaewTUDtPdqfNtP34nkize0gAL637k dwLoB5KMUGfTy7wP2ImW06Xr2waV6BlfWbwcjQsZQVVNTF6c5ENEnwyH/5qw4mlfjxDf RY0UG5/awmyh9DSrmDeXB03Rzii2iQgga2NXxoPl2rG8Waa5mOCATLx2PSgwdYZRNV5F 2k/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:newsgroups:openpgp:from:reply-to:references:cc:to :subject:dkim-signature; bh=fG5+8goCREn2B6mOQWUy8HQT95KgdgjfEUm69jC0dao=; b=P4C+JERXUVpjFkLfEj5UZ66ktzI/GrAN2AIGKADhoeI+8wM6gAf8UmFuczinIP/6ul zMj1b3eqDmYdBuazcqKBJNK6YM2gh5FgkM/KYLQPiYm7NgC9QCdcOtLu6M84tZ5dPDNS ThlzjtT3dfDcKmQAst3J9r2xvOw2KdfFBh1RHer4IPFHvo2THRbgT03fqJkv5Tixsu64 zNT4vAQ0Z0JT0MOnmkWbJJCan2ZAUbl0fJrT+u9hvhIZWU8l+4crfoD0BnBndVbPXj0Q bC5tAwnaX7Fc7MU35lklJP8+2inOprtRUppyQ/YRG7MsScbXTQ6Jm7nEMyMqhQu1whOy 3HXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="WEMg0dC/"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si6541681pfc.158.2019.04.01.21.49.16; Mon, 01 Apr 2019 21:49:31 -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=@kernel.org header.s=default header.b="WEMg0dC/"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728768AbfDBEl5 (ORCPT + 99 others); Tue, 2 Apr 2019 00:41:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:49158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725812AbfDBEl5 (ORCPT ); Tue, 2 Apr 2019 00:41:57 -0400 Received: from [10.71.11.124] (unknown [147.50.13.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2923020651; Tue, 2 Apr 2019 04:41:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554180115; bh=o1orBNUqoGT7WvWBxrx3ZCt01taJOdMi0vlXBNLVaK0=; h=Subject:To:Cc:References:Reply-To:From:Date:In-Reply-To:From; b=WEMg0dC//yB+cp8/4WUjxPSS5J3HENn2UgtRliVWYlr9jEu6neCLQvvWztKPLDO35 RuIAFXHzVWEJU2KDdlDHYGYFYD0Bc58DltGuxi4M3c8FoL+kmFVC8u8YZNJYfeOUtN RkhBunrD+xKHn8OgbZmBUDt03tRM1nirLWky7GX8= Subject: Re: [PATCH 2/6] kbuild: allow Kbuild to start from any directory To: Masahiro Yamada , linux-kbuild@vger.kernel.org Cc: Michal Marek , linux-kernel@vger.kernel.org References: <1553947458-8311-1-git-send-email-yamada.masahiro@socionext.com> <1553947458-8311-2-git-send-email-yamada.masahiro@socionext.com> Reply-To: kbingham@kernel.org From: Kieran Bingham Openpgp: preference=signencrypt Newsgroups: gmane.linux.kernel,gmane.linux.kbuild.devel Message-ID: Date: Tue, 2 Apr 2019 11:41:38 +0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <1553947458-8311-2-git-send-email-yamada.masahiro@socionext.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Yamada-san, Thank you for the patches, I like the direction this series is taking. Small spelling error spotted below... But as I've now gone through all of it I'll offer Reviewed-by: Kieran Bingham On 30/03/2019 12:04, Masahiro Yamada wrote: > Kbuild always runs in the top of the output directory. > > If Make starts in the source directory with O=, it relocates the > working directory to the location specified by O=. > > Also, users can start build from the output directory by using the > Makefile generated by scripts/mkmakefile. > > With a little more effort, Kbuild will be able to start from any > directory path. > > This commit allows to specify the source directory by using > the -f option. > > For example, you can do: > > $ cd path/to/output/dir > $ make -f path/to/source/dir/Makefile > > Or, for the equivalent behavior, you can do: > > $ make O=path/to/output/dir -f path/to/source/dir/Makefile > > KBUILD_SRC is now deprecated. > > Signed-off-by: Masahiro Yamada > --- > > Makefile | 87 +++++++++++++++++++++++++++++++++++++--------------------------- > 1 file changed, 50 insertions(+), 37 deletions(-) > > diff --git a/Makefile b/Makefile > index 9cbd367..1b2a70e 100644 > --- a/Makefile > +++ b/Makefile > @@ -96,56 +96,65 @@ endif > > export quiet Q KBUILD_VERBOSE > > -# kbuild supports saving output files in a separate directory. > -# To locate output files in a separate directory two syntaxes are supported. > -# In both cases the working directory must be the root of the kernel src. > +# Kbuild will save output files in the current working directory. > +# This does not need to match to the root of the kernel source tree. > +# > +# For example, you can do this: > +# > +# cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile > +# > +# If you want to save output files in a different location, there are > +# two syntaxes to specify it. > +# > # 1) O= > # Use "make O=dir/to/store/output/files/" > # > # 2) Set KBUILD_OUTPUT > -# Set the environment variable KBUILD_OUTPUT to point to the directory > -# where the output files shall be placed. > -# export KBUILD_OUTPUT=dir/to/store/output/files/ > -# make > +# Set the environment variable KBUILD_OUTPUT to point to the output directory. > +# export KBUILD_OUTPUT=dir/to/store/output/files/; make > # > # The O= assignment takes precedence over the KBUILD_OUTPUT environment > # variable. > > -# KBUILD_SRC is not intended to be used by the regular user (for now), > -# it is set on invocation of make with KBUILD_OUTPUT or O= specified. > - > -# OK, Make called in directory where kernel src resides > -# Do we want to locate output files in a separate directory? > +# Do we want to change the working directory? > ifeq ("$(origin O)", "command line") > KBUILD_OUTPUT := $(O) > endif > > -ifneq ($(words $(subst :, ,$(CURDIR))), 1) > - $(error main directory cannot contain spaces nor colons) > +ifneq ($(KBUILD_OUTPUT),) > +# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot > +# expand a shell special character '~'. We use a bit tredious way to handle it. very minor, but I noticed while looking through the series ^^ s/bit tredious/somewhat tedious/ > +abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) > +$(if $(abs_objtree),, \ > + $(error failed to create output directory "$(KBUILD_OUTPUT)")) > + > +# $(realpath ...) resolves symlinks > +abs_objtree := $(realpath $(abs_objtree)) > +else > +abs_objtree := $(CURDIR) > +endif # ifneq ($(KBUILD_OUTPUT),) > + > +ifeq ($(abs_objtree),$(CURDIR)) > +# Suppress "Entering directory ..." unless we are changing the work directory. > +MAKEFLAGS += --no-print-directory > +else > +need-sub-make := 1 > endif > > -ifneq ($(KBUILD_OUTPUT),) > -# check that the output directory actually exists > -saved-output := $(KBUILD_OUTPUT) > -KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \ > - && pwd) > -$(if $(KBUILD_OUTPUT),, \ > - $(error failed to create output directory "$(saved-output)")) > +abs_srctree := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) > + > +ifneq ($(words $(subst :, ,$(abs_srctree))), 1) > +$(error source directory cannot contain spaces or colons) > +endif > > +ifneq ($(abs_srctree),$(abs_objtree)) > # Look for make include files relative to root of kernel src > # > # This does not become effective immediately because MAKEFLAGS is re-parsed > -# once after the Makefile is read. It is OK since we are going to invoke > -# 'sub-make' below. > -MAKEFLAGS += --include-dir=$(CURDIR) > - > +# once after the Makefile is read. We need to invoke sub-make. > +MAKEFLAGS += --include-dir=$(abs_srctree) > need-sub-make := 1 > -else > - > -# Do not print "Entering directory ..." at all for in-tree build. > -MAKEFLAGS += --no-print-directory > - > -endif # ifneq ($(KBUILD_OUTPUT),) > +endif > > ifneq ($(filter 3.%,$(MAKE_VERSION)),) > # 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x > @@ -155,6 +164,7 @@ need-sub-make := 1 > $(lastword $(MAKEFILE_LIST)): ; > endif > > +export abs_srctree abs_objtree > export sub_make_done := 1 > > ifeq ($(need-sub-make),1) > @@ -166,9 +176,7 @@ $(filter-out _all sub-make $(lastword $(MAKEFILE_LIST)), $(MAKECMDGOALS)) _all: > > # Invoke a second make in the output directory, passing relevant variables > sub-make: > - $(Q)$(MAKE) \ > - $(if $(KBUILD_OUTPUT),-C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR)) \ > - -f $(CURDIR)/Makefile $(MAKECMDGOALS) > + $(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS) > > endif # need-sub-make > endif # sub_make_done > @@ -213,16 +221,21 @@ ifeq ("$(origin M)", "command line") > KBUILD_EXTMOD := $(M) > endif > > -ifeq ($(KBUILD_SRC),) > +ifeq ($(abs_srctree),$(abs_objtree)) > # building in the source tree > srctree := . > else > - ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR))) > + ifeq ($(abs_srctree)/,$(dir $(abs_objtree))) > # building in a subdirectory of the source tree > srctree := .. > else > - srctree := $(KBUILD_SRC) > + srctree := $(abs_srctree) > endif > + > + # TODO: > + # KBUILD_SRC is only used to distinguish in-tree/out-of-tree build. > + # Replace it with $(srctree) or something. > + KBUILD_SRC := $(abs_srctree) > endif > > export KBUILD_CHECKSRC KBUILD_EXTMOD KBUILD_SRC > -- -- Kieran