Commit fb71e8af1bb3cd53ec32db7fa2d540f07c2afe34

Thomas de Grivel 2023-02-03T18:59:01

wip

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
diff --git a/bin/shpkg b/bin/shpkg
index 1308e0b..37e5a3a 100755
--- a/bin/shpkg
+++ b/bin/shpkg
@@ -15,6 +15,34 @@ if [ "x$1" = "xbuild" ]; then
     shift
     verbose 2 shpkg_build "$@"
     exit
+elif [ "x$1" = "xclean-all" ]; then
+    shift
+    verbose 2 shpkg_clean_all "$@"
+    exit
+elif [ "x$1" = "xclean-sources" ]; then
+    shift
+    verbose 2 shpkg_clean_sources "$@"
+    exit
+elif [ "x$1" = "xclean-build" ]; then
+    shift
+    verbose 2 shpkg_clean_build "$@"
+    exit
+elif [ "x$1" = "xclean-configure" ]; then
+    shift
+    verbose 2 shpkg_clean_configure "$@"
+    exit
+elif [ "x$1" = "xclean-fake" ]; then
+    shift
+    verbose 2 shpkg_clean_fake "$@"
+    exit
+elif [ "x$1" = "xclean-package" ]; then
+    shift
+    verbose 2 shpkg_clean_package "$@"
+    exit
+elif [ "x$1" = "xclean-sources" ]; then
+    shift
+    verbose 2 shpkg_clean_sources "$@"
+    exit
 elif [ "x$1" = "xclone" ]; then
     shift
     verbose 2 shpkg_clone "$@"
@@ -47,12 +75,6 @@ elif [ "x$1" = "xpull" ] ||
     shift
     verbose 2 shpkg_pull "$@"
     exit
-elif [ "x$1" = "xremove" ] ||
-     [ "x$1" = "xrm" ]; then
-    shift
-    verbose 2 shpkg_uninstall "$@"
-    verbose 2 shpkg_remove "$@"
-    exit
 elif [ "x$1" = "xuninstall" ]; then
     shift
     verbose 2 shpkg_uninstall "$@"
@@ -69,23 +91,26 @@ fi
 echo "Usage: shpkg OPERATION PKG ...
 
 Source directory operations :
- clone          shortcut for git clone
- fetch          shortcut for git fetch
- pull           shortcut for git pull
- remove | rm    shortcut for uninstall and rm -rf repo
+ clone            shortcut for git clone
+ fetch            shortcut for git fetch
+ pull             shortcut for git pull
+ clean-sources    remove source directory
 
 Compilation operations :
- autogen        shortcut for ./autogen
- configure      shortcut for ./configure
- clean          shortcut for make clean
- build          shortcut for make
+ autogen          shortcut for ./autogen
+ configure        shortcut for ./configure
+ build            shortcut for make
+ clean-configure  remove configured and object files
+ clean-build      remove object files
 
 Package operations :
- fake           install compiled sources into fake directory
- package        build package from sources
- install        install package
- upgrade        pull sources, build package and install
- uninstall      uninstall package
+ fake             install compiled sources into fake directory
+ package          build package from sources
+ install          install package
+ upgrade          pull sources, build package and install
+ uninstall        uninstall package
+ clean-fake       remove fake installation directory
+ clean-package    remove built packages
 " >&2
 
 exit 1
diff --git a/share/shpkg/shpkg.subr b/share/shpkg/shpkg.subr
index bc0740b..0ebc9dc 100644
--- a/share/shpkg/shpkg.subr
+++ b/share/shpkg/shpkg.subr
@@ -3,43 +3,72 @@
 
 set -e
 
