Simplify install/uninstall

This commit is contained in:
Roberto E. Vargas Caballero 2023-09-26 23:09:34 +02:00
parent 6285c22a07
commit ddde8021b3
4 changed files with 89 additions and 24 deletions

View File

@ -210,19 +210,18 @@ getconf.o: getconf.h
getconf.h:
scripts/getconf.sh > $@
install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
cd $(DESTDIR)$(PREFIX)/bin && ln -f test [ && chmod 755 $(BIN)
mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
install uninstall:
scripts/mkproto $@ $(DESTDIR)$(PREFIX) $(DESTDIR)$(MANPREFIX) proto
scripts/$@ proto
uninstall:
cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) [ install
cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN) install.1
sbase-box-install: sbase-box
scripts/mkproto $@ $(DESTDIR)$(PREFIX) $(DESTDIR)$(MANPREFIX) proto
scripts/$@ proto
$(DESTDIR)$(PREFIX)/bin/sbase-box -i $(DESTDIR)$(PREFIX)/bin/
sbase-box-uninstall: sbase-box
$(DESTDIR)$(PREFIX)/bin/sbase-box -d $(DESTDIR)$(PREFIX)/bin/
$(MAKE) uninstall
dist: clean
mkdir -p sbase-$(VERSION)
@ -235,21 +234,10 @@ sbase-box: $(BIN)
scripts/mkbox
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB)
sbase-box-install: sbase-box
mkdir -p $(DESTDIR)$(PREFIX)/bin
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
cp -f sbase-box $(DESTDIR)$(PREFIX)/bin
chmod 755 $(DESTDIR)$(PREFIX)/bin/sbase-box
$(DESTDIR)$(PREFIX)/bin/sbase-box -i $(DESTDIR)$(PREFIX)/bin/
cp -f $(MAN) $(DESTDIR)$(MANPREFIX)/man1/
mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
sbase-box-uninstall: uninstall
cd $(DESTDIR)$(PREFIX)/bin && rm -f sbase-box
clean:
rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz
rm -f getconf.h
rm -f proto
rm -rf build
.PHONY: all install uninstall dist sbase-box-install sbase-box-uninstall clean

21
scripts/install Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
set -e
while read type src dst perm
do
case $type in
d)
mkdir -p $src
;;
c)
cp $src $dst
;;
*)
echo install: wrong entry type >&2
exit 1
;;
esac
chmod $perm $dst
done < $1

24
scripts/mkproto Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh
usage()
{
echo mkproto: prefix manprefix proto>&2
exit 1
}
prefix=${1?$(usage)}
manprefix=${2?$(usage)}
proto=${3?$(usage)}
trap "rm -f scripts/proto" EXIT INT QUIT TERM
(set -e
echo d $prefix/bin $prefix/bin 755
find . -maxdepth 1 -type f -perm /111 |
sed "s@.*@c & $prefix/bin/& 755@"
echo d $manprefix/man1 $manprefix/man1 755
find . -maxdepth 1 -name '*.1' |
sed "s@.*@c & $manprefix/man1/& 644@") > $proto
trap "" EXIT INT QUIT TERM

32
scripts/uninstall Executable file
View File

@ -0,0 +1,32 @@
#!/bin/sh
set -e
while read type src dst perm
do
case $type in
d)
echo $type $src $dst $perm
continue
;;
c)
rm -f $dst
;;
*)
echo uninstall: wrong entry type >&2
exit 1
;;
esac
done < $1 |
sort -r |
while read type src dst perm
do
case $type in
d)
if test `ls $dst | wc -l` -eq 0
then
rmdir $dst
fi
;;
esac
done