From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29176 invoked by alias); 4 Apr 2010 07:06:44 -0000 Received: (qmail 29052 invoked by uid 22791); 4 Apr 2010 07:06:42 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail.gmx.net (HELO mail.gmx.net) (213.165.64.20) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Sun, 04 Apr 2010 07:06:37 +0000 Received: (qmail invoked by alias); 04 Apr 2010 07:06:34 -0000 Received: from xdsl-89-0-132-162.netcologne.de (EHLO localhost.localdomain) [89.0.132.162] by mail.gmx.net (mp037) with SMTP; 04 Apr 2010 09:06:34 +0200 Received: from ralf by localhost.localdomain with local (Exim 4.69) (envelope-from ) id 1NyJuj-0007bT-Rz; Sun, 04 Apr 2010 09:06:33 +0200 Date: Sun, 04 Apr 2010 07:06:00 -0000 From: Ralf Wildenhues To: gcc@gcc.gnu.org, libtool@gnu.org Subject: how to "parse" gcc -v output Message-ID: <20100404070633.GA29215@gmx.de> Mail-Followup-To: gcc@gcc.gnu.org, libtool@gnu.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-10-28) X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2010-04/txt/msg00049.txt.bz2 Hello gcc and libtool lists, Both Autoconf and Libtool have macros which "parse" output of 'gcc -v' for some link commands. Yes, I know, almost by definition this is not "parseable" text, but GCC does not provide a stable API that allows to find out - which libraries it needs to link shared modules against, or - which libraries are needed to let g++ link mixed C++/Fortran code, so in practice there is no other choice (unless the user provides this information). In some situations, esp. when -flto is used, -v output consists of many parts. Libtool needs to know which parts it can drop, or needs to look at. Can we be fairly confident that, iff there is a line matching '^ [^ ].*collect' it will pick the one line that contains the verbose driver invocation that lets us pick up init/fini objects as well as compiler libs to link against? I.e., can we assume the leading space to be stable, and the 'collect2' name to be fairly stable across GCC versions and systems? It seems to work with all versions starting from 2.95 on those systems where collect2 is used (the 2.7.2.3 I can still find here matches '^ [^ ].*ld '). If we don't find such a line, then picking the first line with a single leading space seems prudent. That would e.g. match linking with ld on FreeBSD. If not, can you suggest a different approach? Should we be using -### instead? Looking for the first line with leading space and containing ' -L' (I think Alexandre Oliva suggested that a while ago)? I'm willing to add API to a future GCC if that's the only viable way (that way at least we have a fixed set of past and present versions to match). Thanks, Ralf