4
votes

I am writing a web server, mainly for practice, and decided to get to learn about make and makefiles. My aim is to automate builds to my vps, using Clang/LLVM to build the software, and save the diagnostics to a text file, for a script to submit to my email address. What I can not seem to achieve is to save the diagnostics to my file.

While my Clang builds successfuly, and generates the diagnostics, and my makefile seems to work, I have failed to redirect the diagnostics, both from inside the makefile, and the command line.

My makefile (working correctly, but slightly modified to accomodate the need to save results):

# Makefile to build Ironman HTTP Server
# We will use the clang frontend from the llvm compiler infrastructure
# for building

# --- targets
Ironman : 
        clang -o Ironman src/Ironman.c > report

# --- remove binary and executable files
clean:
        rm -f Ironman
        rm -f report

I suspect that ( I may be terribly wrong here) this happens because clang doesn't really return the diagnostics, it just prints them. I do not know if this is the case, and the Clang user guide doesn't suggest anything like that.

[EDIT]: I played with Clang a bit and saw that on a successful compilation it returns 0. The method that I tested it with is:

$ clang <source_file.c>
$ echo $?
0

This suggests that my theory may be correct, which complicates things :-\

Could somebody point me in the right direction?

1

1 Answers

6
votes

Clang, like any other program, outputs diagnostics to stderr. You can redirect stderr to stdout like so:

Ironman : 
    clang -o Ironman src/Ironman.c > report 2>&1