makefilecsharmclang

How to capture both the printed screen logs and output into a log file when using `armclang` in a Makefile?


I'm trying to capture the printed screen logs into a log file when using armclang in a Makefile.

Makefile:

all: startup_armclang startup_armasm main_armclang

startup_armclang:
    armclang --target=arm-arm-none-eabi -march=armv7-r -DBL1 _DRAM_JUMP -E -x assembler-with-cpp ./startup.s > temp.s

startup_armasm:
    armasm --diag_style=gnu --brief_diagnostics -g --debug --keep --cpu=Cortex-R5 -I. -I./System -o startup.o temp.s
    rm -f temp.s

main_armclang:
    armclang -c --target=arm-arm-none-eabi -marm -march=armv7-r -mcpu=cortex-r5 -g1 --debug -O0 -fno-function-sections -fno-data-sections -mfloat-abi=soft -mfpu=none -I. -I./System Main.c -o Main.o -MMD -MF Main.d

I tried :

  1. $>make all > log

    make: Warning: File Makefile has modification time 4.1e+02 s in the future armclang: warning: Avoid specifying both the architecture (-march) and the processor (-mcpu) because specifying both has the potential to cause a conflict. The compiler infers the correct architecture from the processor. [-Wunused-command-line-argument] Main.c:605:56: warning: expression result unused [-Wunused-value] ptBootInfo->tImage.mCtrMode, ~~~~~~~~~~~~~~~~~~~~~~~~^~~~ Main.c:606:56: warning: expression result unused [-Wunused-value] ptBootInfo->tImage.mInstBuff, ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ Main.c:607:84: warning: expression result unused [-Wunused-value] ptBootInfo->tImage.mFlashAddr[CoreType][ImgType], ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ Main.c:608:37: warning: expression result unused [-Wunused-value] (UINT8 *)(ptBootInfo->tHeader[CoreType][ImgType]), ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~ Main.c:609:55: error: extraneous ')' before ';' BL_IMG_HEADER_SIZE); ^ Main.c:609:37: warning: expression result unused [-Wunused-value]

But only logged as the below log:

armclang --target=arm-arm-none-eabi -march=armv7-r -DBL1 _DRAM_JUMP -E -x assembler-with-cpp ./startup.s > ./temp.s
armasm --diag_style=gnu --brief_diagnostics -g --debug -keep --cpu=Cortex-R5 -I . -I./System -o ./startup.o temp.s
rm -f temp.s
armclang -c --target=arm-arm-none-eabi -marm -march=armv7-r -mcpu=cortex-r5 -g1 --debug -O0 --fno-function-sections --fno-data-sections -mfloat-abi=soft -mfpu=none -I . -I./System Main.c -o Main.o -MMD -MF Main.d
  1. $>make all 2>&1 | tee log But this make Error message as 'Ambiguous output redirect'.

Solution

  • I have to hand a small C project built with a GNU Makefile and I have introduced #error Whoops into one of the source files. My default shell is:

    $ echo $SHELL
    /bin/bash
    

    My sabotaged project (fails to) build like:

    $ make
    cc    -c -o bar_init.o bar_init.c
    cc    -c -o default_opt_init.o default_opt_init.c
    cc    -c -o foo_init.o foo_init.c
    cc    -c -o init.o init.c
    cc    -c -o main.o main.c
    main.c:3:2: error: #error Whoops
        3 | #error Whoops
          |  ^~~~~
    make: *** [<builtin>: main.o] Error 1
    

    I can log the standard output and standard error while still sending them to console in just the way you attempted:

    $ make 2>&1 | tee log
    cc    -c -o bar_init.o bar_init.c
    cc    -c -o default_opt_init.o default_opt_init.c
    cc    -c -o foo_init.o foo_init.c
    cc    -c -o init.o init.c
    cc    -c -o main.o main.c
    main.c:3:2: error: #error Whoops
        3 | #error Whoops
          |  ^~~~~
    make: *** [<builtin>: main.o] Error 1
    
    $ cat log
    cc    -c -o bar_init.o bar_init.c
    cc    -c -o default_opt_init.o default_opt_init.c
    cc    -c -o foo_init.o foo_init.c
    cc    -c -o init.o init.c
    cc    -c -o main.o main.c
    main.c:3:2: error: #error Whoops
        3 | #error Whoops
          |  ^~~~~
    make: *** [<builtin>: main.o] Error 1
    

    So it works in bash. You are using the csh shell. I also have the tcsh shell, which has the same redirection facilities as csh:

    $ tcsh
    > make clean
    rm -f prog *.o
    > make 2>&1 | tee log
    Ambiguous output redirect.
    > make 2 > & 1 |
    

    As you see, shell redirection syntax is not the same in [t]csh and bash.

    [t]csh redirection facilities are less convenient than those of bash. To achieve what you want in [t]csh you need to do:

    > make clean
    rm -f prog *.o
    > make |& cat | tee log
    cc    -c -o bar_init.o bar_init.c
    cc    -c -o default_opt_init.o default_opt_init.c
    cc    -c -o foo_init.o foo_init.c
    cc    -c -o init.o init.c
    cc    -c -o main.o main.c
    main.c:3:2: error: #error Whoops
        3 | #error Whoops
          |  ^~~~~
    make: *** [<builtin>: main.o] Error 1
    
    > cat log
    cc    -c -o bar_init.o bar_init.c
    cc    -c -o default_opt_init.o default_opt_init.c
    cc    -c -o foo_init.o foo_init.c
    cc    -c -o init.o init.c
    cc    -c -o main.o main.c
    main.c:3:2: error: #error Whoops
        3 | #error Whoops
          |  ^~~~~
    make: *** [<builtin>: main.o] Error 1