From patchwork Wed Aug 15 14:27:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10566653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 50D171815 for ; Wed, 15 Aug 2018 14:28:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4107329D86 for ; Wed, 15 Aug 2018 14:28:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 326D929D7D; Wed, 15 Aug 2018 14:28:08 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 DC8EA29D7D for ; Wed, 15 Aug 2018 14:28:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729432AbeHORU1 (ORCPT ); Wed, 15 Aug 2018 13:20:27 -0400 Received: from mail-lj1-f180.google.com ([209.85.208.180]:38102 "EHLO mail-lj1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729293AbeHORU0 (ORCPT ); Wed, 15 Aug 2018 13:20:26 -0400 Received: by mail-lj1-f180.google.com with SMTP id p6-v6so1105275ljc.5 for ; Wed, 15 Aug 2018 07:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QkFeSBVO3ndcBJySjbdB4jBjDn31pcPBVo8d0rQR4Gw=; b=bPpmvb/HZ/WLqWJI+/UNL49F065PaI8FHPuO7zbuWas/eUmHQusXBPQtlNXMsvVyqL YSo4P7NWFNy2Lx6pek8knvYz42+/pWbJlGMKPrfgrKojh50Zw72JEPK9ko5qWXTYqahl LE7MTBbXFXV747Hvp53LpW402ZehNae9RYrQQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QkFeSBVO3ndcBJySjbdB4jBjDn31pcPBVo8d0rQR4Gw=; b=NyI3ezH4OZldK2vTXO8HDQbNCsO2i3hFgWLfd6lVzAf5sxMTCJLfkv36McDgEZJ7XC 2IdVoS/06LnQCfk8whmnFlJPoBgXaLDwtO/tlaWV0nYm2OMxHqjYORH1lWX7CyJZykVQ 6NmCk/eINt9AF1KHyMsVPpA3g3jcAi+x4r8u19hkEYoKlOPd3qEWL46A/lKoTdBphC3I C5r2tZLGyy/ewcwH28stlCgqtvJdgX7rTA5Qm7g3AOzf3O9b5w1ZJkc8FEM8nU5lwE/i uVFFghF9XTEUrMNPap92BdCTZBFOX1Yu9di03yo8RHX/fjbwakeOsjoZeHoNvYVDoA8j Cywg== X-Gm-Message-State: AOUpUlHMJ5m9Hk25kxmBdRpMlrg7U4iOWOIFgJIX1y354CF6zE/W0ygE rT1mpXdsNHI2wYlJLcj1/MTHvfVcjlU07Q== X-Google-Smtp-Source: AA+uWPxBllHj7TP4r5les7Nlfo81SDfXjTNZYetuXv6oI97Wn06rSbbkSSTFiATM6N0y/o5pRBLJXQ== X-Received: by 2002:a2e:590e:: with SMTP id n14-v6mr18033982ljb.128.1534343283267; Wed, 15 Aug 2018 07:28:03 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id l3-v6sm4559597lfi.36.2018.08.15.07.28.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Aug 2018 07:28:02 -0700 (PDT) From: Rasmus Villemoes To: Masahiro Yamada , Michal Marek Cc: linux-kbuild@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] Kbuild: refactor fixdep to use getopt() Date: Wed, 15 Aug 2018 16:27:47 +0200 Message-Id: <20180815142749.18804-2-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180815142749.18804-1-linux@rasmusvillemoes.dk> References: <20180815142749.18804-1-linux@rasmusvillemoes.dk> 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 As preparation for teaching an old dog a few new tricks. Signed-off-by: Rasmus Villemoes --- scripts/basic/fixdep.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 850966f3d602..666041841200 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -381,16 +381,23 @@ int main(int argc, char *argv[]) const char *depfile, *target, *cmdline; int insert_extra_deps = 0; void *buf; + int opt; - if (argc == 5 && !strcmp(argv[1], "-e")) { - insert_extra_deps = 1; - argv++; - } else if (argc != 4) + while ((opt = getopt(argc, argv, "e")) != -1) { + switch (opt) { + case 'e': insert_extra_deps = 1; break; + default: usage(); + } + } + argc -= optind; + argv += optind; + + if (argc != 3) usage(); - depfile = argv[1]; - target = argv[2]; - cmdline = argv[3]; + depfile = argv[0]; + target = argv[1]; + cmdline = argv[2]; printf("cmd_%s := %s\n\n", target, cmdline); From patchwork Wed Aug 15 14:27:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10566657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B8ECA1390 for ; Wed, 15 Aug 2018 14:28:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8F1929D86 for ; Wed, 15 Aug 2018 14:28:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D86729D89; Wed, 15 Aug 2018 14:28:17 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 4484529D86 for ; Wed, 15 Aug 2018 14:28:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729433AbeHORU2 (ORCPT ); Wed, 15 Aug 2018 13:20:28 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:45045 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729388AbeHORU2 (ORCPT ); Wed, 15 Aug 2018 13:20:28 -0400 Received: by mail-lj1-f193.google.com with SMTP id q127-v6so1089020ljq.11 for ; Wed, 15 Aug 2018 07:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6OYwUrioNl0zu7PVa/7o6YFOoh5jN7+LZqEy07jO1sw=; b=RoHdLxuWjTk/rNqR20+kqFPqE+YmvChPEWvIfIoh0xsfbFvs0Cv53/HL4B99ASpYXB lfRVRlTEiiE/jOPdWVRhNxer02ttnJnejDr9qRS5oZrFdZCKOJfqPnl7NRYu6ALgO1jI snbagIsjAJrr6/i2pDRkk3PPpcyPJH953OVMQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6OYwUrioNl0zu7PVa/7o6YFOoh5jN7+LZqEy07jO1sw=; b=ECUaV0DwUZOtolr74WWxIbaLqvzI+UnRqYJG1+VySjg5TJJMzDlRwA6TtWCkPfu7Yr OiuvZDp80IW8cTLYAON7R0jim3A2BYAc3p4ArHThOWhN9IOe3fM8jztlnFQ5jCBjs3Er hPV+B4JBmmOpcXAxTuMIGAH8NQIyAmbgsu8/5M0y1oZpXd06qQJhcS7katFEy+R9Z8Hq MDs2ALb5nD7tXaClG9jFmmOTnMO0A08rlZlwX2GpBvzgRWfVF5+Rb8ZC990N2I6hPR9o cYJtIHiW+ETG2kGh9bhM6g/USRdB4lmatsz8PHiWEZ+K7S6jXdFqMle2I0mN9F3DV999 zjFA== X-Gm-Message-State: AOUpUlGMCsQJrZMV0IeTGCpy1RCBRjxv8G1651j5mjLOTuIhrSsoCqF6 f//GpifKYQad6lope+j+7WXdsw== X-Google-Smtp-Source: AA+uWPwx9eqaLRvtean9XmwcRN3Qu7MNpL+hO5JjbqGcHvMwd+Q9c4kWVsz1iPSLQM+FS0wWQVgxfA== X-Received: by 2002:a2e:9941:: with SMTP id r1-v6mr17648692ljj.53.1534343284381; Wed, 15 Aug 2018 07:28:04 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id l3-v6sm4559597lfi.36.2018.08.15.07.28.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Aug 2018 07:28:04 -0700 (PDT) From: Rasmus Villemoes To: Masahiro Yamada , Michal Marek Cc: linux-kbuild@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] Kbuild: teach fixdep to optionally remove the depfile Date: Wed, 15 Aug 2018 16:27:48 +0200 Message-Id: <20180815142749.18804-3-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180815142749.18804-1-linux@rasmusvillemoes.dk> References: <20180815142749.18804-1-linux@rasmusvillemoes.dk> 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 Instead of having to spawn an 'rm' instance to remove the depfile after processing, let the fixdep program itself do that. For debugging, it's nice to not do it unconditionally. Note that the fixdep calls from Makefiles are done under 'set -e', so this also preserves the behaviour of keeping the depfile if fixdep exits prematurely. Signed-off-by: Rasmus Villemoes --- scripts/Kbuild.include | 7 +++---- scripts/basic/fixdep.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index d52db4279aa5..a944510acd9d 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -274,8 +274,8 @@ ifndef CONFIG_TRIM_UNUSED_KSYMS cmd_and_fixdep = \ $(echo-cmd) $(cmd_$(1)); \ - scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\ - rm -f $(depfile); \ + scripts/basic/fixdep -r $(depfile) $@ '$(make-cmd)' \ + > $(dot-target).tmp; \ mv -f $(dot-target).tmp $(dot-target).cmd; else @@ -298,9 +298,8 @@ ksym_dep_filter = \ cmd_and_fixdep = \ $(echo-cmd) $(cmd_$(1)); \ $(ksym_dep_filter) | \ - scripts/basic/fixdep -e $(depfile) $@ '$(make-cmd)' \ + scripts/basic/fixdep -e -r $(depfile) $@ '$(make-cmd)' \ > $(dot-target).tmp; \ - rm -f $(depfile); \ mv -f $(dot-target).tmp $(dot-target).cmd; endif diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 666041841200..7b59c185858a 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -105,8 +105,9 @@ static void usage(void) { - fprintf(stderr, "Usage: fixdep [-e] \n"); + fprintf(stderr, "Usage: fixdep [-e] [-r] \n"); fprintf(stderr, " -e insert extra dependencies given on stdin\n"); + fprintf(stderr, " -r remove after processing\n"); exit(1); } @@ -380,12 +381,14 @@ int main(int argc, char *argv[]) { const char *depfile, *target, *cmdline; int insert_extra_deps = 0; + int remove_depfile = 0; void *buf; int opt; - while ((opt = getopt(argc, argv, "e")) != -1) { + while ((opt = getopt(argc, argv, "er")) != -1) { switch (opt) { case 'e': insert_extra_deps = 1; break; + case 'r': remove_depfile = 1; break; default: usage(); } } @@ -405,5 +408,8 @@ int main(int argc, char *argv[]) parse_dep_file(buf, target, insert_extra_deps); free(buf); + if (remove_depfile) + unlink(depfile); + return 0; } From patchwork Wed Aug 15 14:27:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10566655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDC4F1510 for ; Wed, 15 Aug 2018 14:28:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC0A229D86 for ; Wed, 15 Aug 2018 14:28:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF3A729D89; Wed, 15 Aug 2018 14:28:14 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 521ED29D86 for ; Wed, 15 Aug 2018 14:28:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729453AbeHORUa (ORCPT ); Wed, 15 Aug 2018 13:20:30 -0400 Received: from mail-lj1-f173.google.com ([209.85.208.173]:37471 "EHLO mail-lj1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729287AbeHORUa (ORCPT ); Wed, 15 Aug 2018 13:20:30 -0400 Received: by mail-lj1-f173.google.com with SMTP id v9-v6so1105946ljk.4 for ; Wed, 15 Aug 2018 07:28:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n7WUS0fKlMJeliJ0iVDgDM0bVFy8v2B78VhpQ00X0gc=; b=AWbi6eIEgLvZ0w5jCL0adOrFg7glp2UoH27I/PoPy7ocKBxNnJw+w6v04cdFHOSjCa GE1VIq/tOnPAKlM0DI/KieDGzl9fmwmwZEzp4L+kku9zQpi6TRSkwR7S9aZTIvIjpvTu JLP8wuwpsltDFlSPLt2K87EDPzCrHPpir53vk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n7WUS0fKlMJeliJ0iVDgDM0bVFy8v2B78VhpQ00X0gc=; b=IgXTXMjtQiRGUqUYqlC3V+E/MJg6YE2WH1iJkWuKXLlP/GjVQ24A9YU5+DGcOpXWNa w8YlDEtvcjLyEkV7y4dQXbld9C7eFd86qaqgA6tQe7Dz1GozBlclpV0ReT7+9PzUEBs0 mbNnXcBqJ1Iw2YQrxAiFQQ84y0PsU1s3qPvxg0VnC1sk5GdwN+xFhJvLySW7sW3xCuW9 tHCMSot8FM8DLFe0eGEKlqR9jCqPsnZ+i0nLYg+4/OhaZcOaBKynJfaq3PaA09MmWc/v YrqI0v/akN3gawDz5ui9Vs1i+EGxprC1s8QO6Mn7GLkbPtYUk0nMzEbXmzAcLttUqL48 lmCw== X-Gm-Message-State: AOUpUlFpgOSzYSlOS6WhrzqUiEDvyy1VKHo+m0pGw3CaDpO0fSt5Yc8Y +gYQKktJevl2xaLPyhTZNk4v3A== X-Google-Smtp-Source: AA+uWPygkwnyDvOT8lsonh346skNO2Fz32YdNbYqmp6CCZyEChwMSKd0uC0XYyE+yxTHeKE8vmQTyA== X-Received: by 2002:a2e:800e:: with SMTP id j14-v6mr15801669ljg.114.1534343285495; Wed, 15 Aug 2018 07:28:05 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id l3-v6sm4559597lfi.36.2018.08.15.07.28.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Aug 2018 07:28:05 -0700 (PDT) From: Rasmus Villemoes To: Masahiro Yamada , Michal Marek Cc: linux-kbuild@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] Kbuild: let fixdep do the renaming to .cmd Date: Wed, 15 Aug 2018 16:27:49 +0200 Message-Id: <20180815142749.18804-4-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180815142749.18804-1-linux@rasmusvillemoes.dk> References: <20180815142749.18804-1-linux@rasmusvillemoes.dk> 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 Avoid spawning one more process per TU by having fixdep open the tmpfile and rename to its final name. The only change in behaviour is that if fixdep fails, the tmpfile we leave behind is $(dot-target).cmd.tmp rather than $(dot-target).tmp . Signed-off-by: Rasmus Villemoes --- scripts/Kbuild.include | 10 ++++------ scripts/basic/fixdep.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index a944510acd9d..ded089436a3f 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -274,9 +274,8 @@ ifndef CONFIG_TRIM_UNUSED_KSYMS cmd_and_fixdep = \ $(echo-cmd) $(cmd_$(1)); \ - scripts/basic/fixdep -r $(depfile) $@ '$(make-cmd)' \ - > $(dot-target).tmp; \ - mv -f $(dot-target).tmp $(dot-target).cmd; + scripts/basic/fixdep -r -o $(dot-target).cmd \ + $(depfile) $@ '$(make-cmd)'; else @@ -298,9 +297,8 @@ ksym_dep_filter = \ cmd_and_fixdep = \ $(echo-cmd) $(cmd_$(1)); \ $(ksym_dep_filter) | \ - scripts/basic/fixdep -e -r $(depfile) $@ '$(make-cmd)' \ - > $(dot-target).tmp; \ - mv -f $(dot-target).tmp $(dot-target).cmd; + scripts/basic/fixdep -e -r -o $(dot-target).cmd \ + $(depfile) $@ '$(make-cmd)'; endif diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 7b59c185858a..78985052a3c7 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -94,6 +94,7 @@ * but I don't think the added complexity is worth it) */ +#define _GNU_SOURCE #include #include #include @@ -105,9 +106,10 @@ static void usage(void) { - fprintf(stderr, "Usage: fixdep [-e] [-r] \n"); + fprintf(stderr, "Usage: fixdep [-e] [-r] [-o ] \n"); fprintf(stderr, " -e insert extra dependencies given on stdin\n"); fprintf(stderr, " -r remove after processing\n"); + fprintf(stderr, " -o write to instead of stdout\n"); exit(1); } @@ -380,15 +382,17 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps) int main(int argc, char *argv[]) { const char *depfile, *target, *cmdline; + char *outfile = NULL, *tmpfile; int insert_extra_deps = 0; int remove_depfile = 0; void *buf; int opt; - while ((opt = getopt(argc, argv, "er")) != -1) { + while ((opt = getopt(argc, argv, "ero:")) != -1) { switch (opt) { case 'e': insert_extra_deps = 1; break; case 'r': remove_depfile = 1; break; + case 'o': outfile = optarg; break; default: usage(); } } @@ -402,12 +406,35 @@ int main(int argc, char *argv[]) target = argv[1]; cmdline = argv[2]; + if (outfile) { + if (asprintf(&tmpfile, "%s.tmp", outfile) < 0) { + perror("fixdep:asprintf"); + exit(1); + } + if (freopen(tmpfile, "w", stdout) == NULL) { + perror("fixdep:freopen"); + exit(1); + } + } + printf("cmd_%s := %s\n\n", target, cmdline); buf = read_file(depfile); parse_dep_file(buf, target, insert_extra_deps); free(buf); + if (fclose(stdout)) { + perror("fixdep:fclose"); + exit(1); + } + if (outfile) { + if (rename(tmpfile, outfile) < 0) { + perror("fixdep:rename"); + exit(1); + } + free(tmpfile); + } + if (remove_depfile) unlink(depfile);