build.mk 3.45 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
ifeq (,$(MKIMAGE_PROFILES))
10
$(error this makefile is designed to be included in toplevel one)
11
endif
12

13
# try not to bog down the system, both CPU and I/O wise
14
ifneq (,$(NICE))
15 16 17
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
# e2k* builds always run natively, and without setarch
25 26 27 28 29 30 31
ifneq (,$(findstring e2k,$(ARCH)))
USE_QEMU := 0
else
USE_QEMU ?= 1
endif

ifeq ($(USE_QEMU),1)
32

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

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
46
export GLOBAL_HSH_USE_QEMU=$(EARCH)
47 48
endif
else
49
START += $(ARCH)
50
endif
51
endif
52

53

54
# to be passed into distcfg.mk; suggestions are welcome
55
ifneq (,$(filter-out $(DIRECT_TARGETS),$(MAKECMDGOALS)))
56 57 58 59 60 61 62 63
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; \
)
64
endif
65

66
LOGDIR ?= $(wildcard $(IMAGEDIR))
67 68 69

make-aptbox: ; @:
ifneq (0,$(CHECK))
70
	@mkdir -p $(BUILDDIR)/.work/pkgbox; \
71 72
	mkdir -p $(BUILDDIR)/.work/.cache; \
	mkdir -p $(BUILDDIR)/.work/.out; \
73 74
	APTCONF=$(wildcard $(APTCONF)); \
	mkaptbox --without-stuff --target=$(ARCH) $${APTCONF:+--apt-config=$$APTCONF} -- $(BUILDDIR)/.work/pkgbox
75
endif
Mikhail Efremov's avatar
Mikhail Efremov committed
76

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