Received: by 10.192.165.156 with SMTP id m28csp2189313imm; Sat, 14 Apr 2018 16:37:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx4964F25gsEIo1T7DuguHqqFx6Kp2PO1iFi+WSezUnshQllDhspTmSk0pPLbkRMaXdk/tliO X-Received: by 2002:a17:902:1681:: with SMTP id h1-v6mr10162333plh.145.1523749072916; Sat, 14 Apr 2018 16:37:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523749072; cv=none; d=google.com; s=arc-20160816; b=YRMVNkzAvVBaV3hT9IlsO0t+VLwS+G0UpQXChf5VHrl8yd28sR+wMjnPc92N+mTwk0 iSJ2ZEdlDYFG7brRlPQJMEjAUsbnkSDgSnN4igy/uJvt8nGUPRHN6S7t+ZwPkWA+XUiB camFuvuHd/wmSuHiRJfTuk7388BlF2vvHcCniGwRnCP7D3Wfw9BR4q4ge55+LucQhQLq rUHVXmMUqXcfRygL79mFTjYNVHb40rxTHmy527OXsIfVw4m7Dsf7RcuNQc2j5JfymVcw w33hdMOnwMtiVnmJTQ/N6rqfXARCZ7ldMO2NfaKDUpJvGV+rsQ//4RB1M0zZ9kpt3bOL Wnnw== 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:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=dkBdpXPVKhun0gc/D4zb/brUGnBQgsrxRsMc+VvoIX0=; b=VocTPk5zadR4c4n9LWxIcMTZnGZr62ptPrTZt2LpGSqy7bqYn1RN4cAkZrV8klG/e8 GsuA2MxRHyE9viQR3PHgfCf1eoHuNvgGAh7+HOn/UP+8k8DQRF6P1dHgO6HpkiLzM9NO dr69FFPh87sp/8RZ/J/uRfnnlAywdVWRd3v4ODHSo9Av43AXfnWMua+KzgikUg97j20F byR++Oguk1LO365j+PuJn/IcbqvS4drOgVRyNH8vlqErxFi0w4O2+h4hBD+1prOSYtYB YxymQaVLBLT8B9ux/hlDq3J/w5szOT8D7M8U78ouZpgsTjo++FrplsMupqKMifCzD/C2 IZJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=LOrR6Xug; 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 y136si7957060pfg.81.2018.04.14.16.37.03; Sat, 14 Apr 2018 16:37:52 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=LOrR6Xug; 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 S1752176AbeDNXdi (ORCPT + 99 others); Sat, 14 Apr 2018 19:33:38 -0400 Received: from merlin.infradead.org ([205.233.59.134]:43874 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751623AbeDNXdh (ORCPT ); Sat, 14 Apr 2018 19:33:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=dkBdpXPVKhun0gc/D4zb/brUGnBQgsrxRsMc+VvoIX0=; b=LOrR6Xugn/5C16mpFlS1C4f+YM jzBIrW3w7hkNjeeg5ht05+9dTkhT2bnhKb2TVIWkwDJjZqqIVV349B2xOBT0XwnV3kDASiyu8zlbP VXtE+zCXEEyE6XRf9RDk/ViUPdXFe1naPK9hlU+dMIXYKtIlkjOtW1k7GUCzZOphJcI48bK46aFnY uQryqOWuT4zSUhLk4V/bb0i9yxmfxtZvBxGiJLcRKy8uluQq/HXAeHc507XDi15asLG+uPGWWL/ai 8RIyIDOn3Se5Gsiqhjh1scdzfipB4CeyOOpVUvplJTPQVReaF0/JTHdzFaTO/ohqbMtN9LNT+MfW0 Zbpyml3Q==; Received: from [96.71.163.243] (helo=vortex.dunlab) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1f7Ufg-0006Ha-FT; Sat, 14 Apr 2018 23:33:29 +0000 Subject: Re: [PATCH 17/30] Documentation: kconfig: document a new Kconfig macro language To: Masahiro Yamada , linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, linux-kernel@vger.kernel.org References: <1523595999-27433-1-git-send-email-yamada.masahiro@socionext.com> <1523595999-27433-18-git-send-email-yamada.masahiro@socionext.com> From: Randy Dunlap Message-ID: <9086cd96-bbeb-fa6e-6a62-8869ae8c7ee3@infradead.org> Date: Sat, 14 Apr 2018 16:33:21 -0700 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1523595999-27433-18-git-send-email-yamada.masahiro@socionext.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/12/18 22:06, Masahiro Yamada wrote: > Add a document for the macro language introduced to Kconfig. > > Signed-off-by: Masahiro Yamada > --- > > Changes in v3: None > Changes in v2: None > > Documentation/kbuild/kconfig-macro-language.txt | 179 ++++++++++++++++++++++++ > MAINTAINERS | 2 +- > 2 files changed, 180 insertions(+), 1 deletion(-) > create mode 100644 Documentation/kbuild/kconfig-macro-language.txt > > diff --git a/Documentation/kbuild/kconfig-macro-language.txt b/Documentation/kbuild/kconfig-macro-language.txt > new file mode 100644 > index 0000000..1f6281b > --- /dev/null > +++ b/Documentation/kbuild/kconfig-macro-language.txt > @@ -0,0 +1,179 @@ > +Concept > +------- > + > +The basic idea was inspired by Make. When we look at Make, we notice sort of > +two languages in one. One language describes dependency graphs consisting of > +targets and prerequisites. The other is a macro language for performing textual > +substitution. > + > +There is clear distinction between the two language stages. For example, you > +can write a makefile like follows: > + > + APP := foo > + SRC := foo.c > + CC := gcc > + > + $(APP): $(SRC) > + $(CC) -o $(APP) $(SRC) > + > +The macro language replaces the variable references with their expanded form, > +and handles as if the source file were input like follows: > + > + foo: foo.c > + gcc -o foo foo.c > + > +Then, Make analyzes the dependency graph and determines the targets to be > +updated. > + > +The idea is quite similar in Kconfig - it is possible to describe a Kconfig > +file like this: > + > + CC := gcc > + > + config CC_HAS_FOO > + def_bool $(shell $(srctree)/scripts/gcc-check-foo.sh $(CC)) > + > +The macro language in Kconfig processes the source file into the following > +intermediate: > + > + config CC_HAS_FOO > + def_bool y > + > +Then, Kconfig moves onto the evaluation stage to resolve inter-symbol > +dependency, which is explained in kconfig-language.txt. > + > + > +Variables > +--------- > + > +Like in Make, a variable in Kconfig works as a macro variable. A macro > +variable is expanded "in place" to yield a text string that may then expanded may then be expanded > +further. To get the value of a variable, enclose the variable name in $( ). > +As a special case, single-letter variable names can omit the parentheses and is and are > +simply referenced like $X. Unlike Make, Kconfig does not support curly braces > +as in ${CC}. > + > +There are two types of variables: simply expanded variables and recursively > +expanded variables. > + > +A simply expanded variable is defined using the := assignment operator. Its > +righthand side is expanded immediately upon reading the line from the Kconfig > +file. > + > +A recursively expanded variable is defined using the = assignment operator. > +Its righthand side is simply stored as the value of the variable without > +expanding it in any way. Instead, the expansion is performed when the variable > +is used. > + > +There is another type of assignment operator; += is used to append text to a > +variable. The righthand side of += is expanded immediately if the lefthand > +side was originally defined as a simple variable. Otherwise, its evaluation is > +deferred. > + > + > +Functions > +--------- > + > +Like Make, Kconfig supports both built-in and user-defined functions. A > +function invocation looks much like a variable reference, but includes one or > +more parameters separated by commas: > + > + $(function-name arg1, arg2, arg3) > + > +Some functions are implemented as a built-in function. Currently, Kconfig > +supports the following: > + > + - $(shell command) > + > + The 'shell' function accepts a single argument that is expanded and passed > + to a subshell for execution. The standard output of the command is then read > + and returned as the value of the function. Every newline in the output is > + replaced with a space. Any trailing newlines are deleted. The standard error > + is not returned, nor is any program exit status. > + > + - $(warning text) > + > + The 'warning' function prints its arguments to stderr. The output is prefixed > + with the name of the current Kconfig file, the current line number. It file and the current line number. It > + evaluates to an empty string. > + > + - $(info text) > + > + The 'info' function is similar to 'warning' except that it sends its argument > + to stdout without any Kconfig name or line number. Are current Kconfig file name and line number available so that someone can construct their own $(info message) messages? > + > +A user-defined function is defined by using the = operator. The parameters are > +referenced within the body definition with $1, $2, etc. (or $(1), $(2), etc.) > +In fact, a user-defined function is internally treated as a recursive variable. so the difference is just whether there are arguments? A recursive variable does not have arguments and a function always has at least one argument? > + > +A user-defined function is referenced in the same way as a built-in function: > + > + $(my_func, arg0, arg1, arg2) Syntax given above is: + $(function-name arg1, arg2, arg3) with no comma after the function name. Which is it? > + > +Note 1: > +There is a slight difference in the whitespace handling of the function call > +between Make and Kconfig. In Make, leading whitespaces are trimmed from the > +first argument. So, $(info FOO) is equivalent to $(info FOO). Kconfig keeps > +any leading whitespaces except the one right after the function name, which > +works as a separator. So, $(info FOO) prints " FOO" to the stdout. > + > +Note 2: > +In Make, a user-defined function is referenced by using a built-in function, > +'call', like this: > + > + $(call my_func, arg0, arg1, arg2) > + > +However, Kconfig did not adopt this form just for the purpose of shortening the > +syntax. > + > + > +Caveats > +------- > + > +A variable (or function) can not be expanded across tokens. So, you can not use cannot cannot > +a variable as a shorthand for an expression that consists of multiple tokens. > +The following works: > + > + RANGE_MIN := 1 > + RANGE_MAX := 3 > + > + config FOO > + int "foo" > + range $(RANGE_MIN) $(RANGE_MAX) > + > +But, the following does not work: > + > + RANGES := 1 3 > + > + config FOO > + int "foo" > + range $(RANGES) > + > +A variable can not be expanded to any keyword in Kconfig. The following does cannot > +not work: > + > + MY_TYPE := tristate > + > + config FOO > + $(MY_TYPE) "foo" > + default y > + > +Obviously from the design, $(shell command) is expanded in the textual > +substitution phase. You can not pass symbols to the 'shell' function. cannot > +The following does not work as expected. > + > + config ENDIAN_OPTION > + string > + default "-mbig-endian" if CPU_BIG_ENDIAN > + default "-mlittle-endian" if CPU_LITTLE_ENDIAN > + > + config CC_HAS_ENDIAN_OPTION > + def_bool $(shell $(srctree)/scripts/gcc-check-option ENDIAN_OPTION) > + > +Instead, you can do like follows so that any function call is statically > +expanded. > + > + config CC_HAS_ENDIAN_OPTION > + bool fix indentation? > + default $(shell $(srctree)/scripts/gcc-check-option -mbig-endian) if CPU_BIG_ENDIAN > + default $(shell $(srctree)/scripts/gcc-check-option -mlittle-endian) if CPU_LITTLE_ENDIAN -- ~Randy