2011-10-06 12:46:31 +04:00
# step 4 is kicked off here but actually done by image.in/Makefile
2011-11-21 14:08:33 +04:00
ANSI_OK ?= 1; 32
ANSI_FAIL ?= 1; 31
2011-10-06 12:46:31 +04:00
2015-04-02 20:46:48 +03:00
MAX_LINES = 200
2013-06-15 15:40:15 +04:00
MAX_ERRORS = 5
2019-02-14 20:55:58 +03:00
GOTCHA := ^( ( ( \* \* ) ?( E:| [ Ee] rror| [ Ww] arning) .*) | ( .* ( FAILURE| FATAL| ERROR| conflicts| Conflicts:| Depends:) .*) | ( .* ( Stop| failed| not found) \. ) | ( not allowed) ) $$
2012-04-10 18:48:27 +04:00
2011-10-06 12:46:31 +04:00
i f n d e f M K I M A G E _ P R O F I L E S
$( error this makefile is designed to be included in toplevel one )
2011-06-12 19:06:36 +04:00
e n d i f
2011-05-11 23:40:47 +04:00
2011-11-04 17:53:06 +04:00
# try not to bog down the system, both CPU and I/O wise
i f d e f N I C E
START := nice $( shell ionice -c3 echo "ionice -c3" 2>/dev/null)
e n d i f
2011-11-04 22:44:25 +04:00
# in kilobytes (a kilometer is 1024 meters, you know)
LOWSPACE = 1024
2011-11-04 17:53:06 +04:00
# it's also nice to know how long and much it takes
START += time -f "%E %PCPU %Mk"
2018-12-07 15:54:28 +03:00
# e2k* builds always run natively, and without setarch
i f e q ( , $( findstring e 2k ,$ ( ARCH ) ) )
2012-07-09 22:50:57 +04:00
# /usr/bin/{i586,x86_64} are setarch(8) symlinks but arm is not;
2012-11-18 02:54:37 +04:00
# armh (armv7l) doesn't have any but should cope with qemu-arm.static;
2012-07-09 22:50:57 +04:00
# also check whether non-x86 build is running native
ifeq (,$(wildcard $(subst : , /$( ARCH ) , $( PATH ) :)))
2018-12-07 15:54:28 +03:00
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) )
i f e q ( , $( findstring $ ( UARCH ) ,$ ( shell uname -m ) ) )
2012-11-18 02:54:37 +04:00
export GLOBAL_HSH_USE_QEMU = $( EARCH)
2012-07-09 22:50:57 +04:00
e n d i f
e l s e
2011-11-04 17:53:06 +04:00
START += $( ARCH)
2012-07-06 20:33:39 +04:00
e n d i f
2018-05-21 22:24:25 +03:00
e n d i f
2011-11-04 17:53:06 +04:00
2018-12-07 15:54:28 +03:00
2011-12-30 14:46:58 +04:00
# 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 ; \
)
2010-09-27 23:02:57 +04:00
2013-02-04 19:18:06 +04:00
LOGDIR ?= $( wildcard $( IMAGEDIR) )
2012-06-15 20:33:04 +04:00
2011-12-30 14:46:58 +04:00
# actual build starter
2012-03-19 15:42:10 +04:00
# NB: our output MUST go into stderr to escape POSTPROC
2011-12-30 14:46:58 +04:00
build-image : profile /populate
2012-03-19 15:42:10 +04:00
@{ \
if [ -n " $( CHECK) " ] ; then \
2011-12-05 21:13:33 +04:00
echo " $( TIME) skipping actual image build (CHECK is set) " ; \
exit; \
fi ; \
2015-04-02 20:46:48 +03:00
if [ -z " $( QUIET) " ] ; then \
echo -n " $( TIME) starting image build " ; \
if [ -n " $( DEBUG) " ] ; then \
echo " : tail -f $( BUILDLOG) " $( SHORTEN) ; \
else \
echo " (coffee time)" ; \
fi ; \
2011-12-05 21:13:33 +04:00
fi ; \
if $( START) $( MAKE) -C $( BUILDDIR) / $( LOG) ; then \
2015-04-02 20:46:48 +03:00
DURATION = " (`tail -1 $( BUILDLOG) | cut -f1 -d.`) " ; \
tail -n $( MAX_LINES) " $( BUILDLOG) " $( SHORTEN) \
| if [ -z " $( QUIET) " ] ; then \
2015-11-20 23:15:10 +03:00
echo " $( TIME) done $$ DURATION " ; \
2015-10-09 16:39:13 +03:00
GREP_COLOR = " $( ANSI_OK) " \
grep --color= auto '^\*\* image: .*$$' || :; \
2015-04-02 20:46:48 +03:00
else \
echo -n " $( TIME) $$ DURATION " ; \
sed -rn 's/^\*\* image: (.*)$$/\1/p' ; \
fi ; \
2012-04-25 17:56:48 +04:00
RETVAL = 0; \
2011-05-11 23:40:47 +04:00
else \
2012-04-25 17:56:48 +04:00
RETVAL = $$ ?; \
2011-12-30 14:46:58 +04:00
echo -n " $( TIME) failed, see log " ; \
2015-04-02 20:46:48 +03:00
if [ -z " $( DEBUG) " -o -n " $( QUIET) " ] ; then \
2011-12-30 14:46:58 +04:00
echo " : $( BUILDLOG) " $( SHORTEN) ; \
else \
echo " above" ; \
2011-05-11 23:40:47 +04:00
fi ; \
2015-04-02 20:46:48 +03:00
if [ -z " $( DEBUG) " ] ; then \
echo " $( TIME) (you might want to rerun with DEBUG=1) " ; \
fi ; \
tail -n $( MAX_LINES) " $( BUILDLOG) " \
2015-10-09 16:39:13 +03:00
| GREP_COLOR = " $( ANSI_FAIL) " \
egrep --color= auto -m " $( MAX_ERRORS) " " $( GOTCHA) " ; \
2011-11-04 22:44:25 +04:00
df -P $( BUILDDIR) | awk ' END { if ( $$ 4 < $( LOWSPACE) ) \
2011-11-04 15:26:31 +04:00
{ print "NB: low space on " $$ 6" (" $$ 5" used)" } } ' ; \
2011-12-05 21:13:33 +04:00
fi ; \
2016-09-09 09:22:07 +03:00
if [ -n " $( AUTOCLEAN) " -a $$ RETVAL = 0 ] ; then $( MAKE) distclean; fi ; \
2012-03-19 15:42:10 +04:00
if [ -n " $( BELL) " ] ; then echo -ne '\a' ; fi ; \
2012-04-25 17:56:48 +04:00
exit $$ RETVAL; \
2012-03-19 15:42:10 +04:00
} >& 2