lkml.org 
[lkml]   [2018]   [Mar]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v2 09/21] kconfig: add 'macro' keyword to support user-defined function
On Mon, Mar 26, 2018 at 10:29 PM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> Now, we got a basic ability to test compiler capability in Kconfig.
>
> config CC_HAS_STACKPROTECTOR
> def_bool $(shell (($CC -Werror -fstack-protector -c -x c /dev/null -o /dev/null) && echo y) || echo n)
>
> This works, but it is ugly to repeat this long boilerplate.
>
> We want to describe like this:
>
> config CC_HAS_STACKPROTECTOR
> bool
> default $(cc-option -fstack-protector)
>
> It is straight-forward to add a new function, but I do not like to
> hard-code specialized functions like this. Hence, here is another
> feature to add functions from Kconfig files.
>
> A user-defined function is defined with a special keyword 'macro'.
> It can be referenced in the same way as built-in functions. This
> feature was also inspired by Makefile where user-defined functions
> are referenced by $(call func-name, args...), but I omitted the 'call'
> to makes it shorter.
>
> The macro definition can contain $(1), $(2), ... which will be replaced
> with arguments from the caller. The macro works just as a textual
> shorthand, which is also expanded in the lexer phase.
>
> [Example Code]
>
> macro success $(shell ($(1) && echo y) || echo n)
>
> config TRUE
> bool "true"
> default $(success true)
>
> config FALSE
> bool "false"
> default $(success false)
>
> [Result]
>
> $ make -s alldefconfig
> $ tail -n 2 .config
> CONFIG_TRUE=y
> # CONFIG_FALSE is not set
>
> [Example Code]
>
> macro success $(shell ($(1) && echo y) || echo n)
>
> macro cc-option $(success $CC -Werror $(1) -c -x c /dev/null -o /dev/null)
>
> config CC_HAS_STACKPROTECTOR
> def_bool $(cc-option -fstack-protector)
>
> [Result]
> $ make -s alldefconfig
> $ tail -n 1 .config
> CONFIG_CC_HAS_STACKPROTECTOR=y
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Cool, I like this "macro" idea for keeping this clean.

> ---
>
> Reminder for myself:
> Update Documentation/kbuild/kconfig-language.txt

Yes please. :)

Otherwise, looks good!

-Kees

--
Kees Cook
Pixel Security

\
 
 \ /
  Last update: 2018-03-28 05:45    [W:0.375 / U:0.328 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site