-
Notifications
You must be signed in to change notification settings - Fork 68
/
build
executable file
·118 lines (100 loc) · 2.62 KB
/
build
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
#!/bin/bash
cd "$(dirname "$0")"
SOURCE="http://mirrors.ustc.edu.cn/gnu/libc"
GLIBC_DIR="/glibc"
if [ ! -d "srcs" ]; then
mkdir srcs
fi
if [ ! -d $GLIBC_DIR ]; then
mkdir $GLIBC_DIR
fi
die() {
echo >&2 $1
exit 1
}
usage() {
echo -e >&2 "Usage: $0 version arch\nSupported version:2.19, 2.23-2.29\nSupported arch: i686, amd64"
exit 2
}
download(){
local filename=$1
if [ ! -f srcs/$filename ]; then
wget "$SOURCE/$filename" -O "srcs/$filename"
else
echo "[?] srcs/$filename already exists. remove it to re-download. continue ? (y/[n])"
read opt
if [ "$opt" = "y" ] || [ "$opt" = "Y" ]; then
:
else
die "[*] check src/$filename manually"
fi
fi
}
extract(){
local filepath=$1
local output_dir=$2
if [ ! -f $filepath ]; then
die "[-] Invalid filepath: $filepath"
fi
if [ ! -d $output_dir ]; then
echo "[*] Making directory $output_dir"
mkdir -p $output_dir
cp $filepath $output_dir/src.tar.gz
pushd $output_dir 1>/dev/null
tar xf src.tar.gz
mv */* ./
rm src.tar.gz
popd 1>/dev/null
else
echo "[?] Seems that source code exists in $output_dir. continue ? (y/[n])"
read opt
if [ "$opt" = "y" ] || [ "$opt" = "Y" ]; then
:
else
die "[*] check $output_dir manually"
fi
fi
}
build(){
local arch=$1
local src_dir=$2
local output_dir=$3
if [ ! -d $src_dir ]; then
die "[-] Invalid src_dir: $src_dir"
fi
if [ ! -d $output_dir ]; then
echo "[*] Making directory $output_dir"
mkdir -p $output_dir
fi
pushd $src_dir 1>/dev/null
mkdir build
cd build
if [ $arch = 'amd64' ]; then
../configure --prefix=$output_dir --disable-werror --enable-debug=yes
elif [ $arch = 'i686' ]; then
../configure --prefix=$output_dir --disable-werror --enable-debug=yes --host=i686-linux-gnu --build=i686-linux-gnu CC="gcc -m32" CXX="g++ -m32"
else
die "[-] Invalid arch: $arch"
fi
make
make install
cd ../
rm -rf build
popd 1>/dev/null
}
if [[ $# != 2 ]]; then
usage
fi
echo "[*] checking requirements"
apt-get install gawk bison gcc-multilib g++-multilib -y
GLIBC_VERSION=$1
ARCH=$2
SRC="glibc-$GLIBC_VERSION.tar.gz"
echo "[*] downloading $SRC"
download $SRC
SRC_DIR=$GLIBC_DIR/$GLIBC_VERSION/source
echo "[*] extracting to $SRC_DIR"
extract "srcs/$SRC" $SRC_DIR
echo "[*] building..."
build $ARCH $SRC_DIR $GLIBC_DIR/$GLIBC_VERSION/$ARCH/
echo "[+] build finished. check $GLIBC_DIR/$GLIBC_VERSION/$ARCH/"