do cflags on stdout, not stderr
authorDavid Mitchell <davem@iabyn.com>
Wed, 4 Dec 2013 15:53:51 +0000 (15:53 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 25 Dec 2013 20:30:47 +0000 (20:30 +0000)
commitba0f5503397ddc65667224047f121adc8b44784c
treee972e39d0ab94882661a6396b31bdd6dfdc81ae1
parent44213caae04b4cd4f4a3abf272bd783994216b59
do cflags on stdout, not stderr

The current UNIX build system does a strange thing to generate the
appropriate command-line to compile a particular src file. It calls
the cflags shell script, which
1) echoes to stdout the command line needed to compile the specified
   file (excluding the name of the src file itself), e.g.
        cc -c -Dfoo -Wbar ...
2) echoes the same thing to stderr, prefixied with '   CCCMD ='

Make then does

    `sh cflags foo.o`  foo.c

the cflags output to stdout is captured by the backticks, and is used
by make as the command line to run (with the foo.c appended). This run is
silent. The output to stderr isn't captured, and gets displayed. So the
user sees:

    $ make
    `sh cflags foo.o` foo.c
       CCCMD = cc -c -Dfoo -Wbar ...
    ...

This is annoying for 2 reasons:
1) you don't get a simple command-line displayed which you could do a
simple cut and paste with (e.g. when you want to recompile a specific
source file, but alter the flags).
2) The make generates output on stderr, even when then there aren't any
errors. So "make 2>errs" can't be used to quickly spot warnings and
errors.

This commit fixes this by making cflags just output the cc command and
flags to stdout, then get Makefile to call it twice, once to echo
the command-line (on stdout), and once to execute it with backticks.
So the make output is now:

    $ make
    cc -c -Dfoo -Wbar ... foo.c
    ...

There is some stuff in Makefile.SH related to cross-compiling, which this
commit make have broken. Specifically the CCCMD and CCCMDSRC macros
have been changed in the normal case to remove backticks (and add them to
the make rules instead), but not for the cross compilation route.
The CC* defs in the cross-compilation case have a trailing -I$(CROSS_LIB)
outside of the backticks, which compilates matters.

However, in the subdir Cross/, there appears to be separate (and
divergent) copies of Makefile.SH and cflags, so maybe the files
I edited are no longer used for cross-compilation????

(followup: according to
   <20131204170112.GA2490@iabyn.com>
the cross-compiling stuff I mentioned above has bit-rotted, and I don't
need to worry about it)
Makefile.SH
cflags.SH