Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do you do to make compiler lines shorter?

Often when I'm working on a project with others, the amount of library paths and include paths that get sourced by the compiler in the Makefile get more numerous as time goes by. Also the paths can get very long as well.

Here's an example:

g++ -c -pipe -O2 -Wall -W -DQT_BOOTSTRAPPED -DQT_MOC -DQT_NO_CODECS
-DQT_LITE_UNICODE -DQT_NO_LIBRARY -DQT_NO_STL -DQT_NO_COMPRESS
-DQT_NO_DATASTREAM -DQT_NO_TEXTSTREAM -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES
-DQT_NO_THREAD -DQT_NO_REGEXP -DQT_NO_QOBJECT -DQT_NO_SYSTEMLOCALE
-DQT_NO_GEOM_VARIANT -DQT_NO_USING_NAMESPACE -D_LARGEFILE64_SOURCE
-D_LARGEFILE_SOURCE -I../../../mkspecs/qws/linux-generic-g++ -I.
-I../../corelib/arch/generic -I../../../include -I. -I../../../include/QtCore
-I. -I.uic/release-shared -o release-shared/moc.o moc.cpp

I'm wondering what kind of recipes you use to make compiler lines much shorter, while still giving the user the option to display the raw lines if they really need that information later.

Are there tools that do this automatically?

like image 925
Neil Avatar asked May 20 '09 20:05

Neil


2 Answers

Not only can you make your compiler output shorter, you can colorcode it, and add a verbose flag. The output will look something like this:

alt text http://img526.imageshack.us/img526/9572/sconsf.png

Here's how (color theme stolen from the SCons Wiki):

import os,sys
colors = {}
colors['cyan']   = '\033[96m'
colors['purple'] = '\033[95m'
colors['blue']   = '\033[94m'
colors['green']  = '\033[92m'
colors['yellow'] = '\033[93m'
colors['red']    = '\033[91m'
colors['end']    = '\033[0m'

#If the output is not a terminal, remove the colors
if not sys.stdout.isatty():
   for key, value in colors.iteritems():
      colors[key] = ''

compile_source_message = '%s\nCompiling %s==> %s$SOURCE%s' % \
   (colors['blue'], colors['purple'], colors['yellow'], colors['end'])

compile_shared_source_message = '%s\nCompiling shared %s==> %s$SOURCE%s' % \
   (colors['blue'], colors['purple'], colors['yellow'], colors['end'])

link_program_message = '%s\nLinking Program %s==> %s$TARGET%s' % \
   (colors['red'], colors['purple'], colors['yellow'], colors['end'])

link_library_message = '%s\nLinking Static Library %s==> %s$TARGET%s' % \
   (colors['red'], colors['purple'], colors['yellow'], colors['end'])

ranlib_library_message = '%s\nRanlib Library %s==> %s$TARGET%s' % \
   (colors['red'], colors['purple'], colors['yellow'], colors['end'])

link_shared_library_message = '%s\nLinking Shared Library %s==> %s$TARGET%s' % \
   (colors['red'], colors['purple'], colors['yellow'], colors['end'])

java_compile_source_message = '%s\nCompiling %s==> %s$SOURCE%s' % \
   (colors['blue'], colors['purple'], colors['yellow'], colors['end'])

java_library_message = '%s\nCreating Java Archive %s==> %s$TARGET%s' % \
   (colors['red'], colors['purple'], colors['yellow'], colors['end'])

env = Environment()
AddOption("--verbose",action="store_true", dest="verbose_flag",default=False,help="verbose output")
if not GetOption("verbose_flag"):
  env["CXXCOMSTR"] = compile_source_message,
  env["CCCOMSTR"] = compile_source_message,
  env["SHCCCOMSTR"] = compile_shared_source_message,
  env["SHCXXCOMSTR"] = compile_shared_source_message,
  env["ARCOMSTR"] = link_library_message,
  env["RANLIBCOMSTR"] = ranlib_library_message,
  env["SHLINKCOMSTR"] = link_shared_library_message,
  env["LINKCOMSTR"] = link_program_message,
  env["JARCOMSTR"] = java_library_message,
  env["JAVACCOMSTR"] = java_compile_source_message,

Compile with "scons --verbose" to see the normal bulky gcc output.

like image 190
Imran.Fanaswala Avatar answered Sep 28 '22 04:09

Imran.Fanaswala


If it's mostly the spewing of huge lines during 'make' that causes the annoyance, you can also change your Makefile to not echo the compiler line, but to instead have something like:

     .cpp.o:
          @echo $(CC) $<
          @$(CC) $(FLAGS) -c -o $@ $<

The '@' suppresses the echo of the command line

like image 30
jesup Avatar answered Sep 28 '22 04:09

jesup