Commit 3d2f69f1 authored by Michael Shigorin's avatar Michael Shigorin

lib/{clean,profile}.mk: robustness improvements

First, let's not do rsync --delete on an unverified target dir again: the lesson was learned during a subway hacking session and I must say that SSDs are frightening fast (even if it was more than a second to realize what happens and terminate the extermination before it got /home, thanks xterm). Second, let's use a variable for common name and make's own realpath function instead of external binary.
parent abfd88e2
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
# drop stock predefined rules # drop stock predefined rules
.DEFAULT: .DEFAULT:
SYMLINK = build
# tmpfs-sparing extra rule: cleanup workdir after completing each stage # tmpfs-sparing extra rule: cleanup workdir after completing each stage
# (as packed results are saved this only lowers RAM pressure) # (as packed results are saved this only lowers RAM pressure)
# NB: it's useful enough to be enabled by default in DEBUG abscence # NB: it's useful enough to be enabled by default in DEBUG abscence
...@@ -18,22 +20,26 @@ endif ...@@ -18,22 +20,26 @@ endif
# ordinary clean: destroys workdirs but not the corresponding results # ordinary clean: destroys workdirs but not the corresponding results
clean: clean:
@echo "$(TIME) cleaning up $(WARNING)"
@find -name '*~' -delete >&/dev/null ||: @find -name '*~' -delete >&/dev/null ||:
@if [ -L build -a -d build/ ]; then \ @if [ -L "$(SYMLINK)" -a -d "$(SYMLINK)"/ ]; then \
$(MAKE) -C build $@ \ echo "$(TIME) cleaning up $(WARNING)"; \
GLOBAL_BUILDDIR=$(shell readlink build) $(LOG) ||:; \ $(MAKE) -C "$(SYMLINK)" $@ \
GLOBAL_BUILDDIR="$(realpath $(SYMLINK))" $(LOG) ||:; \
fi fi
# there can be some sense in writing log here even if normally # there can be some sense in writing log here even if normally
# $(BUILDDIR)/ gets purged: make might have failed, # $(BUILDDIR)/ gets purged: make might have failed,
# and BUILDLOG can be specified by hand either # and BUILDLOG can be specified by hand either
distclean: clean distclean: clean
@if [ -L build -a -d build/ ]; then \ @if [ -L "$(SYMLINK)" -a -d "$(SYMLINK)"/ ]; then \
rm -rf build/.git; \ build="$(realpath $(SYMLINK)/)"; \
$(MAKE) -C build $@ \ if [ "$$build" = / ]; then \
GLOBAL_BUILDDIR=$(shell readlink build) $(LOG) || \ echo "** ERROR: invalid \`"$(SYMLINK)"' symlink" >&2; \
rm -rf build/; \ exit 128; \
rm -rf $(shell readlink build); \ else \
$(MAKE) -C "$(SYMLINK)" $@ \
GLOBAL_BUILDDIR="$$build" $(LOG) ||: \
rm -rf "$$build"; \
fi; \
fi fi
@rm -f build ||: @rm -f "$(SYMLINK)"
...@@ -35,8 +35,12 @@ SHORTEN = $(shell \ ...@@ -35,8 +35,12 @@ SHORTEN = $(shell \
# step 1: initialize the off-tree mkimage profile (BUILDDIR) # step 1: initialize the off-tree mkimage profile (BUILDDIR)
profile/init: distclean profile/init: distclean
@if [ "`realpath "$(BUILDDIR)/"`" = / ]; then \
echo "$(TIME) ERROR: invalid BUILDDIR: \`$(BUILDDIR)'"; \
exit 128; \
fi;
@echo -n "$(TIME) initializing BUILDDIR: " @echo -n "$(TIME) initializing BUILDDIR: "
@rsync -qaH --delete image.in/ "$(BUILDDIR)"/ @rsync -qaxH --delete-after image.in/ "$(BUILDDIR)"/
@mkdir "$(BUILDDIR)"/.mki # mkimage toplevel marker @mkdir "$(BUILDDIR)"/.mki # mkimage toplevel marker
@$(call put,ifndef DISTCFG_MK) @$(call put,ifndef DISTCFG_MK)
@$(call put,DISTCFG_MK = 1) @$(call put,DISTCFG_MK = 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment