From 390f4f6bc8fd474d64db4c4f295fb8c0bb60edac Mon Sep 17 00:00:00 2001
From: Michael Shigorin <mike@altlinux.org>
Date: Mon, 5 Dec 2011 19:13:33 +0200
Subject: [PATCH] lib/build.mk: add basic CHECK support

The idea is to check:
- the reachability of every target
  used to build the image in question;
- the availability of all the package lists
  and subsequently packages for that image;
- the lack of "dangling" intermediate targets,
  features, pkglists, hooks etc.

So far only the first step is implemented --
it's easy and somewhat helpful already for
  make CHECK=1 all
---
 doc/variables.txt |  5 +++++
 lib/build.mk      | 16 ++++++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/doc/variables.txt b/doc/variables.txt
index 8096cc1d..7d4cb575 100644
--- a/doc/variables.txt
+++ b/doc/variables.txt
@@ -22,6 +22,11 @@
   + значение: пусто (по умолчанию авто) либо строка
   + см. ../lib/profile.mk
 
+- CHECK
+  + включает режим проверки сборки конфигурации
+  + значение: пусто (по умолчанию) либо любая строка
+  + см. ../lib/build.mk
+
 - CLEAN
   + экономия RAM+swap при сборке в tmpfs, иначе места на диске
   + очистка рабочего каталога после успешной сборки очередной стадии
diff --git a/lib/build.mk b/lib/build.mk
index 12c54aa3..d5be01a8 100644
--- a/lib/build.mk
+++ b/lib/build.mk
@@ -29,8 +29,12 @@ IMAGEDIR ?= $(shell [ -d "$$HOME/out" -a -w "$$HOME/out" ] \
 
 # poehali
 build: profile/populate
-	@echo -n "$(TIME) starting image build"
-	@if [ -n "$(DEBUG)" ]; then \
+	@if [ -n "$(CHECK)" ]; then \
+		echo "$(TIME) skipping actual image build (CHECK is set)"; \
+		exit; \
+	fi; \
+	echo -n "$(TIME) starting image build"; \
+	if [ -n "$(DEBUG)" ]; then \
 		echo ": tail -f $(BUILDLOG)" $(SHORTEN); \
 	else \
 		if [ -n "$(ALL)" ]; then \
@@ -38,8 +42,8 @@ build: profile/populate
 		else \
 			echo " (coffee time)"; \
 		fi; \
-	fi
-	@if $(START) $(MAKE) -C $(BUILDDIR)/ $(LOG); then \
+	fi; \
+	if $(START) $(MAKE) -C $(BUILDDIR)/ $(LOG); then \
 		echo "$(TIME) done (`tail -1 $(BUILDLOG) | cut -f1 -d.`)"; \
 		tail -200 "$(BUILDLOG)" \
 		| GREP_COLOR="$(ANSI_OK)" \
@@ -54,5 +58,5 @@ build: profile/populate
 		  egrep --color=always "^(E:|[Ee]rror|[Ww]arning).*"; \
 		df -P $(BUILDDIR) | awk 'END { if ($$4 < $(LOWSPACE)) \
 			{ print "NB: low space on "$$6" ("$$5" used)"}}'; \
-	fi
-	@if [ -n "$(BELL)" ]; then echo -ne '\a' >&2; fi
+	fi; \
+	if [ -n "$(BELL)" ]; then echo -ne '\a' >&2; fi