-# Console output
-err () {
-    R="$1"
-    shift
-    printf '\33[0;31m' >&2
-    echo -n "$0:" error: "$@" >&2
-    printf '\33[0m\n' >&2
-    exit "$R"
+# Config
+SHPKG_DATE="$(date +%F_%T)"
+
+SHPKG_DIR="${SHPKG_DIR:-${HOME}/shpkg}"
+
+SHPKG_ETC_DIR="${SHPKG_DIR}/etc/shpkg"
+SHPKG_INCLUDE_DIR="${SHPKG_DIR}/include"
+SHPKG_LIB_DIR="${SHPKG_DIR}/lib"
+SHPKG_SHARE_DIR="${SHPKG_DIR}/share/shpkg"
+SHPKG_SRC_DIR="${SHPKG_DIR}/src"
+SHPKG_VAR_DB_DIR="${SHPKG_DIR}/var/db/shpkg"
+SHPKG_VAR_LOG_DIR="${SHPKG_DIR}/var/log/shpkg"
+
+SHPKG_PREFIX="${SHPKG_DIR}"
+
+# Logging
+SHPKG_LOG="${SHPKG_VAR_LOG_DIR}/shpkg.${SHPKG_DATE}.log"
+echo "Date: ${SHPKG_DATE}" > "${SHPKG_LOG}"
+echo "Command: $0" "$@" >> "${SHPKG_LOG}"
+
+shpkg_log () {
+    tee -a "${SHPKG_LOG}"
 }
 
-verbose_puts () {
-    if [ "x$1" = "x1" ]; then
-        printf '\33[0;34m'
-    elif [ "x$1" = "x2" ]; then
-        printf '\33[0;35m'
-    else
-        err 1 "bad verbose level"
-    fi
-    shift
-    echo -n "$@"
-    printf '\33[0m\n'
+# Console output
+verbose__puts () {
+    {
+        if [ "x$1" = "x1" ]; then
+            printf '\33[0;34m'
+        elif [ "x$1" = "x2" ]; then
+            printf '\33[0;35m'
+        else
+            err 1 "bad verbose level"
+        fi
+        shift
+        echo -n "$@"
+        printf '\33[0m\n'
+    }
 }
 
 verbose () {
     if [ "x$1" = "x-n" ]; then
         shift
-        verbose_puts "$@"
+        verbose__puts "$@"
     else
-        verbose_puts "$@"
+        verbose__puts "$@"
         shift
         "$@"
     fi
 }
 
-# Config
-SHPKG_DIR="${SHPKG_DIR:-${HOME}/shpkg}"
+err () {
+    R="$1"
+    shift
+    {
+        printf '\33[0;31m'
+        echo -n "$0:" error: "$@"
+        printf '\33[0m\n'
+    } >&2
+    verbose 1 exit "$R"
+}
+
+# Startup
+# verbose -n 2 "logging to ${SHPKG_LOG}"
 
+# C compiler
 if [ "x${CC}" = "x" ]; then
     if which cc >/dev/null; then
         CC=cc
@@ -51,14 +80,27 @@ if [ "x${CC}" = "x" ]; then
         err 1 "C compiler not found."
     fi
 fi
+SHPKG_TARGET="$(LC_ALL=C.UTF-8 ${CC} -v 2>&1 | grep '^Target: ' | head -n 1 | cut -c 9-)"
+export CPPFLAGS="${CPPFLAGS} -I${SHPKG_INCLUDE_DIR}"
+export LDFLAGS="${LDFLAGS} -L${SHPKG_LIB_DIR}"
+export PKG_CONFIG_PATH="${SHPKG_LIB_DIR}/pkgconfig"
+
+SHPKG_TARGET_DIR="${SHPKG_DIR}/target/${SHPKG_TARGET}"
 
+SHPKG_FAKE_DIR="${SHPKG_TARGET_DIR}/fake"
+SHPKG_OBJ_DIR="${SHPKG_TARGET_DIR}/obj"
+SHPKG_PACKAGE_DIR="${SHPKG_TARGET_DIR}/packages"
+SHPKG_TAG_DIR="${SHPKG_TARGET_DIR}/tag"
+
+# OS detection
 SHPKG_OS="$(uname)"
 if [ "x${SHPKG_OS}" = "xLinux" ]; then
     SHPKG_OS="${SHPKG_OS}/$(uname -a | grep -io -e Debian -e Gentoo -e Ubuntu)"
 fi
 
-SHPKG_PREFIX="${SHPKG_DIR}"
+SHPKG_OS_DIR="${SHPKG_SHARE_DIR}/${SHPKG_OS}"
 
+# SHA256
 if which sha256 >/dev/null 2>&1; then
     SHPKG_SHA256=sha256
 elif which sha256sum >/dev/null 2>&1; then
@@ -67,25 +109,16 @@ else
     err 1 "sha256 executable not found"
 fi
 
-SHPKG_TARGET="$(${CC} -v 2>&1 | grep '^Target: ' | head -n 1 | cut -c 9-)"
-
-SHPKG_ETC_DIR="${SHPKG_DIR}/etc/shpkg"
-SHPKG_INCLUDE_DIR="${SHPKG_DIR}/include"
-SHPKG_LIB_DIR="${SHPKG_DIR}/lib"
-SHPKG_SHARE_DIR="${SHPKG_DIR}/share/shpkg"
-SHPKG_SRC_DIR="${SHPKG_DIR}/src"
-SHPKG_TARGET_DIR="${SHPKG_DIR}/target/${SHPKG_TARGET}"
-SHPKG_VAR_DB_DIR="${SHPKG_DIR}/var/db/shpkg"
-
-SHPKG_FAKE_DIR="${SHPKG_TARGET_DIR}/fake"
-SHPKG_OBJ_DIR="${SHPKG_TARGET_DIR}/obj"
-SHPKG_OS_DIR="${SHPKG_SHARE_DIR}/${SHPKG_OS}"
-SHPKG_PACKAGE_DIR="${SHPKG_TARGET_DIR}/packages"
-SHPKG_TAG_DIR="${SHPKG_TARGET_DIR}/tag"
+shpkg_sha256 () {
+    sha256 "$@"
+}
 
-export CPPFLAGS="${CPPFLAGS} -I${SHPKG_INCLUDE_DIR}"
-export LDFLAGS="${LDFLAGS} -L${SHPKG_LIB_DIR}"
-export PKG_CONFIG_PATH="${SHPKG_LIB_DIR}/pkgconfig"
+shpkg_sha256sum () {
+    for F; do
+        echo -n "SHA256 ($F) = "
+        sha256sum "$F" | cut -d ' ' -f 1
+    done
+}
 
 # Setup
 if ! [ -d "${SHPKG_FAKE_DIR}" ]; then
@@ -101,18 +134,6 @@ if ! [ -d "${SHPKG_VAR_DB_DIR}" ]; then
     verbose 1 mkdir -p "${SHPKG_VAR_DB_DIR}"
 fi
 
-# SHA256
-shpkg_sha256 () {
-    sha256 "$@"
-}
-
-shpkg_sha256sum () {
-    for F; do
-        echo -n "SHA256 ($F) = "
-        sha256sum "$F" | cut -d ' ' -f 1
-    done
-}
-
 # Repo index
 SHPKG_REPO_INDEX="${SHPKG_SHARE_DIR}/repo_index"
 if ! [ -f "${SHPKG_REPO_INDEX}" ]; then
@@ -141,16 +162,16 @@ shpkg_repo_info () {
 }
 
 shpkg_src_parent_dir () {
-    dirname "$(shpkg_dir "${REPO}")"
+    dirname "$(shpkg_dir "${SHPKG_REPO}")"
 }
 
 # Source repository
 shpkg_clone () {
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
-        SHPKG_REPO_PARENT_DIR="$(shpkg_src_parent_dir "${REPO}")"
-        SHPKG_REPO_GIT_BRANCH="$(shpkg_git_branch "${REPO}")"
-        SHPKG_REPO_GIT_URL="$(shpkg_git_url "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_PARENT_DIR="$(shpkg_src_parent_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_GIT_BRANCH="$(shpkg_git_branch "${SHPKG_REPO}")"
+        SHPKG_REPO_GIT_URL="$(shpkg_git_url "${SHPKG_REPO}")"
         SHPKG_REPO_BASENAME="$(basename "${SHPKG_REPO_DIR}")"
         if ! [ -d "${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}" ]; then
             verbose 1 mkdir -p "${SHPKG_SRC_DIR}/${SHPKG_REPO_PARENT_DIR}"
@@ -165,8 +186,8 @@ shpkg_clone () {
 }
 
 shpkg_fetch () {
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
         ( verbose 1 cd "${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}" &&
               verbose 1 git fetch
         )
@@ -174,17 +195,18 @@ shpkg_fetch () {
 }
 
 shpkg_pull () {
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
         ( verbose 1 cd "${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}" &&
               verbose 1 git pull; )
     done
 }
 
-shpkg_remove () {
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
-        SHPKG_REPO_PARENT_DIR="$(shpkg_src_parent_dir "${REPO}")"
+shpkg_clean_sources () {
+    for SHPKG_REPO; do
+        ( verbose 2 shpkg_clean_configure "${SHPKG_REPO}"; )
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_PARENT_DIR="$(shpkg_src_parent_dir "${SHPKG_REPO}")"
         verbose 1 rm -rf "${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
         verbose -n 1 "rmdir ${SHPKG_SRC_DIR}/${SHPKG_REPO_PARENT_DIR}"
         rmdir "${SHPKG_SRC_DIR}/${SHPKG_REPO_PARENT_DIR}" 2>/dev/null || true
@@ -204,8 +226,8 @@ shpkg_version () {
 # Building from sources
 shpkg_autogen () {
     verbose 2 shpkg_clone "$@"
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
         SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
         if [ -x "${SHPKG_REPO_SRC_DIR}/autogen" ]; then
             ( verbose 1 cd "${SHPKG_REPO_SRC_DIR}" &&
@@ -221,18 +243,19 @@ shpkg_autogen () {
 }
 
 shpkg_build () {
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
-        SHPKG_REPO_VERSION="$(shpkg_version "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_OBJ_DIR="${SHPKG_OBJ_DIR}/${SHPKG_REPO_DIR}"
         SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
+        SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
 	if shpkg__tag_is_absent build-done; then
-	    ( verbose 2 shpkg_configure "${REPO}"; )
-            SHPKG_REPO_VERSION="$(shpkg_version "${REPO}")"
+	    ( verbose 2 shpkg_configure "${SHPKG_REPO}"; )
+            SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
             if [ -f "${SHPKG_REPO_SRC_DIR}/Makefile" ]; then
 		( verbose 1 cd "${SHPKG_REPO_SRC_DIR}" &&
                       verbose 1 make; )
             elif [ -f "${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}/CMakeLists.txt" ]; then
-		cmake --build "${SHPKG_OBJ_DIR}/${SHPKG_REPO_DIR}"
+		cmake --build "${SHPKG_REPO_OBJ_DIR}"
             fi
             shpkg__tag_write build-done
 	fi
@@ -245,15 +268,40 @@ shpkg_checksum () {
     done
 }
 
+shpkg_clean_build () {
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_OBJ_DIR="${SHPKG_OBJ_DIR}/${SHPKG_REPO_DIR}"
+        SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
+        SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
+        if [ -f "${SHPKG_REPO_SRC_DIR}/Makefile" ]; then
+	    ( verbose 1 cd "${SHPKG_REPO_SRC_DIR}" &&
+                  verbose 1 make clean; )
+        fi
+        if [ -d "${SHPKG_REPO_OBJ_DIR}" ]; then
+            verbose 1 rm -rf "${SHPKG_REPO_OBJ_DIR}"
+        fi
+        shpkg__tag_remove build-done
+    done
+}
+
+shpkg_clean_configure () {
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
+        shpkg__tag_remove configure-done
+    done
+}
+
 shpkg_configure () {
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
-        SHPKG_REPO_FAKE_DIR="$(shpkg_fake_dir "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_FAKE_DIR="$(shpkg_fake_dir "${SHPKG_REPO}")"
         SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
-        SHPKG_REPO_VERSION="$(shpkg_version "${REPO}")"
+        SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
 	if shpkg__tag_is_absent configure-done; then
-            ( verbose 2 shpkg_autogen "${REPO}"; )
-            SHPKG_REPO_VERSION="$(shpkg_version "${REPO}")"
+            ( verbose 2 shpkg_autogen "${SHPKG_REPO}"; )
+            SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
             if ! [ -d "${SHPKG_REPO_FAKE_DIR}" ]; then
                 verbose 1 mkdir -p "${SHPKG_REPO_FAKE_DIR}"
             fi
@@ -273,9 +321,9 @@ shpkg_configure () {
 
 shpkg_fake () {
     verbose 2 shpkg_build "$@"
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
-        SHPKG_REPO_FAKE_DIR="$(shpkg_fake_dir "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_FAKE_DIR="$(shpkg_fake_dir "${SHPKG_REPO}")"
         SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
         if [ -d "${SHPKG_REPO_FAKE_DIR}" ]; then
 	    verbose 1 rm -rf "${SHPKG_REPO_FAKE_DIR}"
@@ -291,18 +339,18 @@ shpkg_fake () {
 }
 
 shpkg_fake_dir () {
-    echo "${SHPKG_FAKE_DIR}/$(shpkg_dir "${REPO}")"
+    echo "${SHPKG_FAKE_DIR}/$(shpkg_dir "$1")"
 }
 
 shpkg_package () {
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
-        SHPKG_REPO_VERSION="$(shpkg_version "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
         SHPKG_REPO_PACKAGE="${SHPKG_PACKAGE_DIR}/${SHPKG_REPO_DIR}-${SHPKG_REPO_VERSION}.tgz"
 	if ! [ -f "${SHPKG_REPO_PACKAGE}" ]; then
-            SHPKG_REPO_FAKE_DIR="$(shpkg_fake_dir "${REPO}")"
-	    verbose 2 shpkg_fake "${REPO}"
-            SHPKG_REPO_VERSION="$(shpkg_version "${REPO}")"
+            SHPKG_REPO_FAKE_DIR="$(shpkg_fake_dir "${SHPKG_REPO}")"
+	    verbose 2 shpkg_fake "${SHPKG_REPO}"
+            SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
             SHPKG_REPO_PACKAGE="${SHPKG_PACKAGE_DIR}/${SHPKG_REPO_DIR}-${SHPKG_REPO_VERSION}.tgz"
             SHPKG_REPO_PACKAGE_CHECKSUM="${SHPKG_PACKAGE_DIR}/${SHPKG_REPO_DIR}-${SHPKG_REPO_VERSION}.SHA256"
             SHPKG_REPO_PACKAGE_DIR="$(dirname "${SHPKG_REPO_PACKAGE}")"
@@ -324,32 +372,42 @@ shpkg__tag_is_absent() {
     ! [ -f "${SHPKG_REPO_TAG_DIR}/$1" ]
 }
 
+shpkg__tag_remove() {
+    for SHPKG_TAG; do
+        SHPKG_REPO_TAG_DIR="${SHPKG_TAG_DIR}/${SHPKG_REPO_DIR}/${SHPKG_REPO_VERSION}"
+        if [ -f "${SHPKG_REPO_TAG_DIR}/${SHPKG_TAG}" ]; then
+            verbose 1 "rm ${SHPKG_REPO_TAG_DIR}/${SHPKG_TAG}"
+        fi
+    done
+}
+
 shpkg__tag_write() {
-    SHPKG_REPO_TAG_DIR="${SHPKG_TAG_DIR}/${SHPKG_REPO_DIR}/${SHPKG_REPO_VERSION}"
-    DATE="$(date +%F\ %T)"
-    if ! [ -d "${SHPKG_REPO_TAG_DIR}" ]; then
-        verbose 1 mkdir -p "${SHPKG_REPO_TAG_DIR}"
-    fi
-    verbose -n 1 "echo ${DATE} > ${SHPKG_REPO_TAG_DIR}/$1"
-    echo "${DATE}" > "${SHPKG_REPO_TAG_DIR}/$1"
+    for SHPKG_TAG; do
+        SHPKG_REPO_TAG_DIR="${SHPKG_TAG_DIR}/${SHPKG_REPO_DIR}/${SHPKG_REPO_VERSION}"
+        if ! [ -d "${SHPKG_REPO_TAG_DIR}" ]; then
+            verbose 1 mkdir -p "${SHPKG_REPO_TAG_DIR}"
+        fi
+        verbose -n 1 "echo ${SHPKG_DATE} > ${SHPKG_REPO_TAG_DIR}/${SHPKG_TAG}"
+        echo "${SHPKG_DATE}" > "${SHPKG_REPO_TAG_DIR}/${SHPKG_TAG}"
+    done
 }
 
 # Packages
 shpkg_install () {
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
         if ! grep -Eq "^${SHPKG_REPO_DIR}\$" "${SHPKG_OS_DIR}/system_packages"; then
-            SHPKG_REPO_VERSION="$(shpkg_version "${REPO}")"
+            SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
             SHPKG_REPO_PACKAGE="${SHPKG_PACKAGE_DIR}/${SHPKG_REPO_DIR}-${SHPKG_REPO_VERSION}.tgz"
 	    SHPKG_REPO_INSTALLED="${SHPKG_VAR_DB_DIR}/installed/${SHPKG_REPO_DIR}"
 	    SHPKG_REPO_INSTALLED_DIR="$(dirname "${SHPKG_REPO_INSTALLED}")"
 	    if ! [ -f "${SHPKG_REPO_INSTALLED}" ] ||
 		    ! head -n 1 < "${SHPKG_REPO_INSTALLED}" |
 		        grep "Version: ${SHPKG_REPO_VERSION}" >/dev/null; then
-	        ( verbose 2 shpkg_install_dependencies "${REPO}"; )
-	        ( verbose 2 shpkg_build "${REPO}"; )
-	        ( verbose 2 shpkg_package "${REPO}"; )
-                SHPKG_REPO_VERSION="$(shpkg_version "${REPO}")"
+	        ( verbose 2 shpkg_install_dependencies "${SHPKG_REPO}"; )
+	        ( verbose 2 shpkg_build "${SHPKG_REPO}"; )
+	        ( verbose 2 shpkg_package "${SHPKG_REPO}"; )
+                SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
                 SHPKG_REPO_PACKAGE="${SHPKG_PACKAGE_DIR}/${SHPKG_REPO_DIR}-${SHPKG_REPO_VERSION}.tgz"
                 SHPKG_REPO_PACKAGE_CHECKSUM="${SHPKG_PACKAGE_DIR}/${SHPKG_REPO_DIR}-${SHPKG_REPO_VERSION}.SHA256"
                 ( verbose 1 cd "${SHPKG_DIR}" &&
@@ -368,8 +426,8 @@ shpkg_install () {
 }
 
 shpkg_install_dependencies () {
-    for REPO; do
-        SHPKG_REPO_DEPENDS_ON="$(shpkg_depends_on "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DEPENDS_ON="$(shpkg_depends_on "${SHPKG_REPO}")"
         if [ "x${SHPKG_REPO_DEPENDS_ON}" != "x" ]; then
             ( verbose 2 shpkg_install ${SHPKG_REPO_DEPENDS_ON}; )
         fi
@@ -379,8 +437,8 @@ shpkg_install_dependencies () {
 # TODO: remove package files: hash files on install and delete them if not changed
 # TODO: remove metadata about installed packages
 shpkg_uninstall () {
-    for REPO; do
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
 	SHPKG_REPO_INSTALLED="${SHPKG_VAR_DB_DIR}/installed/${SHPKG_REPO_DIR}"
         if [ -f "${SHPKG_REPO_INSTALLED}" ]; then
             verbose 1 cd "${SHPKG_DIR}"
@@ -405,18 +463,19 @@ shpkg_upgrade () {
     verbose 2 shpkg_install "$@"
 }
 
-# Meta
-shpkg_clean() {
-    for REPO; do
-        ( verbose 2 shpkg_uninstall "${REPO}"; )
-        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
-        SHPKG_REPO_FAKE_DIR="$(shpkg_fake_dir "${REPO}")"
-        rm -rf "${SHPKG_REPO_FAKE_DIR}"
+# Clean
+shpkg_clean_all() {
+    for SHPKG_REPO; do
+        SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_FAKE_DIR="$(shpkg_fake_dir "${SHPKG_REPO}")"
+        verbose 1 rm -rf "${SHPKG_REPO_FAKE_DIR}"
+        SHPKG_REPO_OBJ_DIR="${SHPKG_OBJ_DIR}/${SHPKG_REPO_DIR}"
+        verbose 1 rm -rf "${SHPKG_REPO_OBJ_DIR}"
         SHPKG_REPO_PACKAGE="${SHPKG_PACKAGE_DIR}/${SHPKG_REPO_DIR}"
-        rm -rf "${SHPKG_REPO_PACKAGE}"-*
+        verbose 1 rm -rf "${SHPKG_REPO_PACKAGE}"-*
         SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
-        rm -rf "${SHPKG_REPO_SRC_DIR}"
+        verbose 1 rm -rf "${SHPKG_REPO_SRC_DIR}"
         SHPKG_REPO_TAG_DIR="${SHPKG_TAG_DIR}/${SHPKG_REPO_DIR}"
-        rm -rf "${SHPKG_REPO_TAG_DIR}"
+        verbose 1 rm -rf "${SHPKG_REPO_TAG_DIR}"
     done
 }