From patchwork Thu May 17 06:16:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 10405533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B5FE86037D for ; Thu, 17 May 2018 06:23:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A64BD288D0 for ; Thu, 17 May 2018 06:23:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B38F2894C; Thu, 17 May 2018 06:23:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AAE1288D0 for ; Thu, 17 May 2018 06:23:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752200AbeEQGTT (ORCPT ); Thu, 17 May 2018 02:19:19 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24996 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751379AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUE002841; Thu, 17 May 2018 15:17:53 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUE002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537874; bh=eENoMDFY0PNYPD2jYFeMGggW47xsAzSKITeObRHmmlQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MadLPkbEtZupeCBXt6gen2ZONMJQ3NsYYWhDLY48P/HfRMJcJoQA28m+A5CCXRctP P+MpJAv8EJwC6kPgBMq2eT+0C8KWTOr1TpWH6i53VTtVg360COfwFl4F4lOziOUcPB JhX/h9WyYpQTh/xcfGxWoZI4C9IyQR8NeD2TTtXmogvMErTZo/eg/9liPa8Ot02ofe OgBifI9yrUOfz2cXpn3cqQ5rem59sH+8DKLGq21AexU1NetufrzIt7FeIt0WL7pJBh +xqcWvFxAhd9vkaLlaSgSfI+loB+LUiMpTDzy1F4skTf7z1if4bRsRnxatyFd6sKOR yeJZOw4qT19/w== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 16/31] kconfig: add 'if' built-in function Date: Thu, 17 May 2018 15:16:55 +0900 Message-Id: <1526537830-22606-17-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The 'if' function is invoked in the form: $(if,condition,then-part,else-part) The behavior is slightly different from that of Make. In Make, the condition is true if the expansion contains any characters (even space). That is why we sometimes need $(strip ...) in the condition part. I thought it was a nasty part in Make, so I changed it for Kconfig; the condition is true if the expansion contains any characters except whitespaces. Unlike the other functions, the parameters passed to 'if' are lazily expanded. The then-part is expanded only when the condition true, and the else-part when false. If the parameters were evaluated before passed to the 'if' function, $(if,$(cond),$(error,...)) would terminate the parsing regardless of $(cond). Signed-off-by: Masahiro Yamada --- Changes in v4: - Newly added Changes in v3: None Changes in v2: None scripts/kconfig/preprocess.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 591bcf7..88844a7 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -111,6 +111,32 @@ static char *do_error(int argc, char *argv[], int old_argc, char *old_argv[]) return NULL; } +static char *do_if(int argc, char *argv[], int old_argc, char *old_argv[]) +{ + char *cond, *p, *res; + const char *sel; + + cond = expand_string_with_args(argv[0], old_argc, old_argv); + p = cond; + + /* condition is true if any character except whitespaces is contained */ + while (*p == ' ' || *p == '\t') + p++; + + if (*p) + sel = argv[1]; + else if (argc >= 3) + sel = argv[2]; + else + sel = ""; + + res = expand_string_with_args(sel, old_argc, old_argv); + + free(cond); + + return res; +} + static char *do_info(int argc, char *argv[], int old_argc, char *old_argv[]) { printf("%s\n", argv[0]); @@ -168,6 +194,7 @@ static char *do_warning(int argc, char *argv[], int old_argc, char *old_argv[]) static const struct function function_table[] = { /* Name MIN MAX EXP? Function */ { "error", 1, 1, true, do_error }, + { "if", 2, 3, false, do_if }, { "info", 1, 1, true, do_info }, { "shell", 1, 1, true, do_shell }, { "warning", 1, 1, true, do_warning },