build.mk 2.75 KB
Newer Older
1
# step 4 is kicked off here but actually done by image.in/Makefile
2 3
ANSI_OK   ?= 1;32
ANSI_FAIL ?= 1;31
4

5
MAX_LINES = 200
6
MAX_ERRORS = 5
7
GOTCHA := ^(((\*\* )?(E:|[Ee]rror|[Ww]arning).*)|(.* (FAILURE|FATAL|ERROR|conflicts|Depends:) .*)|(.* (Stop|failed|not found)\.)|(not allowed))$$
8

9 10
ifndef MKIMAGE_PROFILES
$(error this makefile is designed to be included in toplevel one)
11
endif
12

13 14 15 16 17
# try not to bog down the system, both CPU and I/O wise
ifdef NICE
START := nice $(shell ionice -c3 echo "ionice -c3" 2>/dev/null)
endif

18 19 20
# in kilobytes (a kilometer is 1024 meters, you know)
LOWSPACE = 1024

21 22 23
# it's also nice to know how long and much it takes
START += time -f "%E %PCPU %Mk"

24
# /usr/bin/{i586,x86_64} are setarch(8) symlinks but arm is not;
Michael Shigorin's avatar
Michael Shigorin committed
25
# armh (armv7l) doesn't have any but should cope with qemu-arm.static;
26
# also check whether non-x86 build is running native
Michael Shigorin's avatar
Michael Shigorin committed
27
EARCH := $(subst armh,arm,$(ARCH))
28
ifeq (,$(wildcard $(subst :,/$(ARCH) ,$(PATH):)))
Michael Shigorin's avatar
Michael Shigorin committed
29 30
ifeq (,$(findstring $(EARCH),$(shell uname -m)))
export GLOBAL_HSH_USE_QEMU=$(EARCH)
31 32
endif
else
33
START += $(ARCH)
34
endif
35

36 37 38 39 40 41 42 43 44
# to be passed into distcfg.mk; suggestions are welcome
IMAGEDIR ?= $(shell \
	if [ -d "$$HOME/out" -a -w "$$HOME/out" ]; then \
		echo "$$HOME/out"; \
	else \
		dir="`dirname $(BUILDDIR)`/out"; \
		mkdir -p "$$dir" && echo "$$dir" || echo "/tmp"; \
	fi; \
)
45

46
LOGDIR ?= $(wildcard $(IMAGEDIR))
Mikhail Efremov's avatar
Mikhail Efremov committed
47

48
# actual build starter
49
# NB: our output MUST go into stderr to escape POSTPROC
50
build-image: profile/populate
51 52
	@{ \
	if [ -n "$(CHECK)" ]; then \
53 54 55
		echo "$(TIME) skipping actual image build (CHECK is set)"; \
		exit; \
	fi; \
56 57 58 59 60 61 62
	if [ -z "$(QUIET)" ]; then \
		echo -n "$(TIME) starting image build"; \
		if [ -n "$(DEBUG)" ]; then \
			echo ": tail -f $(BUILDLOG)" $(SHORTEN); \
		else \
			echo " (coffee time)"; \
		fi; \
63 64
	fi; \
	if $(START) $(MAKE) -C $(BUILDDIR)/ $(LOG); then \
65 66 67
		DURATION="(`tail -1 $(BUILDLOG) | cut -f1 -d.`)"; \
		tail -n $(MAX_LINES) "$(BUILDLOG)" $(SHORTEN) \
		| if [ -z "$(QUIET)" ]; then \
68
			echo "$(TIME) done $$DURATION"; \
69 70
			GREP_COLOR="$(ANSI_OK)" \
			  grep --color=auto '^\*\* image: .*$$' ||:; \
71 72 73 74
		else \
			echo -n "$(TIME) $$DURATION "; \
			sed -rn 's/^\*\* image: (.*)$$/\1/p'; \
		fi; \
75
		RETVAL=0; \
76
	else \
77
		RETVAL=$$?; \
78
		echo -n "$(TIME) failed, see log"; \
79
		if [ -z "$(DEBUG)" -o -n "$(QUIET)" ]; then \
80 81 82
			echo ": $(BUILDLOG)" $(SHORTEN); \
		else \
			echo " above"; \
83
		fi; \
84 85 86 87
		if [ -z "$(DEBUG)" ]; then \
			echo "$(TIME) (you might want to rerun with DEBUG=1)"; \
		fi; \
		tail -n $(MAX_LINES) "$(BUILDLOG)" \
88 89
		| GREP_COLOR="$(ANSI_FAIL)" \
		  egrep --color=auto -m "$(MAX_ERRORS)" "$(GOTCHA)"; \
90
		df -P $(BUILDDIR) | awk 'END { if ($$4 < $(LOWSPACE)) \
91
			{ print "NB: low space on "$$6" ("$$5" used)"}}'; \
92
	fi; \
93
	if [ -n "$(BELL)" ]; then echo -ne '\a'; fi; \
94
	exit $$RETVAL; \
95
	} >&2