PDA

View Full Version : Nicer compile output



Dtag
April 10th, 2009, 12:03 PM
Hi

I am often compiling programs on the console. Are there any suggestions for getting a nicer console output for the compilation process?

For example instead of:
'g++ blablaverylongline bla.cpp'
have it say something like:
'Compiling "bla.cpp"...'
or
'Linking...'

My search attempts on the web have been unsuccessful so far. I have seen something similar before though when I was compiling something from source. I believe it used cmake(?). I haven't tried the latter though because I want to stick to qmake.

I would also appreciate other suggestions to facilitate looking through compilation warnings/errors.

Thanks alot

dwhitney67
April 10th, 2009, 04:48 PM
Hi

I am often compiling programs on the console. Are there any suggestions for getting a nicer console output for the compilation process?

For example instead of:
'g++ blablaverylongline bla.cpp'
have it say something like:
'Compiling "bla.cpp"...'
or
'Linking...'

...

Usually when I build a project, my output does look like the one you describe. I, however, am using a Makefile.

A very basic Makefile could look like:


APP = appfoo
SRCS = foo.cpp
OBJS = $(SRCS:.cpp=.o)
INCLUDES =
CXXFLAGS = -Wall -ansi -pedantic
LFLAGS =
LIBS =

all: $(APP)

$(APP): $(OBJS)
@echo "Linking $@..."
@$(CXX) $^ $(LFLAGS) $(LIBS) -o $@

.cpp.o:
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $<

nvteighen
April 10th, 2009, 08:15 PM
You know: UNIX philosophy (though GNU's not Unix!)...



Rule of Silence: When a program has nothing surprising to say, it should say nothing. (http://en.wikipedia.org/wiki/Unix_philosophy)

Dtag
April 11th, 2009, 09:49 AM
Hi,

thanks for your replies. I have tried your Makefile and indeed it's pretty much what I was looking for. Unfortunately I don't want to use raw Makefiles. Any idea how to make qmake generate something like this? Or how to filter Make's output to make it look like this?

Thanks

Dtag
April 11th, 2009, 11:27 AM
Hi again

your Makefile inspired me to write a small script that postprocesses the qmake generated Makefiles:



#!/bin/sh

perl -pi -e 's/^(.*)\$\(CXX\)(.*)/$1\@echo "### Compiling \$\<..."\n$1\@\$\(CXX\)$2/g' $1
perl -pi -e 's/^(.*)\$\(LINK\)(.*)/$1\@echo "### Linking \$\@..."\n$1\@\$\(CXX\)$2/g' $1

perl -pi -e 's/^(.*)\/usr\/lib\/qt4\/bin\/moc(.*)/$1\@echo "### Qt-Moc \$\@..."\n$1\@\/usr\/lib\/qt4\/bin\/moc$2/g' $1
perl -pi -e 's/^(.*)\/usr\/lib\/qt4\/bin\/uic(.*)/$1\@echo "### Qt-Uic \$<..."\n$1\@\/usr\/lib\/qt4\/bin\/uic$2/g' $1


Its probably not particularily nice but it works - it will simply replace $(CXX) with @echo ...\n@$(CXX)...
(and analogously for $(LINK), ...). I am simply calling it after every qmake now.

Thanks again

dwhitney67
April 11th, 2009, 12:56 PM
Oh, so you are doing Qt?

Did I not mention that I have an answer for every problem? :p

Just kidding, but I do have a copy of a solution for a Qt project I supported in the past. It involves writing a wrapper-Makefile that calls the Makefile generated by qmake.

Below is a summary; basically it overrides the definitions for CXX, UIC, and LINK (and the CXXFLAGS) that are used by the Makefile that is generate by qmake, so that the compilation/linking output is suppressed and replaced with the one I define.


APPNAME = my_ui_app

...

QTDIR := /usr/local/qt
QMAKESPEC := $(QTDIR)/mkspecs/linux-g++
QMAKE := $(QTDIR)/bin/qmake
QMAKE_DEBUG :=
QCXXFLAGS := -pipe -w -O2 -DQT_NO_DEBUG -DQT_SHARED

export QTDIR QMAKESPEC QMAKE QMAKE_DEBUG QCXXFLAGS

# Define compilation and link statements so that detailed output is suppressed.
#
QCXX = @echo $(APPNAME) ui Compiling: $$<;$(CXX)
QUIC = @echo $(APPNAME) ui UICing: $$^;$(QTDIR)/bin/uic
QLINK = @echo $(APPNAME) ui Linking: UI;$(CXX)

MY_QT_DIR = qt_ui

...

$(MY_QT_DIR):
$(QMAKE) -o $@/Makefile $@/*.pro
make -C $@ CXX="$(QCXX)" UIC="$(QUIC)" LINK="$(QLINK)" CXXFLAGS="$(QCXXFLAGS)"

...


The Makefile above is incomplete, but should provide an idea. I used such a Makefile with Qt 3.2.3 application, but using two distinct versions (one made under Linux 2.4.x, another for Linux 2.6.17). Depending on the version being made, I adjusted the QTDIR.

P.S. Your solution seems easier, but since I do not know Perl, I guess that was not an option for me. Also, if you employ my way, the Makefile cannot reside within the directory where qmake will generate a Makefile.

Dtag
April 11th, 2009, 02:46 PM
Hey

ahh hehe that inspired me to create ANOTHER solution (I think this time its the ultimate solution):
You just add:



QMAKE_CC = @echo "\*\*\* Compiling $<..." && $$QMAKE_CC
QMAKE_CXX = @echo "\*\*\* Compiling $<..." && $$QMAKE_CXX
QMAKE_LINK = @echo "\*\*\* Linking $@..." && $$QMAKE_LINK
QMAKE_LINK_SHLIB = @echo "\*\*\* Linking $@..." && $$QMAKE_LINK_SHLIB


To the .pro file and the rest is done by QT :)

Thanks again