mkimage-profiles/lib/clean.mk
Michael Shigorin 2f307ffffb main.mk introduced, lib/*.mk partially rewritten
The former toplevel Makefile is now toplevel main.mk;
this change allows for multi-target, multi-arch processing
in the current toplevel Makefile.

As the "build" symlink semantics change quite considerably
when one is doing bulk builds (several pruned builddirs might
be useful for comparison), BUILDDIR is now much more likely
to be recreated: the cases when it will persist are when it's
either a single-image build or when the prefix hasn't changed.

There are some more or less subtle bugfixes and enhancements
all over the map as well.

Done within 20111230..20120102 timeframe, actually...
2012-01-02 21:01:09 +02:00

57 lines
1.7 KiB
Makefile

# this makefile can be used standalone
# drop stock predefined rules
.DEFAULT:
SYMLINK = build
# tmpfs-sparing extra rule: cleanup workdir after completing each stage
# (as packed results are saved this only lowers RAM pressure)
# NB: it's useful enough to be enabled by default in DEBUG abscence
ifndef DEBUG
CLEAN ?= 1
endif
ifdef CLEAN
export GLOBAL_CLEAN_WORKDIR = clean-current
ifdef DEBUG
WARNING = (NB: DEBUG scope is limited when CLEAN is enabled)
endif
endif
# ordinary clean: destroys workdirs but not the corresponding results
clean:
@find -name '*~' -delete >&/dev/null ||:
@if [ -L "$(SYMLINK)" -a -d "$(SYMLINK)"/ ]; then \
echo "$(TIME) cleaning up $(WARNING)"; \
$(MAKE) -C "$(SYMLINK)" $@ \
GLOBAL_BUILDDIR="$(realpath $(SYMLINK))" $(LOG) ||:; \
fi
# 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
distclean: clean
@if [ -L "$(SYMLINK)" -a -d "$(SYMLINK)"/ ]; then \
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; \
fi
@rm -f "$(SYMLINK)"
# builddir existing outside read-only metaprofile is less ephemeral
# than BUILDDIR is -- usually it's unneeded afterwards so just zap it
postclean: build-image
@if [ "$(NUM_TARGETS)" -gt 1 -a -z "$(DEBUG)" ] || \
[ ! -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)"; \
fi