Browse Source

Support relocable install via DESTDIR

DESTDIR[1] can be now set to specify the root in situations such as when
building a package or installing to a chrooted environment.

If not specified by environment variable (eg. by make) or in mkit.ini,
the default value is governed by MKIT_DEFAULT_DESTDIR, which defaults to
"/".

  [1]: https://www.gnu.org/prep/standards/html_node/DESTDIR.html
Alois Mahdal 9 years ago
parent
commit
142cdbf606
3 changed files with 17 additions and 1 deletions
  1. 15
    1
      src/include/deploy.sh
  2. 1
    0
      src/make.skel
  3. 1
    0
      src/mkit.mk

+ 15
- 1
src/include/deploy.sh View File

57
     fi
57
     fi
58
 }
58
 }
59
 
59
 
60
+get_destdir() {
61
+    #
62
+    # Get DESTDIR: first from ENV:DESTDIR, then the default
63
+    #
64
+    {
65
+        ini 1value ENV:DESTDIR | grep . && return
66
+        echo "$MKIT_DEFAULT_DESTDIR"
67
+    } \
68
+      | xargs readlink -m \
69
+      | grep -m 1 .
70
+}
71
+
60
 get_dst() {
72
 get_dst() {
61
     #
73
     #
62
     # Find out target path for src file $2 of group $1
74
     # Find out target path for src file $2 of group $1
73
     local grp="$1"
85
     local grp="$1"
74
     local root=$(ini 1value "roots:$grp")
86
     local root=$(ini 1value "roots:$grp")
75
     test -n "$root" || die "missing in config.ini: roots:$grp"
87
     test -n "$root" || die "missing in config.ini: roots:$grp"
76
-    echo "$root"
88
+    echo "$destdir/$root"
77
 }
89
 }
78
 
90
 
79
 install() {
91
 install() {
82
     #
94
     #
83
     check_env
95
     check_env
84
     local dst group mode src
96
     local dst group mode src
97
+    local destdir=$(get_destdir)
85
     ini values "lists:group" \
98
     ini values "lists:group" \
86
       | while read group;
99
       | while read group;
87
         do
100
         do
103
     #
116
     #
104
     check_env
117
     check_env
105
     local dst group src
118
     local dst group src
119
+    local destdir=$(get_destdir)
106
     ini values "lists:group" \
120
     ini values "lists:group" \
107
       | while read group;
121
       | while read group;
108
         do
122
         do

+ 1
- 0
src/make.skel View File

11
 export MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
11
 export MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
12
 export MKIT_LOCAL=${MKIT_LOCAL:-.mkit}
12
 export MKIT_LOCAL=${MKIT_LOCAL:-.mkit}
13
 export MKIT_DRY=${MKIT_DRY:-false}
13
 export MKIT_DRY=${MKIT_DRY:-false}
14
+export MKIT_DEFAULT_DESTDIR=${MKIT_DEFAULT_DESTDIR:-/}
14
 
15
 
15
 . "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
16
 . "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
16
 
17
 

+ 1
- 0
src/mkit.mk View File

9
 	@echo build options:
9
 	@echo build options:
10
 	@echo "VERSION  = ${VERSION}"
10
 	@echo "VERSION  = ${VERSION}"
11
 	@echo "PRERELEASE = ${PRERELEASE}"
11
 	@echo "PRERELEASE = ${PRERELEASE}"
12
+	@echo "DESTDIR   = ${DESTDIR}"
12
 	@echo "PREFIX   = ${PREFIX}"
13
 	@echo "PREFIX   = ${PREFIX}"
13
 
14
 
14
 build:
15
 build: