Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2902490imm; Wed, 16 May 2018 23:20:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqmVWoM6ZAp8Kj6fWgYSPt0f8+rPI/3m1Oh5JXngr4Sd9vunikaV+M6EDzFXJxA8a45UUbC X-Received: by 2002:a65:44c3:: with SMTP id g3-v6mr3121984pgs.428.1526538007151; Wed, 16 May 2018 23:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538007; cv=none; d=google.com; s=arc-20160816; b=dCcxAWWyLswAFAmtx87sglafMvE1WlTb4x+Q+njVBqmGfOBJGcz3CHzuALLE/hrYTw X6/kUAIX9VJYbZ4PkO9GxuDPCZjUVjenDOoS7uE226l1tgTLMMMtAqVH77cCNF6YPGmL XZmeAQtFkzepH9PTnxd6YnFc63UctonBYUR0A+9xzlLArpWUs9qJvJzLifLAgZTbE+p0 j9E7UQQNCf2l5cloQgPLSuMwSfFmXwAYQCacScC6gc1GueOsqKQKOSKv1lx9EmcpXGUs YXbVTzZbjGjMPpre1joB5YCw+s+6BU9omd8F0GARGUcDLmgIbBA1QQbYX3Og8cPVzYzU e08A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=eENoMDFY0PNYPD2jYFeMGggW47xsAzSKITeObRHmmlQ=; b=YP12q/B7eIBSjfMain70K34jO51qiYrDuGH2EnYz3pfDWNj6aavuQjlTB620ISNm5b 5I2ROWZe8s1AO8hcJvLlExnIkNkQtPJYSqrvEg7qpa+bknHBfCHkA9/Jy+gYAvyTWJfV q+AYe6oRB8V9LunLDgKgVR6lTIYE2EZeCtvtp6zk51ghhzK3NJYTTuoZLzVNynrk4LI3 oydqcleWzg8Bdfdkl1K5xP2buHw1gTsZJcWedFegeMoP6ZsoxuI1hWMncB9SgLj/HWR0 ZAJIGfpAekDh4/ZUewz6LzzoRosI8Cg+vR+clc2DuqJPFsfb0liPB1SdBTac5v9pzpoj gSGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=MadLPkbE; 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 g1-v6si4307950pld.11.2018.05.16.23.19.53; Wed, 16 May 2018 23:20:07 -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=MadLPkbE; 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 S1752240AbeEQGTX (ORCPT + 99 others); Thu, 17 May 2018 02:19:23 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 }, -- 2.7.4