From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id B9E22386482B for ; Fri, 1 Sep 2023 13:04:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9E22386482B Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=kitware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kitware.com Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-76dbe1866ecso116161385a.0 for ; Fri, 01 Sep 2023 06:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kitware.com; s=google; t=1693573456; x=1694178256; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lP3364Z6HzVU3Ekzueaq+vdqRp4slb3XDgcyWa7noNc=; b=mKSqn+wu8F41XtDYYibSF3So+DTKaa0wqwHn/Qjktnec21leM1xOZ/o4uzMnJLszK8 XxQbMoI/zfQwN4Wuj7/VHJJTfk1I6XFX95epaVGbZ7KNJ0TMPvHXKZl84qrKkgrwQ04g a39rup0TKkXS0FHlbqb6dLsjOfDQYaX/+2JGY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693573456; x=1694178256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lP3364Z6HzVU3Ekzueaq+vdqRp4slb3XDgcyWa7noNc=; b=URVOtjO8SjHJ30ULYMtKH52VnRbDaw0GWlj0wBRUv5lOo/Z1xG7BKMN0RYNypv4Xuu SxTENwrFZyWwLrdUQuAs0+Y5GgaC3mBUzDCqZycEcAXaOLJfmmk1QrFP3OfTXSCDwYTS dryNj4gTX71CRb+9HVjSlAQHEBM6V8vloH0AZUB1uO/86BQ+ViIp5R25fcYpbV2s0GfN cL/GNAtNI/P9hxVLy7/ZHvUeApYSiJX5T+mCWARya74hSlyEIuEVHObBWFqopK6l4mgf zwqllDh3r7fOXE+YCP08gbTpUZ0V+byYPxO7DwZwxdmEt4JInDnKvNp8ngMGS8onA/YW zGFQ== X-Gm-Message-State: AOJu0Yyj8940uZdqin0cv7tJGU1HfAmIXIS85DX8+xHiEkdElcc132XD ELsn5KbLzHonRK6IvVD3sJ9DGA== X-Google-Smtp-Source: AGHT+IE6e5KYXwgXXPn3ixO5qrkiZrh25PK4DDlqQq8meOsXtj1G5tzWzzAXzqBTZPjHC5CFgv514g== X-Received: by 2002:a05:620a:408a:b0:76c:e7b7:1d9d with SMTP id f10-20020a05620a408a00b0076ce7b71d9dmr2875530qko.27.1693573455890; Fri, 01 Sep 2023 06:04:15 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id u7-20020ae9c007000000b0076cb0ed2d7asm1388835qkk.24.2023.09.01.06.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 06:04:15 -0700 (PDT) From: Ben Boeckel To: gcc-patches@gcc.gnu.org Cc: Ben Boeckel , jason@redhat.com, nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com Subject: [PATCH v8 1/4] spec: add a spec function to join arguments Date: Fri, 1 Sep 2023 09:04:01 -0400 Message-ID: <20230901130407.259768-2-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230901130407.259768-1-ben.boeckel@kitware.com> References: <20230901130407.259768-1-ben.boeckel@kitware.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When passing `-o` flags to other options, the typical `-o foo` spelling leaves a leading whitespace when replacing elsewhere. This ends up creating flags spelled as `-some-option-with-arg= foo.ext` which doesn't parse properly. When attempting to make a spec function to just remove the leading whitespace, the argument splitting ends up masking the whitespace. However, the intended extension *also* ends up being its own argument. To perform the desired behavior, the arguments need to be concatenated together. gcc/: * gcc.cc (join_spec_func): Add a spec function to join all arguments. Signed-off-by: Ben Boeckel --- gcc/gcc.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index fdfac0b4fe4..4c4e81dee50 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -447,6 +447,7 @@ static const char *greater_than_spec_func (int, const char **); static const char *debug_level_greater_than_spec_func (int, const char **); static const char *dwarf_version_greater_than_spec_func (int, const char **); static const char *find_fortran_preinclude_file (int, const char **); +static const char *join_spec_func (int, const char **); static char *convert_white_space (char *); static char *quote_spec (char *); static char *quote_spec_arg (char *); @@ -1772,6 +1773,7 @@ static const struct spec_function static_spec_functions[] = { "debug-level-gt", debug_level_greater_than_spec_func }, { "dwarf-version-gt", dwarf_version_greater_than_spec_func }, { "fortran-preinclude-file", find_fortran_preinclude_file}, + { "join", join_spec_func}, #ifdef EXTRA_SPEC_FUNCTIONS EXTRA_SPEC_FUNCTIONS #endif @@ -10975,6 +10977,27 @@ find_fortran_preinclude_file (int argc, const char **argv) return result; } +/* The function takes any number of arguments and joins them together. + + This seems to be necessary to build "-fjoined=foo.b" from "-fseparate foo.a" + with a %{fseparate*:-fjoined=%.b$*} rule without adding undesired spaces: + when doing $* replacement we first replace $* with the rest of the switch + (in this case ""), and then add any arguments as arguments after the result, + resulting in "-fjoined= foo.b". Using this function with e.g. + %{fseparate*:-fjoined=%:join(%.b$*)} gets multiple words as separate argv + elements instead of separated by spaces, and we paste them together. */ + +static const char * +join_spec_func (int argc, const char **argv) +{ + if (argc == 1) + return argv[0]; + for (int i = 0; i < argc; ++i) + obstack_grow (&obstack, argv[i], strlen (argv[i])); + obstack_1grow (&obstack, '\0'); + return XOBFINISH (&obstack, const char *); +} + /* If any character in ORIG fits QUOTE_P (_, P), reallocate the string so as to precede every one of them with a backslash. Return the original string or the reallocated one. */ -- 2.41.0