Rohan G Rohan G - 3 months ago 20
Bash Question

Build time for makefile recipe

I want to caluclate time spent for each recipe in makefile

SYS_TIME = $(shell date)
SUBDIRS = a b c d

.PHONY = default

default:
for dir in $(SUBDIRS); \
do \
$(eval ST = $(SYS_TIME)) \
$(MAKE) -C FOLD=$$dir; \
$(eval ET = $(SYS_TIME))
echo "time spent = $(ST) - $(ET) "
done; \


result should look like:


time spent = 1:35

time spent = 2:23

time spent = 10:59

time spent = 5:35


it signify 1 minute 35 sec for first and same for others

Answer

Just prefix your command lines with time, e.g.: time $(MAKE) -C $$dir.