-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathMakefile.common
More file actions
44 lines (41 loc) · 1.44 KB
/
Makefile.common
File metadata and controls
44 lines (41 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
SHELL:=$(shell which bash)
# A helper to generate pretty logs, callable as:
# $(call run-with-log,CMD,TXT,STEM)
#
# Arguments:
# CMD: command to execute (may contain double quotes, but not escaped)
# TXT: readable text to print out once the command terminates
# STEM: path stem for the logs, stdout will be in STEM.output, stderr in STEM.err, CMD in STEM.cmd
ifeq (,$(NOSHORTLOG))
ifeq ($(shell uname -s),Darwin)
ifeq (,$(shell which gtime))
$(error gtime not found; try brew install gnu-time)
endif
TIME := gtime -q -f '%E'
else ifeq ($(shell uname -s),FreeBSD)
TIME := /usr/bin/time
else
ifeq ($(shell which time),)
$(error 'time' not found, try apt-get install time)
endif
TIME := $(shell which time) -q -f '%E'
endif
run-with-log = \
@echo "$(subst ",\",$1)" > $3.cmd; \
$(TIME) -o $3.time sh -c "$(subst ",\",$1)" > $3.output 2> >( tee $3.err 1>&2 ); \
ret=$$?; \
time=$$(cat $3.time); \
if [ $$ret -eq 0 ]; then \
echo "$2, $$time"; \
else \
echo "<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>"; \
echo -e "\033[31mFatal error while running\033[0m: $1"; \
echo -e "\033[31mFailed after\033[0m: $$time"; \
echo -e "\033[36mFull log is in $3.{output,err}, see excerpt below\033[0m:"; \
tail -n 20 $3.err; \
echo "<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>"; \
false; \
fi
else
run-with-log = $(WRAP) $(RUNLIM) $1
endif