diff --git a/Makefile b/Makefile index fa192ad5..700565b0 100644 --- a/Makefile +++ b/Makefile @@ -30,9 +30,13 @@ $(DIRECT_TARGETS): export NUM_TARGETS := $(words $(MAKECMDGOALS)) +# for pipefail +SHELL = /bin/bash + # real targets need real work %: @n=1; \ + set -o pipefail; \ say() { echo "$$@" >&2; }; \ if [ "$(NUM_TARGETS)" -gt 1 ]; then \ n="`echo $(MAKECMDGOALS) \ diff --git a/lib/build.mk b/lib/build.mk index c2272ac5..90dba160 100644 --- a/lib/build.mk +++ b/lib/build.mk @@ -2,7 +2,8 @@ ANSI_OK ?= 1;32 ANSI_FAIL ?= 1;31 -GOTCHA := ^(((\*\* )?(E:|[Ee]rror|[Ww]arning).*)|(.* (Stop|failed)\.))$$ +MAX_ERRORS = 3 +GOTCHA := ^(((\*\* )?(E:|[Ee]rror|[Ww]arning).*)|(.* (conflicts|Depends:) .*)|(.* (Stop|failed)\.))$$ ifndef MKIMAGE_PROFILES $(error this makefile is designed to be included in toplevel one) @@ -51,7 +52,9 @@ build-image: profile/populate tail -200 "$(BUILDLOG)" $(SHORTEN) \ | GREP_COLOR="$(ANSI_OK)" GREP_OPTIONS="--color=auto" \ grep '^\*\* image: .*$$' ||:; \ + RETVAL=0; \ else \ + RETVAL=$$?; \ echo -n "$(TIME) failed, see log"; \ if [ -z "$(DEBUG)" ]; then \ echo ": $(BUILDLOG)" $(SHORTEN); \ @@ -61,9 +64,10 @@ build-image: profile/populate fi; \ tail -200 "$(BUILDLOG)" \ | GREP_COLOR="$(ANSI_FAIL)" GREP_OPTIONS="--color=auto" \ - egrep "$(GOTCHA)"; \ + egrep -m "$(MAX_ERRORS)" "$(GOTCHA)"; \ df -P $(BUILDDIR) | awk 'END { if ($$4 < $(LOWSPACE)) \ { print "NB: low space on "$$6" ("$$5" used)"}}'; \ fi; \ if [ -n "$(BELL)" ]; then echo -ne '\a'; fi; \ + exit $$RETVAL; \ } >&2 diff --git a/reports.mk b/reports.mk index 7e7709e1..a17a659e 100644 --- a/reports.mk +++ b/reports.mk @@ -24,25 +24,31 @@ reports/prep: @mkdir -p "$(REPORTDIR)" reports/scripts: reports/prep - @grep "^mki.*scripts: Run: " $(BUILDLOG) \ - | sed -rn "s,^.*($(BUILDDIR)|$(SYMLINK))/(.*)'$$,\2,p" \ - > "$(REPORTDIR)/$*.log" \ - && echo "** scripts report: $(REPORTDIR)/$(@F).log" $(SHORTEN) + @OUT="$(REPORTDIR)/$(@F).log"; \ + grep "^mki.*scripts: Run: " $(BUILDLOG) \ + | sed -rn "s,^.*($(BUILDDIR)|$(SYMLINK))/(.*)'$$,\2,p" > "$$OUT" \ + && if [ -s "$$OUT" ]; then \ + echo "** scripts report: $$OUT" $(SHORTEN); \ + fi reports/targets: reports/prep @if ! [ -n "$(REPORT_PATH)" -a -s "$(REPORT_PATH)" ]; then \ exit 0; \ fi; \ if type -t dot >&/dev/null; then \ - REPORT_IMAGE="$(REPORTDIR)/$(@F).png"; \ + OUT="$(REPORTDIR)/$(@F).png"; \ report-targets < "$(REPORT_PATH)" \ - | dot -Tpng -o "$$REPORT_IMAGE" \ - && echo "** target graph report: $$REPORT_IMAGE"; \ + | dot -Tpng -o "$$OUT" \ + && if [ -s "$$OUT" ]; then \ + echo "** target graph report: $$OUT"; \ + fi; \ else \ - REPORT_DOT="$(BUILDDIR)/targets.dot"; \ - report-targets < "$(REPORT_PATH)" > "$$REPORT_DOT" \ - && echo "** graphviz missing, " \ - "target graph dot file: $$REPORT_DOT"; \ + OUT="$(BUILDDIR)/targets.dot"; \ + report-targets < "$(REPORT_PATH)" > "$$OUT" \ + && if [ -s "$$OUT" ]; then \ + echo "** graphviz missing, " \ + "target graph dot file: $$OUT"; \ + fi; \ fi $(SHORTEN); \ mv "$(REPORT_PATH)" "$(REPORTDIR)/$(@F).log"