-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·160 lines (118 loc) · 4.65 KB
/
build.sh
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
#!/bin/bash
# Architecture to build.
arch=$1
shift
packagedir=$1
shift
oldwd=$PWD
if [ ! -e "packages/$packagedir" ]; then
echo "The package '$packagedir' does not exist." 1>&2
exit 2
fi
if [ -z $ENVPATH ]; then
ENVPATH=$PWD
fi
if [ -L $ENVPATH/environment.sh -o ! -e $ENVPATH/environment.sh ]; then
rm -f $ENVPATH/environment.sh
ln -s $ENVPATH/environment-$arch.sh $ENVPATH/environment.sh
else
echo "environment.sh should not exist as anything other than a symlink, you should have environment-$arch.sh present instead."
fi
source $ENVPATH/environment.sh
mkdir -p $CROSS_BASE/lib/pkgconfig
mkdir -p $BUILD_BASE
mkdir -p $DOWNLOAD_TEMP
mkdir -p $BUILD_BASE/logs
# Make $CROSS_BASE look like a Pedigree layout.
ln -sf $CROSS_BASE/lib $CROSS_BASE/libraries
ln -sf $CROSS_BASE/bin $CROSS_BASE/applications
# Override pkg-config search directory to avoid host environment leaking.
export PKG_CONFIG_LIBDIR=$CROSS_BASE/lib/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=$CROSS_BASE
cd ./packages/$packagedir
bz2="no"
xz="no"
source ./package-info.sh
logfile=$BUILD_BASE/logs/$package-$version-`date +"%Y%m%d-%H%M"`.log
# truncate log file.
: > $logfile
trap "echo Build failed. | tee -a $logfile; rm -rf $BUILD_BASE/build-$package-$version; cd $oldwd; exit 1" INT TERM EXIT
echo "Building $package ($version)..."
echo "Logs are in $logfile."
# Handle the case where there's a special method for obtaining source.
# This script should obtain the source and tarball it, placing it into the path
# specified in $1 with the format $package-$version.tar.gz
if [ -e ./special.sh ]; then
echo " -> Running special method for obtaining source..."
./special.sh $DOWNLOAD_TEMP $ENVPATH >>$logfile 2>&1
fi
rm -rf $BUILD_BASE/build-$package-$version
mkdir -p $BUILD_BASE/build-$package-$version
cd $BUILD_BASE/build-$package-$version
echo " -> Grabbing/extracting source..." | tee -a $logfile
if [ ! -e ./special.sh -a ! -f $DOWNLOAD_TEMP/$package-$version.tar.gz ]; then
wget $url -nv -O $DOWNLOAD_TEMP/$package-$version.tar.gz >> $logfile
fi
cp $DOWNLOAD_TEMP/$package-$version.tar.gz .
tarflags="-xzf"
if [ $bz2 == "yes" ]; then
tarflags="-xjf"
fi
if [ $xz == "yes" ]; then
tarflags="-xJf"
fi
tar $tarflags $package-$version.tar.gz --strip 1
rm $package-$version.tar.gz
echo " -> Patching where necessary" | tee -a $logfile
patches=
patchfiles=`find $SOURCE_BASE/$package/patches -maxdepth 1 -name "*.diff" 2>/dev/null`
numpatches=`echo $patchfiles | wc -l`
if [ ! -z "$patchfiles" ]; then
for f in $patchfiles; do
echo " (applying $f)" | tee -a $logfile
patch -p1 -d $BUILD_BASE/build-$package-$version/ < $f >>$logfile 2>&1
done
patches="#"
fi
patchfiles=`find $SOURCE_BASE/$package/patches/$version -maxdepth 1 -name "*.diff" 2>/dev/null`
numpatches=`echo $patchfiles | wc -l`
if [ ! -z "$patchfiles" ]; then
for f in $patchfiles; do
echo " (applying $version/$f)" | tee -a $logfile
patch -p1 -d $BUILD_BASE/build-$package-$version/ < $f >>$logfile 2>&1
done
patches="#"
fi
if [ -N $patches ]; then
echo " (no patches needed, hooray!)" | tee -a $logfile
fi
set -e
cd $ENVPATH/packages/$package
scripts="./pre-build.sh ./configure.sh ./build.sh ./install.sh ./setupLinks.sh"
phases=( "Pre-build" "Configure" "Build" "Install" "Symlinks" )
phaseNumber=0
for f in $scripts; do
if [ -e $f ]; then
echo " -> "${phases[$phaseNumber]} | tee -a $logfile
$f "$ENVPATH" "$BUILD_BASE/build-$package-$version" $* >>$logfile 2>&1
fi
let "phaseNumber += 1"
done
echo
echo "Package $package ($version) has been built." | tee -a $logfile
# OK to ignore errors should they occur.
set +e
echo "Adding pkgconfig files (if any) to core pkgconfig directory..." | tee -a $logfile
mkdir -p $CROSS_BASE/lib/pkgconfig
[ -e $OUTPUT_BASE/$package/$version/libraries/pkgconfig ] && cp $OUTPUT_BASE/$package/$version/libraries/pkgconfig/* $CROSS_BASE/lib/pkgconfig/
[ -e $OUTPUT_BASE/$package/$version/lib/pkgconfig ] && cp $OUTPUT_BASE/$package/$version/lib/pkgconfig/* $CROSS_BASE/lib/pkgconfig/
[ -e $OUTPUT_BASE/$package/$version/usr/lib/pkgconfig ] && cp $OUTPUT_BASE/$package/$version/usr/lib/pkgconfig/* $CROSS_BASE/lib/pkgconfig/
# Want to break on errors again!
set -e
echo "Registering $package ($version) in the package manager..." | tee -a $logfile
$PACKMAN_PATH makepkg --path $OUTPUT_BASE/$package/$version --repo $PACKMAN_REPO --name $package --ver $version --arch $arch | tee -a $logfile
$PACKMAN_PATH regpkg --repo $PACKMAN_REPO --name $package --ver $version --arch $arch | tee -a $logfile
cd $oldwd
set +e
rm -rf $BUILD_BASE/build-$package-$version
trap - INT TERM EXIT