forked from DeqingSun/ch55xduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimize-sdcc.sh
More file actions
executable file
·69 lines (55 loc) · 1.58 KB
/
minimize-sdcc.sh
File metadata and controls
executable file
·69 lines (55 loc) · 1.58 KB
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
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Minimize a SDCC snapshot build by leaving out all non-STM8 files."
echo
echo "usage: $0 sdcc-snapshot-filename"
exit 1
fi
#FILE=~/Downloads/sdcc-snapshot-amd64-unknown-linux2.5-20170919-9998.tar.bz2
FILE=$(realpath $1)
case "$FILE" in
*.tar.bz2 | *.tbz)
TARFLAG=j
;;
*.tar.gz | *.tgz)
TARFLAG=z
;;
*.zip)
TARFLAG=zip
;;
esac
# set to v for verbose mode
VERBOSE=
# transform the filename from "*-snapshot-*" to "*-stm8-*"
NAME=$(basename "$FILE")
NAME=${NAME/snapshot/stm8}
# remove all suffixes
NAME=${NAME%%.t*}
NAME=${NAME%%.z*}
# patterns to exclude all unneeded files from unpacking
TAR_EXCLUDE='--exclude=doc --exclude=src --exclude=non-free
--exclude=stlcs --exclude=ds80c390.h --exclude=pic*
--exclude=*00 --exclude=*08 --exclude=*2k
--exclude=*51 --exclude=*80 --exclude=*90
--exclude=*gb --exclude=*ka --exclude=*.info
--exclude=*pdk* --exclude=*rab --exclude=huge
--exclude=large* --exclude=medium --exclude=small*'
ZIP_EXCLUDE='-x */non-free/* */src/* *stlcs* */pic*
*00* *08* *80* *90* *51* *2k* *gb* *ka* */info/* *pdk* *rab*
*/huge/* */large* */medium/* */small*'
TMP=$(mktemp -d sdcc-repack-XXXXXX --tmpdir)
echo "Unpacking into $TMP..."
if [ $TARFLAG == zip ]; then
# unzip "$FILE" -d "$TMP" $ZIP_EXCLUDE
cd "$TMP"
unzip "$FILE" $ZIP_EXCLUDE
cd -
else
tar x${VERBOSE}${TARFLAG}f "$FILE" -C "$TMP" $TAR_EXCLUDE
fi
# always repack into a tar.bz2 file, even if was a zip before.
echo "Repacking into file $NAME"
tar c${VERBOSE}jf "$NAME.tar.bz2" -C "$TMP" sdcc
echo "cleaning up temporary files"
rm -rf "$TMP"
echo "done."