views:

122

answers:

1

The linux kernel (and various other projects including git) have very nice makefiles that hide the giant cc calls into nice little acronyms.

For example:

gcc -O2 -o cool.o cool.c -llib
gcc -O2 -o neat.o neat.c -llib

would become:

CC cool.c
CC neat.c

Which is really nice if you have a project with a large number of files and long compiler flags. I recall that this had to do with suppressing the default output and making a custom one. How do you do it?

+5  A: 

You can prepend @ to calls in the makefile targets.

E.g.:

%.o: %.c
    @$(CC) $(CFLAGS) -c -o $@ $<
    @echo "CC $<"
Maister
awesome! exactly what I needed!
wickedchicken
The Linux kernel Makefile's allow you to decide whether to show the compile command or not (which can be useful when debugging). They conditionally set `Q = @` and then write the command as `$(Q)$(CC) ...`. Now you can choose to set a command by setting `Q = `
R Samuel Klatchko