views:

289

answers:

4

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?

+3  A: 

How about using environment variables?

export LONGPATH=/usr/local/projects/include/foo/system/v1
gcc foo.c -o foo -I$LONGPATH

For more complex scenarios, one can use wrappers to invoke the compiler, so that the actual commands and their parameters only show up on errors or warnings. Using cmake for example, much of the conventional output is already downstripped heavily.

Similarly, there's the possibility to use spec files with gcc.

none
+1 for specfiles
Thomas L Holaday
Any real-world examples of using the spec files?
florin
+1  A: 

In scons, I insert newlines into my command generators to make long commands more readable:

e.g.

tool \
    -opt1 bar1 \
    -opt2 bar2 \
    -opt3 bar3 \
    -opt4 bar4

then I create a local method when constructing the command string to reduce the clutter.

cmds = []
def l(line,indent=1):
    cmds.append(indent*'    '+line)
l('tool',0)
l('-opt1 bar1')
l('-opt2 bar2')
l('-opt3 bar3')
l('-opt4 bar4')

return '\\\n'.join(cmds)
Ross Rogers
+3  A: 

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

jesup
+4  A: 
imran.fanaswala