pretty print makefiles

2019-03-09 10:26发布

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?

2条回答
趁早两清
2楼-- · 2019-03-09 11:04

You can prepend @ to calls in the makefile targets.

E.g.:

%.o: %.c
    @$(CC) $(CFLAGS) -c -o $@ $<
    @echo "CC $<"
查看更多
▲ chillily
3楼-- · 2019-03-09 11:23

For a much more complicated makefile, you could use a Python script to capture the output in realtime and process it however you like, and then print them in realtime: example.

查看更多
登录 后发表回答