annotate include.sh @ 222:8b0d2080707c

Be smarter about extracting tarballs: extract one copy of each tarball into build/sources and then make a symlink tree (cp -sR) in each temp directory to build with. Makes ./forkbomb.sh --fork much faster. :)
author Rob Landley <rob@landley.net>
date Wed, 19 Sep 2007 18:52:56 -0500
parents 8d2d0feff1ef
children 9c48cf5b65f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
173
8b4c243a212e Add better debug info to a status report, and stop fighting ubuntu so much
Rob Landley <rob@landley.net>
parents: 170
diff changeset
1 #!/bin/bash
138
7dffe9648a56 Installing bash but not using it. Yeah, there's a political agenda at work
Rob Landley <rob@landley.net>
parents: 125
diff changeset
2
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
3 function noversion()
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
4 {
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
5 echo "$1" | sed -r -e 's/-*([0-9\.]|[_-]rc|-pre|[0-9][a-zA-Z])*(\.tar\..z2*)$/\2/'
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
6 }
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
7
220
8d2d0feff1ef The "caller" built-in isn't available in bash 2.x.
Rob Landley <rob@landley.net>
parents: 214
diff changeset
8 function extract()
8d2d0feff1ef The "caller" built-in isn't available in bash 2.x.
Rob Landley <rob@landley.net>
parents: 214
diff changeset
9 {
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
10 SRCTREE="${BUILD}/sources"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
11 BASENAME=`noversion "$1"`
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
12 BASENAME="${BASENAME/%\.tar\.*/}"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
13
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
14 # Sanity check: don't ever "rm -rf /". Just don't.
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
15
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
16 if [ -z "$BASENAME" ] || [ -z "$SRCTREE" ]
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
17 then
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
18 dienow
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
19 fi
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
20
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
21 # If it's already extracted, do nothing.
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
22 if [ -f "${SRCTREE}/${BASENAME}/sha1-for-source.txt" ]
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
23 then
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
24 SHA2="$(cat "${SRCTREE}/${BASENAME}/sha1-for-source.txt" 2>/dev/null)"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
25 if [ -z "$2" ] || [ "$2" == "$SHA2" ]
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
26 then
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
27 return 0
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
28 fi
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
29 fi
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
30
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
31 rm -rf "${BUILD}/temp" "${SRCTREE}/${BASENAME}" 2>/dev/null
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
32 mkdir -p "${BUILD}"/{temp,sources} || dienow
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
33
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
34 # Is it a bzip2 or gzip tarball?
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
35 DECOMPRESS=""
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
36 [ "$1" != "${1/%\.tar\.bz2/}" ] && DECOMPRESS="j"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
37 [ "$1" != "${1/%\.tar\.gz/}" ] && DECOMPRESS="z"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
38
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
39 echo -n "Extracting '${BASENAME}'" &&
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
40 cd "${WORK}" &&
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
41 { tar xv${DECOMPRESS}fC "${SRCDIR}/$1" "${BUILD}/temp" || dienow
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
42 } | dotprogress
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
43
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
44 mv "${BUILD}/temp/"* "${SRCTREE}/${BASENAME}" &&
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
45 rmdir "${BUILD}/temp" &&
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
46 echo "$2" > "${SRCTREE}/${BASENAME}/sha1-for-source.txt"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
47
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
48 [ $? -ne 0 ] && dienow
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
49
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
50 # Apply any patches to this package
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
51
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
52 ls "${SOURCES}/patches/$BASENAME"* 2> /dev/null | sort | while read i
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
53 do
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
54 if [ -f "$i" ]
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
55 then
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
56 echo "Applying $i"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
57 (cd "${SRCTREE}/${BASENAME}" && patch -p1 -i "$i") || dienow
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
58 fi
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
59 done
220
8d2d0feff1ef The "caller" built-in isn't available in bash 2.x.
Rob Landley <rob@landley.net>
parents: 214
diff changeset
60 }
8d2d0feff1ef The "caller" built-in isn't available in bash 2.x.
Rob Landley <rob@landley.net>
parents: 214
diff changeset
61
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 function download()
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
63 {
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
64 FILENAME=`echo "$URL" | sed 's .*/ '`
166
87feb7deddbc Mike released an actual uClibc 0.9.29-rc1 (even though it's named weird), so
Rob Landley <rob@landley.net>
parents: 163
diff changeset
65 BASENAME=`echo "$FILENAME" | sed -r -e 's/-*([0-9\.]|[_-]rc|-pre|[0-9][a-zA-Z])*(\.tar\..z2*)$/\2/'`
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
66
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
67 # The extra "" is so we test the sha1sum after the last download.
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
68
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
69 for i in "$URL" http://www.landley.net/code/firmware/mirror/"$FILENAME" ""
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
70 do
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
71 # Return success if we have a valid copy of the file
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
72
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
73 # Test first (so we don't re-download a file we've already got).
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
74
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
75 SUM=`cat "$SRCDIR/$FILENAME" | sha1sum | awk '{print $1}'`
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
76 if [ x"$SUM" == x"$SHA1" ] || [ -z "$SHA1" ] && [ -f "$SRCDIR/$FILENAME" ]
41
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
77 then
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
78 touch "$SRCDIR/$FILENAME"
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
79 if [ -z "$SHA1" ]
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
80 then
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
81 echo "No SHA1 for $FILENAME ($SUM)"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
82 else
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
83 echo "Confirmed $FILENAME"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
84 fi
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
85 if [ ! -z "$EXTRACT_ALL" ]
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
86 then
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
87 extract "$FILENAME" "$SUM"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
88 fi
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
89 return 0
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
90 fi
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
91
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
92 # If there's a corrupted file, delete it. In theory it would be nice
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
93 # to resume downloads, but wget creates "*.1" files instead.
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
94
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
95 rm "$SRCDIR/$FILENAME" 2> /dev/null
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
96
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
97 # If we have another source, try to download file.
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
98
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
99 if [ -n "$i" ]
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
100 then
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
101 wget -P "$SRCDIR" "$i"
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
102 fi
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
103 done
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
104
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
105 # Return failure.
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
106
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
107 echo "Could not download $FILENAME"
81
6dd38c925bc4 Upgrade some packages, and other cleanups.
Rob Landley <rob@landley.net>
parents: 62
diff changeset
108 echo -en "\e[0m"
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
109 return 1
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
110 }
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
111
41
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
112 # Clean obsolete files out of the source directory
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
113
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
114 START_TIME=`date +%s`
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
115
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
116 function cleanup_oldfiles()
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
117 {
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
118 for i in "${SRCDIR}"/*
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
119 do
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
120 if [ -f "$i" ] && [ "$(date +%s -r "$i")" -lt "${START_TIME}" ]
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
121 then
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
122 echo Removing old file "$i"
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
123 rm -rf "$i"
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
124 fi
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
125 done
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
126 }
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
127
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
128 function dienow()
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
129 {
220
8d2d0feff1ef The "caller" built-in isn't available in bash 2.x.
Rob Landley <rob@landley.net>
parents: 214
diff changeset
130 echo -e "\e[31mExiting due to errors\e[0m"
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
131 exit 1
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
132 }
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
133
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
134 function dotprogress()
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
135 {
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
136 x=0
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
137 while read i
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
138 do
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
139 x=$[$x + 1]
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
140 if [[ "$x" -eq 25 ]]
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
141 then
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
142 x=0
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
143 echo -n .
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
144 fi
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
145 done
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
146 echo
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
147 }
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
148
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
149 # Extract package $1, use out-of-tree build directory $2 (or $1 if no $2)
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
150 # Use symlink directory $3 (or $1 if no $3)
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
151
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
152 function setupfor()
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
153 {
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
154 # Make sure the
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
155 cd "${SRCDIR}" &&
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
156 extract "${1}-"*.tar* ""
41
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
157
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
158 # Set CURSRC
173
8b4c243a212e Add better debug info to a status report, and stop fighting ubuntu so much
Rob Landley <rob@landley.net>
parents: 170
diff changeset
159
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
160 export CURSRC="$1"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
161 [ ! -z "$3" ] && CURSRC="$3"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
162 CURSRC="${WORK}/${CURSRC}"
41
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
163
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
164 # Announce package, with easy-to-grep-for "===" marker.
41
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
165
125
2dd9f480ff4e Set PATH for run-mini-native.sh and add more obvious arch display info when
Rob Landley <rob@landley.net>
parents: 124
diff changeset
166 echo "=== Building $1 ($ARCH_NAME)"
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
167 echo "Snapshot '$1'..."
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
168 cd "${WORK}" &&
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
169 mkdir -p "${CURSRC}" &&
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
170 cp -sfR "${SRCTREE}/$1/"* "${CURSRC}"
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
171
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
172 [ $? -ne 0 ] && dienow
41
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
173
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
174 # Do we have a separate working directory?
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
175
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
176 if [ -z "$2" ]
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
177 then
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
178 cd "$1"* || dienow
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
179 else
47
edaa86240321 Turnerize the build script and teach cross-compile.sh to build qemu when
Rob Landley <rob@landley.net>
parents: 41
diff changeset
180 mkdir -p "$2" &&
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
181 cd "$2" || dienow
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
182 fi
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
183 }
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
184
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
185 # Setup
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
186
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
187 umask 022
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
188 unset CFLAGS CXXFLAGS
191
485dabec83c4 Comment one of the non-obvious (and optional) bits.
Rob Landley <rob@landley.net>
parents: 188
diff changeset
189 # This tells gcc to aggressively garbage collect its internal data
485dabec83c4 Comment one of the non-obvious (and optional) bits.
Rob Landley <rob@landley.net>
parents: 188
diff changeset
190 # structures. Without this, gcc triggers the OOM killer trying to rebuild
485dabec83c4 Comment one of the non-obvious (and optional) bits.
Rob Landley <rob@landley.net>
parents: 188
diff changeset
191 # itself in 128 megs of ram, which is the QEMU default size.
124
d5e9d5cf0172 According to http://hostingfu.com/article/compiling-with-gcc-on-low-memory-vps
Rob Landley <rob@landley.net>
parents: 120
diff changeset
192 export CFLAGS="--param ggc-min-expand=0 --param ggc-min-heapsize=8192"
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
193
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
194 # Find/create directories
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
195
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
196 TOP=`pwd`
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
197 export SOURCES="${TOP}/sources"
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
198 export SRCDIR="${SOURCES}/packages"
98
b6b4386a6c83 Make host-tools.sh work when run standalone.
Rob Landley <rob@landley.net>
parents: 96
diff changeset
199 export FROMSRC=../packages
41
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
200 export BUILD="${TOP}/build"
98
b6b4386a6c83 Make host-tools.sh work when run standalone.
Rob Landley <rob@landley.net>
parents: 96
diff changeset
201 export HOSTTOOLS="${BUILD}/host"
b6b4386a6c83 Make host-tools.sh work when run standalone.
Rob Landley <rob@landley.net>
parents: 96
diff changeset
202 export WORK="${BUILD}/host-temp"
b6b4386a6c83 Make host-tools.sh work when run standalone.
Rob Landley <rob@landley.net>
parents: 96
diff changeset
203 export PATH="${HOSTTOOLS}:$PATH"
222
8b0d2080707c Be smarter about extracting tarballs: extract one copy of each tarball
Rob Landley <rob@landley.net>
parents: 220
diff changeset
204 mkdir -p "${SRCDIR}"
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
205
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
206 # For bash: check the $PATH for new executables added after startup.
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
207 set +h
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
208
47
edaa86240321 Turnerize the build script and teach cross-compile.sh to build qemu when
Rob Landley <rob@landley.net>
parents: 41
diff changeset
209 # Are we doing a short build?
edaa86240321 Turnerize the build script and teach cross-compile.sh to build qemu when
Rob Landley <rob@landley.net>
parents: 41
diff changeset
210
edaa86240321 Turnerize the build script and teach cross-compile.sh to build qemu when
Rob Landley <rob@landley.net>
parents: 41
diff changeset
211 if [ "$1" == "--short" ]
edaa86240321 Turnerize the build script and teach cross-compile.sh to build qemu when
Rob Landley <rob@landley.net>
parents: 41
diff changeset
212 then
edaa86240321 Turnerize the build script and teach cross-compile.sh to build qemu when
Rob Landley <rob@landley.net>
parents: 41
diff changeset
213 export BUILD_SHORT=1
edaa86240321 Turnerize the build script and teach cross-compile.sh to build qemu when
Rob Landley <rob@landley.net>
parents: 41
diff changeset
214 shift
edaa86240321 Turnerize the build script and teach cross-compile.sh to build qemu when
Rob Landley <rob@landley.net>
parents: 41
diff changeset
215 fi
edaa86240321 Turnerize the build script and teach cross-compile.sh to build qemu when
Rob Landley <rob@landley.net>
parents: 41
diff changeset
216
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
217 # Get target platform from first command line argument.
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
218
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
219 if [ -z "$NO_ARCH" ]
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
220 then
125
2dd9f480ff4e Set PATH for run-mini-native.sh and add more obvious arch display info when
Rob Landley <rob@landley.net>
parents: 124
diff changeset
221 ARCH_NAME="$1"
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
222 ARCH="$(echo "$1" | sed 's@.*/@@')"
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
223 if [ ! -f "${TOP}/sources/configs/${ARCH}" ]
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
224 then
35
25bfa6ac9f84 Make the "supported architecutes" list have sane line breaks.
Rob Landley <rob@landley.net>
parents: 34
diff changeset
225 echo "Supported architectures: "
25bfa6ac9f84 Make the "supported architecutes" list have sane line breaks.
Rob Landley <rob@landley.net>
parents: 34
diff changeset
226 (cd "${TOP}/sources/configs" && ls)
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
227 exit 1
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
228 fi
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
229
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
230 # Which platform are we building for?
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
231
62
4125b672b00c Get i686 cross-compiling to work like armv4l cross-compiling by lying to
Rob Landley <rob@landley.net>
parents: 60
diff changeset
232 export WORK="${BUILD}/temp-$ARCH"
107
72f414b2939d Have to make the include directory before we can put config files in it.
Rob Landley <rob@landley.net>
parents: 101
diff changeset
233 rm -rf "${WORK}"
72f414b2939d Have to make the include directory before we can put config files in it.
Rob Landley <rob@landley.net>
parents: 101
diff changeset
234 mkdir -p "${WORK}"
62
4125b672b00c Get i686 cross-compiling to work like armv4l cross-compiling by lying to
Rob Landley <rob@landley.net>
parents: 60
diff changeset
235 # Say "unknown" in two different ways so it doesn't assume we're NOT
4125b672b00c Get i686 cross-compiling to work like armv4l cross-compiling by lying to
Rob Landley <rob@landley.net>
parents: 60
diff changeset
236 # cross compiling when the host and target are the same processor. (If host
4125b672b00c Get i686 cross-compiling to work like armv4l cross-compiling by lying to
Rob Landley <rob@landley.net>
parents: 60
diff changeset
237 # and target match, the binutils/gcc/make builds won't use the cross compiler
4125b672b00c Get i686 cross-compiling to work like armv4l cross-compiling by lying to
Rob Landley <rob@landley.net>
parents: 60
diff changeset
238 # during mini-native.sh, and the host compiler links binaries against the
4125b672b00c Get i686 cross-compiling to work like armv4l cross-compiling by lying to
Rob Landley <rob@landley.net>
parents: 60
diff changeset
239 # wrong libc.)
213
1080306ae20e Allow host to be overridden (to build on MacOS X).
Rob Landley <rob@landley.net>
parents: 210
diff changeset
240 [ -z "$CROSS_HOST" ] && export CROSS_HOST=`uname -m`-walrus-linux
1080306ae20e Allow host to be overridden (to build on MacOS X).
Rob Landley <rob@landley.net>
parents: 210
diff changeset
241 [ -z "$CROSS_TARGET" ] && export CROSS_TARGET=${ARCH}-unknown-linux
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
242
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
243 # Read the relevant config file.
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
244
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
245 source "${TOP}/sources/configs/${ARCH}"
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
246
62
4125b672b00c Get i686 cross-compiling to work like armv4l cross-compiling by lying to
Rob Landley <rob@landley.net>
parents: 60
diff changeset
247 # Setup directories and add the cross compiler to the start of the path.
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
248
41
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
249 export CROSS="${BUILD}/cross-compiler-$ARCH"
3baa8ab7ee6d Largeish update.
Rob Landley <rob@landley.net>
parents: 36
diff changeset
250 export NATIVE="${BUILD}/mini-native-$ARCH"
145
b174c242934b Remove redundant $PATH element pointed out by George Boudreau.
Rob Landley <rob@landley.net>
parents: 138
diff changeset
251 export PATH="${CROSS}/bin:$PATH"
108
b66d638a3844 Build User Mode Linux and have that do the ext2 packaging (for now, anyway).
Rob Landley <rob@landley.net>
parents: 107
diff changeset
252 export IMAGE="${BUILD}/image-${ARCH}.ext2"
155
ce1ca3d0f95b Put zImage-$ARCH in build directory, not mini-native-$ARCH, and eliminate
Rob Landley <rob@landley.net>
parents: 145
diff changeset
253
ce1ca3d0f95b Put zImage-$ARCH in build directory, not mini-native-$ARCH, and eliminate
Rob Landley <rob@landley.net>
parents: 145
diff changeset
254
ce1ca3d0f95b Put zImage-$ARCH in build directory, not mini-native-$ARCH, and eliminate
Rob Landley <rob@landley.net>
parents: 145
diff changeset
255 emulator_command image-$ARCH.ext2 zImage-$ARCH \
ce1ca3d0f95b Put zImage-$ARCH in build directory, not mini-native-$ARCH, and eliminate
Rob Landley <rob@landley.net>
parents: 145
diff changeset
256 "rw init=/tools/bin/sh panic=1 PATH=/tools/bin" > "$BUILD/run-$ARCH.sh" &&
ce1ca3d0f95b Put zImage-$ARCH in build directory, not mini-native-$ARCH, and eliminate
Rob Landley <rob@landley.net>
parents: 145
diff changeset
257 chmod +x "$BUILD/run-$ARCH.sh"
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
258 fi
98
b6b4386a6c83 Make host-tools.sh work when run standalone.
Rob Landley <rob@landley.net>
parents: 96
diff changeset
259 mkdir -p "${WORK}"
34
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
260
ad1cfcb043c7 Cleaup pass: Break out shell functions and variable definitions into include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
261 [ -z "$CLEANUP" ] && CLEANUP="rm -rf"
110
62f6268ff61b Build uClibc's readelf and ldd by hand to work around inadequate cross-compile
Rob Landley <rob@landley.net>
parents: 108
diff changeset
262 [ -z "$CC" ] && CC=gcc
182
fc827ab6166f Autodetect number of processors and feed appropriate -j to make.
Rob Landley <rob@landley.net>
parents: 173
diff changeset
263 if [ -z "$CPUS" ]
fc827ab6166f Autodetect number of processors and feed appropriate -j to make.
Rob Landley <rob@landley.net>
parents: 173
diff changeset
264 then
fc827ab6166f Autodetect number of processors and feed appropriate -j to make.
Rob Landley <rob@landley.net>
parents: 173
diff changeset
265 export CPUS=$[$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w)+0]
fc827ab6166f Autodetect number of processors and feed appropriate -j to make.
Rob Landley <rob@landley.net>
parents: 173
diff changeset
266 [ "$CPUS" -lt 1 ] && CPUS=1
fc827ab6166f Autodetect number of processors and feed appropriate -j to make.
Rob Landley <rob@landley.net>
parents: 173
diff changeset
267 fi