build.mk 3.1 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|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 25 26 27

# e2k* builds always run natively, and without setarch
ifeq (,$(findstring e2k,$(ARCH)))

28
# /usr/bin/{i586,x86_64} are setarch(8) symlinks but arm is not;
Michael Shigorin's avatar
Michael Shigorin committed
29
# armh (armv7l) doesn't have any but should cope with qemu-arm.static;
30 31
# also check whether non-x86 build is running native
ifeq (,$(wildcard $(subst :,/$(ARCH) ,$(PATH):)))
32 33 34 35 36 37 38 39 40

EARCH := $(subst armh,arm,$(ARCH))

# for mips*el, `uname -m` never has 'el' suffix, but
# qemu-user-static binaries always do.
UARCH := $(subst mipsel,mips,$(EARCH))
UARCH := $(subst mips64el,mips64,$(UARCH))

ifeq (,$(findstring $(UARCH),$(shell uname -m)))
Michael Shigorin's avatar
Michael Shigorin committed
41
export GLOBAL_HSH_USE_QEMU=$(EARCH)
42 43
endif
else
44
START += $(ARCH)
45
endif
46
endif
47

48

49 50 51 52 53 54 55 56 57
# 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; \
)
58

59
LOGDIR ?= $(wildcard $(IMAGEDIR))
Mikhail Efremov's avatar
Mikhail Efremov committed
60

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