2011-05-11 23:40:47 +04:00
# this makefile can be used standalone
# drop stock predefined rules
.DEFAULT :
2011-12-31 23:09:59 +04:00
SYMLINK = build
2011-08-16 00:30:20 +04:00
# tmpfs-sparing extra rule: cleanup workdir after completing each stage
# (as packed results are saved this only lowers RAM pressure)
2011-11-07 14:28:09 +04:00
# NB: it's useful enough to be enabled by default in DEBUG abscence
i f n d e f D E B U G
CLEAN ?= 1
e n d i f
2011-08-16 00:30:20 +04:00
i f d e f C L E A N
export GLOBAL_CLEAN_WORKDIR = clean-current
i f d e f D E B U G
2011-11-04 15:26:31 +04:00
WARNING = ( NB: DEBUG scope is limited when CLEAN is enabled)
2011-08-16 00:30:20 +04:00
e n d i f
e n d i f
# ordinary clean: destroys workdirs but not the corresponding results
2012-03-19 15:42:10 +04:00
# NB: our output MUST go into stderr to escape POSTPROC
2010-08-28 20:28:42 +04:00
clean :
2012-03-19 15:42:10 +04:00
@{ \
find -name '*~' -delete >& /dev/null || :; \
if [ -L " $( SYMLINK) " -a -d " $( SYMLINK) " / ] ; then \
2011-12-31 23:09:59 +04:00
echo " $( TIME) cleaning up $( WARNING) " ; \
$( MAKE) -C " $( SYMLINK) " $@ \
GLOBAL_BUILDDIR = " $( realpath $( SYMLINK) ) " $( LOG) || :; \
2012-03-19 15:42:10 +04:00
fi ; \
} >& 2
2010-08-28 20:28:42 +04:00
2011-05-11 23:40:47 +04:00
# there can be some sense in writing log here even if normally
# $(BUILDDIR)/ gets purged: make might have failed,
# and BUILDLOG can be specified by hand either
2010-08-28 20:28:42 +04:00
distclean : clean
2012-03-19 15:42:10 +04:00
@{ \
if [ -L " $( SYMLINK) " -a -d " $( SYMLINK) " / ] ; then \
2011-12-31 23:09:59 +04:00
build = " $( realpath $( SYMLINK) /) " ; \
if [ " $$ build " = / ] ; then \
echo "** ERROR: invalid \`" $( SYMLINK) "' symlink" >& 2; \
exit 128; \
else \
$( MAKE) -C " $( SYMLINK) " $@ \
GLOBAL_BUILDDIR = " $$ build " $( LOG) || : \
rm -rf " $$ build " ; \
fi ; \
2012-03-19 15:42:10 +04:00
fi ; \
rm -f " $( SYMLINK) " ; \
} >& 2
2011-12-30 14:46:58 +04:00
# builddir existing outside read-only metaprofile is less ephemeral
# than BUILDDIR is -- usually it's unneeded afterwards so just zap it
postclean : build -image
2012-03-19 15:42:10 +04:00
@{ \
2012-05-12 17:22:15 +04:00
if [ " $( NUM_TARGETS) " -gt 1 -a -z " $( DEBUG) " -a -z " $( __frontend) " ] || \
2011-12-30 14:46:58 +04:00
[ ! -L " $( SYMLINK) " -a " 0 $( DEBUG) " -lt 2 ] ; then \
echo " $( TIME) cleaning up after build " ; \
$( MAKE) -C " $( BUILDDIR) " distclean \
GLOBAL_BUILDDIR = " $( BUILDDIR) " $( LOG) || :; \
rm -rf " $( BUILDDIR) " ; \
2012-03-19 15:42:10 +04:00
fi ; \
} >& 2