commit 246b932d16ead352c5ad950316367614b17e2dae
parent 1d12e6bad4e178f454ba0fd9f3c566340ce62a2c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 8 Oct 2021 01:27:15 +0200
build: Add support for DESTDIR
PREFIX is used to mark what is going to be the final
path where the program is going to be stored and where
it will locate its resources. Package creators need a
way to redirect all the installation to a directory
that can be used as base doe a tar.gz file instead
of installing all the files in the prefix destination.
Diffstat:
3 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/Makefile b/Makefile
@@ -11,6 +11,7 @@ PROJECTDIR = .
include $(PROJECTDIR)/scripts/rules.mk
PREFIX= $(HOME)
+ROOT=$(DESTDIR)$(PREFIX)
NODEP = 1
all:
@@ -36,10 +37,10 @@ x86_64 amd64:
+@$(MAKE) `$(SCRIPTDIR)/config` CONF=amd64-darwin libc libcrt
install-x86_64 install-amd64: amd64
- $(SCRIPTDIR)/install -p $(SCRIPTDIR)/proto.amd64 $(PREFIX)
+ $(SCRIPTDIR)/install -p $(SCRIPTDIR)/proto.amd64 $(ROOT)
uninstall-x86_64 uninstall-amd64:
- $(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.amd64 $(PREFIX)
+ $(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.amd64 $(ROOT)
#############################################################
# i386 rules
@@ -48,10 +49,10 @@ i386:
+@$(MAKE) `$(SCRIPTDIR)/config` CONF=i386-linux libc libcrt
install-i386: i386
- $(SCRIPTDIR)/install -p $(SCRIPTDIR)/proto.i386 $(PREFIX)
+ $(SCRIPTDIR)/install -p $(SCRIPTDIR)/proto.i386 $(ROOT)
uninstall-i386:
- $(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.i386 $(PREFIX)
+ $(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.i386 $(ROOT)
#############################################################
# ppc rules
@@ -60,10 +61,10 @@ ppc:
+@$(MAKE) `$(SCRIPTDIR)/config` CONF=ppc-linux libc libcrt
install-ppc: ppc
- $(SCRIPTDIR)/install -p $(SCRIPTDIR)/proto.ppc $(PREFIX)
+ $(SCRIPTDIR)/install -p $(SCRIPTDIR)/proto.ppc $(ROOT)
uninstall-ppc:
- $(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.ppc $(PREFIX)
+ $(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.ppc $(ROOT)
#############################################################
# arm rules
@@ -72,10 +73,10 @@ arm:
+@$(MAKE) `$(SCRIPTDIR)/config` CONF=arm-linux libc libcrt
install-arm: arm
- $(SCRIPTDIR)/install -p $(SCRIPTDIR)/proto.arm $(PREFIX)
+ $(SCRIPTDIR)/install -p $(SCRIPTDIR)/proto.arm $(ROOT)
uninstall-arm:
- $(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.arm $(PREFIX)
+ $(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.arm $(ROOT)
#############################################################
# arm64 rules
@@ -84,10 +85,10 @@ arm64:
+@$(MAKE) `$(SCRIPTDIR)/config` CONF=arm64-linux libc libcrt
install-arm64: arm64
- $(SCRIPTDIR)/install -p $(SCRIPTDIR)/proto.arm64 $(PREFIX)
+ $(SCRIPTDIR)/install -p $(SCRIPTDIR)/proto.arm64 $(ROOT)
uninstall-arm64:
- $(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.arm64 $(PREFIX)
+ $(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.arm64 $(ROOT)
toolchain: dirs src
libc: dirs src/libc
diff --git a/scripts/install b/scripts/install
@@ -10,22 +10,22 @@ do
shift 2
;;
-*)
- echo usage: install [-p proto] prefix >&2
+ echo usage: install [-p proto] root >&2
exit 1
;;
esac
done
-prefix=${1?'prefix missed'}
+root=${1?'root missed'}
while read type perm name
do
case $type in
d)
- mkdir -p $prefix/$name
+ mkdir -p $root/$name
;;
f)
- cp $name $prefix/$name
+ cp $name $root/$name
;;
*)
echo install: wrong entry type >&2
@@ -33,5 +33,5 @@ do
;;
esac
- chmod $perm $prefix/$name
+ chmod $perm $root/$name
done < ${proto:-scripts/proto.all}
diff --git a/scripts/uninstall b/scripts/uninstall
@@ -10,13 +10,13 @@ do
shift 2
;;
-*)
- echo usage: uninstall [-p proto] prefix >&2
+ echo usage: uninstall [-p proto] root >&2
exit 1
;;
esac
done
-prefix=${1?'prefix missed'}
+root=${1?'root missed'}
proto=${proto:-scripts/proto.all}
while read type perm name
@@ -27,7 +27,7 @@ do
continue
;;
f)
- rm -f $prefix/$name
+ rm -f $root/$name
;;
*)
echo install: wrong entry type >&2
@@ -40,7 +40,10 @@ while read type perm name
do
case $type in
d)
- rmdir $prefix/$name || :
+ if test `ls $root/$name | wc -l` -eq 0
+ then
+ rmdir $root/$name
+ fi
;;
esac
done