2020-09-05 16:11:04 +00:00
|
|
|
# $Id: install-new.mk,v 1.4 2020/08/19 17:51:53 sjg Exp $
|
2013-01-31 16:44:23 +00:00
|
|
|
#
|
|
|
|
# @(#) Copyright (c) 2009, Simon J. Gerraty
|
|
|
|
#
|
|
|
|
# This file is provided in the hope that it will
|
|
|
|
# be of use. There is absolutely NO WARRANTY.
|
|
|
|
# Permission to copy, redistribute or otherwise
|
2020-09-05 16:11:04 +00:00
|
|
|
# use this file is hereby granted provided that
|
2013-01-31 16:44:23 +00:00
|
|
|
# the above copyright notice and this notice are
|
2020-09-05 16:11:04 +00:00
|
|
|
# left intact.
|
|
|
|
#
|
2013-01-31 16:44:23 +00:00
|
|
|
# Please send copies of changes and bug-fixes to:
|
|
|
|
# sjg@crufty.net
|
|
|
|
#
|
|
|
|
|
|
|
|
.if !defined(InstallNew)
|
|
|
|
|
|
|
|
# copy if src and target are different making a backup if desired
|
|
|
|
CmpCp= CmpCp() { \
|
|
|
|
src=$$1 target=$$2 _bak=$$3; \
|
|
|
|
if ! test -s $$target || ! cmp -s $$target $$src; then \
|
|
|
|
trap "" 1 2 3 15; \
|
|
|
|
if test -s $$target; then \
|
|
|
|
if test "x$$_bak" != x; then \
|
|
|
|
rm -f $$target$$_bak; \
|
|
|
|
mv $$target $$target$$_bak; \
|
|
|
|
else \
|
|
|
|
rm -f $$target; \
|
|
|
|
fi; \
|
|
|
|
fi; \
|
|
|
|
cp $$src $$target; \
|
|
|
|
fi; }
|
|
|
|
|
|
|
|
# If the .new file is different, we want it.
|
|
|
|
# Note: this function will work as is for *.new$RANDOM"
|
|
|
|
InstallNew= ${CmpCp}; InstallNew() { \
|
|
|
|
_t=-e; _bak=; \
|
|
|
|
while :; do \
|
|
|
|
case "$$1" in \
|
|
|
|
-?) _t=$$1; shift;; \
|
|
|
|
--bak) _bak=$$2; shift 2;; \
|
|
|
|
*) break;; \
|
|
|
|
esac; \
|
|
|
|
done; \
|
|
|
|
for new in "$$@"; do \
|
|
|
|
if test $$_t $$new; then \
|
|
|
|
target=`expr $$new : '\(.*\).new'`; \
|
|
|
|
CmpCp $$new $$target $$_bak; \
|
|
|
|
fi; \
|
|
|
|
rm -f $$new; \
|
|
|
|
done; :; }
|
|
|
|
|
|
|
|
.endif
|