-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
216 lines (177 loc) · 5.25 KB
/
Copy pathbuild.sh
File metadata and controls
216 lines (177 loc) · 5.25 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env bash
set -e
# 🧹 Set environment
PYTHON_VERSION=3.13.0
PREFIX_USR=$PWD/python-3.13
OPENSSL_DIR=/usr
export cc=clang
export cxx=clang++
# 🧹 Clean previous
rm -rf $PREFIX_USR
mkdir -p $PREFIX_USR
# 📦 Download Python 3.13 if not present
if [ ! -f Python-${PYTHON_VERSION}.tar.xz ]; then
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
fi
# 🗂️ Extract and enter source
rm -rf Python-${PYTHON_VERSION}
tar xf Python-${PYTHON_VERSION}.tar.xz
cd Python-${PYTHON_VERSION}
# ⚡ Max Optimization flags
export CFLAGS="-fPIC -DANDROID -O3 -march=native -mtune=native -fomit-frame-pointer -pipe -flto"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-Wl,-rpath=/data/data/com.termux/files/usr/lib -flto"
export MAKEFLAGS="-j$(nproc)"
export ax_cv_c_float_words_bigendian=no
# 🧠 Configure with maximum optimizations
./configure \
--prefix=$PREFIX_USR \
--enable-optimizations \
--with-lto \
--enable-shared \
--disable-ipv6 \
--with-openssl=$OPENSSL_DIR \
--disable-test-modules \
ac_cv_file__dev_ptmx=yes \
ac_cv_file__dev_ptc=no \
ac_cv_have_long_long_format=yes \
ac_cv_printf_long_long=yes \
ac_cv_func_lstat_dereferences_slashed_symlink=yes \
ac_cv_func_working_mktime=yes
# 🛠️ Build Python
make
# 📦 Install into PREFIX folder
make install
# 🧹 Clean up
cd ..
echo "✅ Python 3.13 built with max optimizations! Output at: $PREFIX_USR"
# 🎯 Strip binaries (reduce size)
find $PREFIX_USR -type f \( -perm -111 -o -name "*.so" \) -exec strip --strip-unneeded {} +
#####################################
# 📦 Create .deb package 📦
#####################################
echo "📦 Creating DEB package for Termux..."
PKG_NAME="python3.13"
PKG_VERSION="$PYTHON_VERSION"
ARCH="aarch64"
DEB_DIR="$PWD/${PKG_NAME}_$PKG_VERSION"
# 1. Create DEB folder structure
rm -rf $DEB_DIR
mkdir -p $DEB_DIR/DEBIAN
mkdir -p $DEB_DIR/data/data/com.termux/files/usr
# 2. Copy compiled files
cp -a $PREFIX_USR/* $DEB_DIR/data/data/com.termux/files/usr/
# 3. Create control file
cat > $DEB_DIR/DEBIAN/control <<EOF
Package: $PKG_NAME
Version: $PKG_VERSION
Architecture: $ARCH
Maintainer: Cross-compiled by Shoaib Hassan
Description: Highly optimized Python 3.13 cross-compiled for Termux aarch64.
EOF
# 4. Create empty postinst script
cat > $DEB_DIR/DEBIAN/postinst <<EOF
# 🧹 Set environment
PYTHON_VERSION=3.13.0
PREFIX_USR=$PWD/python-3.13
OPENSSL_DIR=/usr
export cc=clang
export cxx=clang++
# 🧹 Clean previous
rm -rf $PREFIX_USR
mkdir -p $PREFIX_USR
=======
PYTHON_VERSION=3.13.0
ARCH=aarch64
PKG_NAME=python3.13
DEB_DIR="${PKG_NAME}_${PYTHON_VERSION}"
PREFIX_USR=$(pwd)/python-android
# Install dependencies (for local use; skip if running in CI with pre-installed deps)
if ! command -v aarch64-linux-gnu-gcc &>/dev/null; then
echo "Installing required packages..."
sudo apt update
sudo apt install -y \
clang \
crossbuild-essential-arm64 \
dpkg-dev \
build-essential \
wget \
libffi-dev \
libbz2-dev \
libssl-dev \
libncurses-dev \
libreadline-dev \
zlib1g-dev \
xz-utils
fi
# Clean up
rm -rf "$PREFIX_USR" "$DEB_DIR"
mkdir -p "$PREFIX_USR"
# Download Python source
if [ ! -f Python-${PYTHON_VERSION}.tar.xz ]; then
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
fi
tar xf Python-${PYTHON_VERSION}.tar.xz
cd Python-${PYTHON_VERSION}
# Cross-compilation environment
export CC=aarch64-linux-gnu-clang
export CXX=aarch64-linux-gnu-clang++
export AR=aarch64-linux-gnu-ar
export RANLIB=aarch64-linux-gnu-ranlib
export STRIP=aarch64-linux-gnu-strip
export READELF=aarch64-linux-gnu-readelf
export CFLAGS="--target=aarch64-linux-gnu -fPIC -O2"
export LDFLAGS="--target=aarch64-linux-gnu"
# Configure Python
./configure \
--host=aarch64-linux-gnu \
--build=$(uname -m)-linux-gnu \
--prefix="$PREFIX_USR" \
--enable-shared \
--disable-ipv6 \
ac_cv_file__dev_ptmx=yes \
ac_cv_file__dev_ptc=no \
ac_cv_func_working_mktime=yes \
ac_cv_have_long_long_format=yes \
ac_cv_printf_long_long=yes \
ac_cv_func_lstat_dereferences_slashed_symlink=yes \
CC="$CC" \
CXX="$CXX" \
AR="$AR" \
RANLIB="$RANLIB" \
STRIP="$STRIP" \
CFLAGS="$CFLAGS" \
LDFLAGS="$LDFLAGS"
make -j$(nproc)
make install
# Strip binaries
find "$PREFIX_USR" -type f \( -name "*.so" -o -perm -111 \) -exec "$STRIP" --strip-unneeded {} + || true
cd ..
# Create DEB package structure
mkdir -p "$DEB_DIR/DEBIAN"
mkdir -p "$DEB_DIR/data/data/com.termux/files/usr"
cp -a "$PREFIX_USR"/* "$DEB_DIR/data/data/com.termux/files/usr/"
# Create control file
cat > "$DEB_DIR/DEBIAN/control" <<EOF
Package: $PKG_NAME
Version: $PYTHON_VERSION
Architecture: $ARCH
Maintainer: Termux Cross-Builder
Description: Python $PYTHON_VERSION cross-compiled for Termux (aarch64)
EOF
chmod 0755 "$DEB_DIR/DEBIAN"
chmod 0644 "$DEB_DIR/DEBIAN/control"
# Build DEB
dpkg-deb --build "$DEB_DIR"
echo "✅ DEB package created: ${DEB_DIR}.deb"
ash
EOF
# 5. Set correct permissions
chmod 0755 $DEB_DIR/DEBIAN
chmod 0644 $DEB_DIR/DEBIAN/control
chmod 0755 $DEB_DIR/DEBIAN/postinst
# 6. Build .deb package
dpkg-deb --build $DEB_DIR
echo "✅ DEB package created: ${DEB_DIR}.deb"
=======
echo "✅ Done: DEB package created at ${DEB_DIR}.deb"