Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1616119imm; Wed, 8 Aug 2018 22:09:32 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzhT9J1MgMSPl7GAYOvbFTrxY6ZuThfhWS5+j8Avc8t3NxUIl78cSloQjgVmCPwo5LuF2gU X-Received: by 2002:a63:24c:: with SMTP id 73-v6mr652857pgc.252.1533791371962; Wed, 08 Aug 2018 22:09:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533791371; cv=none; d=google.com; s=arc-20160816; b=ldsR9H7pF8GzWpj8TZgNW3lJv9Ngps0nmdXe9R57MLQm9DlqGlxtPc7EINAF+nwjUa gKe9GOzH6IcdwzDHpemuOPLh60Vb1ehT4UQ2Kx4Hg9a0ZTZQQ6+S8x8oODvoKL4Y1LTk XK1OvOFj98iLXFfq9qptLKkF1bY5WfceOWsSeiMDTg23xmhqEGmvPuVkotiH7H8jz1LW +KYTcW5morq0UutIHBw6sEoSLwQjwhVFaVToWdhZQSwQTC69yfBGjKMGisuCw1By1X1N 7Og9VKPso4ppfcuqPkjdQbOoRV1dEZSmv9fVdmCASNNveQwcCREUf+axG+sKdYKqHlQ7 yJWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-filter :arc-authentication-results; bh=Op8ngJJXgu2A2yiwX462/rZyVMZb/2ftkGBiTEgeiHc=; b=v9HZDT+HMyEbdd0Jsor0S0MMakrZsuXPKjOILnfL3TFyHekA8B+baEWtyNdJIy/TGB eGnil02og82GEyOZVXs8UvxBgsAmlQM2I3FZKWPiF7mZrTDIXNsRHEpUbOUV16TZbAzy IXYNK/7gd+7UgY/yhHG4U2R3ZxV7NzocscbxUT4ucmw0WaIcBatDQR4tRmUTr6HlQB5j cXAcA9vdDflfy95yVf16R5PEOfzaLBugxpPJrgvpuNKF79W7mwCDlCtZ06rULncxuZ5X KpXjI9qk/e0jE2DYndC/OjOjPuEtqZ+h2xZvLdsEhIhQVrkb5rAZZTvY0StI+jmqMGlC tRWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=GOAKDwf1; 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 h17-v6si5825596pgg.218.2018.08.08.22.09.17; Wed, 08 Aug 2018 22:09: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=@nifty.com header.s=dec2015msa header.b=GOAKDwf1; 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 S1729257AbeHIH3u (ORCPT + 99 others); Thu, 9 Aug 2018 03:29:50 -0400 Received: from conssluserg-06.nifty.com ([210.131.2.91]:33255 "EHLO conssluserg-06.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728034AbeHIH3u (ORCPT ); Thu, 9 Aug 2018 03:29:50 -0400 Received: from mail-ua0-f179.google.com (mail-ua0-f179.google.com [209.85.217.179]) (authenticated) by conssluserg-06.nifty.com with ESMTP id w7956ivq000810; Thu, 9 Aug 2018 14:06:45 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-06.nifty.com w7956ivq000810 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1533791205; bh=Op8ngJJXgu2A2yiwX462/rZyVMZb/2ftkGBiTEgeiHc=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=GOAKDwf1iLVZ3Bvrmoc8ZGmJxw+1XEJFWnJoDabjqJ/QrBUXL8XhcWcuUHpnLsri3 C1gVUrZvcDqf9TzZUGHhK6iRe+QxlCFYSy/rLD8fUx4EFhoTLhM741etspNSwKRDOD 6gAqtdq/j4phYyOuPNGB/AnY5j1CiiD4IYbQR2GF1bxJvjpchAlcUgME7+UYS5rIu5 WRonsZNoVt8z1WJsj1xnBIi22VgVrKXe19DwEdF6nIyFtMZlhf4pTZac+dioxDv209 Fsv/QHMNrKxb7dEOd/TyPQsepXvF53aitxD+jFTsKggtRRMrPu6qRc0gJ2fwqnJhSs RrBjKsEY9jBpg== X-Nifty-SrcIP: [209.85.217.179] Received: by mail-ua0-f179.google.com with SMTP id h1-v6so4936826uao.8; Wed, 08 Aug 2018 22:06:44 -0700 (PDT) X-Gm-Message-State: AOUpUlGyXi4XlJyzKf/E9AOW+TtEA77KwoxkTmgKEZ7v/wdUSXN6PFAA HcrJzgtBbOwg5JQpjDmTL+Q0lZcq9Ng4kmXmp8o= X-Received: by 2002:a1f:4049:: with SMTP id n70-v6mr359171vka.140.1533791203993; Wed, 08 Aug 2018 22:06:43 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab0:2642:0:0:0:0:0 with HTTP; Wed, 8 Aug 2018 22:06:03 -0700 (PDT) In-Reply-To: References: From: Masahiro Yamada Date: Thu, 9 Aug 2018 14:06:03 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/1] kbuild: allow alternate src for target's implicit prerequisite To: Vasily Gorbik Cc: Michal Marek , Linux Kernel Mailing List , Linux Kbuild mailing list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-08-06 23:37 GMT+09:00 Vasily Gorbik : > With kbuild there is no easy way to re-compile source files from another > directory, which is required for the decompressor on some platforms > (files like lib/ctype.c, lib/cmdline.c, etc). Writing custom build > rules for those files is not feasible since original rules are complex > and kbuild functions and variables are not exposed. > > The simplest solution is to reverse include source files either into > existing files or separate files. That eliminates the need to tackle > with the kbuild rules, but is ugly. > > Here is another solution to that problem, utilizing secondary expansion. > Build rules are in a form: > $(obj)/%.o: $(src)/%.c ... > $(obj)/%.o: $(src)/%.S ... > > "src" variable could be changed to cover the need of specifying alternate > source file directory. > src := $(if $(SRCDIR_$(@F)),$(SRCDIR_$(@F)),$(src)) > > So, if there is SRCDIR_ set, it will be used, original "src" is > used otherwise. But that wouldn't work as it is. To be able to utilize > automatic variables in implicit prerequisite secondary expansion has to > be used and src value has to be additionally escaped. > > Alternate src dir then could be specified in Makefile as: > obj-y := file1.o file2.o > SRCDIR_file1.o := file1/src/dir > SRCDIR_file2.o := file2/src/dir > > Which is enough to build $(obj)/file1.o from file1/src/dir/file1.(c|S), > and $(obj)/file2.o from file2/src/dir/file2.(c|S) Is this a simple solution compared with existing ones? Kind of. However, it is just moving the complexity around from Makefiles to the core build scripts, after all. I guess the increase of build time is not too big, ( 1 % or so for the incremental build of allmodconfig) but I do not like performing the second expansion for every directory to save some a few Makefiles. > Secondary expansion has been introduced with make 3.81, which is > minimal supported version by kbuild itself. > > Signed-off-by: Vasily Gorbik > --- > scripts/Makefile.build | 26 +++++++++++++++----------- > 1 file changed, 15 insertions(+), 11 deletions(-) > > diff --git a/scripts/Makefile.build b/scripts/Makefile.build > index 514ed63ff571..97c6ece96cfb 100644 > --- a/scripts/Makefile.build > +++ b/scripts/Makefile.build > @@ -70,6 +70,10 @@ $(warning kbuild: Makefile.build is included improperly) > endif > > # =========================================================================== > +# Allow to specify alternate source directory of target's implicit prerequisite > +# e.g. 'SRCDIR_cmdline.o := lib' This does not work for single targets. 'make foo/bar/cmdline.o' works, but 'make foo/bar/cmdline.i' does not. > +.SECONDEXPANSION: > +srcdir := $$(if $$(SRCDIR_$$(@F)),$$(SRCDIR_$$(@F)),$(src)) > -- Best Regards Masahiro Yamada