I\'m using a makefile to compile a program made of many .c
files, and any time make
is invoked it only compiles those files modified after the last run
I would create a function which takes a command to execute and decides whether to echo it.
# 'cmd' takes two arguments:
# 1. The actual command to execute.
# 2. Optional message to print instead of echoing the command
# if executing without 'V' flag.
ifdef V
cmd = $1
else
cmd = @$(if $(value 2),echo -e "$2";)$1
endif
%.o: %.c $(h1) $(h3) %.h
$(call cmd, \
$(CC) $(CFLAGS) -c $< -o $(libDir)$@$(MATHOPTS), \
Compiling $<)
Then the result of plain make
invocation will be something like:
Compiling foo.c
Whereas make V=1
will give:
gcc -Wall -c foo.c -o foo.o ...