File: minisrc.sh

package info (click to toggle)
tcng 10b-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,632 kB
  • ctags: 2,515
  • sloc: ansic: 19,038; pascal: 4,640; yacc: 2,619; sh: 1,908; perl: 1,546; lex: 772; makefile: 755
file content (102 lines) | stat: -rwxr-xr-x 2,385 bytes parent folder | download | duplicates (4)
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
#!/bin/sh -e
#
# minisrc.sh - Extract files needed to build tcsim from an iproute2 tarball
#
# Written 2003,2004 by Werner Almesberger
# Copyright 2003,2004 Werner Almesberger
#

[ -r tcsim/setup.klib ] || {
    echo "$0 must be run from the tcng top-level directory" 1>&2
    exit 1
}


usage()
{
    echo "usage: $0 [-q] path_to/iproute2-x.tar.gz" 1>&2
    exit 1
}


if [ "$1" = -q ]; then
    quiet=true
    shift
else
    quiet=false
fi

[ "${1#-}" = "$1" ] || usage
[ ! -z "$1" ] || usage
[ -f "$1" ] || {
    echo "no such file: $1" 1>&2
    exit 1
}

id=`basename "$1" .tar.gz`
[ "${id#iproute2-}" != "$id" -o "${id#iproute_20}" != "$id" ] || usage

if [ "${id#iproute2-2.6}" == "$id" ]; then
    dir=iproute2
else
    dir=./`echo $id | sed 's/-[^-]*$//'`
fi

#
# Check if we've already extracted the tree
#

if [ -f $dir/.tarball ] && \
  [ "`cat $dir/.tarball`" = "$1" -a "$1" -ot $dir/.tarball ]; then
    $quiet || echo "Source tree has already been extracted to $dir"
    exit 0
else
    rm -f $dir/.tarball
fi

#
# Find out which source files we really need
#

if grep 'ISRC.*ISRC' tcsim/setup.ulib >/dev/null; then
    echo 'setup.ulib must not contain lines with more than one use of $ISRC' \
      2>&1
    exit 1
fi

#
# The 1st substititution extracts anything that is prefixed by $ISRC
# The 2nd substititution removes wildcards
# The 3rd substititution removes empty entries (from the 2nd substitution)
#

IFILES=`sed '/^#/d;/.*$ISRC\/\([][a-zA-Z0-9_\/{},.*-]*\).*/ \
  {s//\1/;s/[a-zA-Z0-9_\/.-]*[][*][][a-zA-Z0-9_\/.*-]*[][*]//g;p;};d' \
    <tcsim/setup.ulib |
    sed 's/,,,*/,/g;s/{,,*/{/g;s/,,*}/}/g;s/{}//g;s/{\([^,]*\)}/\1/g'`
IFILES=`eval echo $IFILES`      # expand {...,...}
IFILES="Makefile $IFILES"
IFILES=`echo $IFILES | tr ' ' '\012' | sort | uniq`

#
# Ugly: since not all files may be present, we ignore all errors from tar
# (unfortunately, including ENOSPC, etc.)
#

$quiet || echo "Extracting files from $1 ..."
$quiet || echo '(may yield a few "Not found in archive" messages)'

#
# Since we have wildcards, we need to remove individual files or tar will
# needlessly complain.
#

tar xfz "$1" $dir/include/SNAPSHOT.h \
  $dir/'tc/*.[ch]' $dir/'lib/*.[ch]' \
  `for n in $IFILES; do \
    [ "${n#tc/*.[ch]}" = "" -o "${n#lib/*.[ch]}" = "" ] || echo $dir/$n; \
    done` || true

echo "$1" >$dir/.tarball

$quiet || echo "Extracted to ./$dir/"