-
Notifications
You must be signed in to change notification settings - Fork 3
/
BUILDING
257 lines (210 loc) · 8.99 KB
/
BUILDING
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
BUILD INSTRUCTIONS:
- Android SDK and NDK
- 7Zip command line '7z'
# ############################################################################
# Typically in ~/.bashrc
# ############################################################################
export JAVA_HOME=/cygdrive/c/d/jdk/
export PATH=${JAVA_HOME}/bin:${PATH}
SDK=/cygdrive/c/d/sdk
NDK=${SDK}/ndk/26.2.11394342
export TOOLCHAIN=${NDK}/toolchains/llvm/prebuilt/windows-x86_64
export PATH=${SDK}/platform-tools:${TOOLCHAIN}/bin:${PATH}
# ############################################################################
# Step 1 - Setting up the toolchain
# ############################################################################
# From the root dir with the tarball
export SRC_ROOT=`pwd`
# TOOLCHAIN is expected to point to your ndk environment toolchain.
[ -n "${TOOLCHAIN}" ] || { echo "TOOLCHAIN must be set"; exit 1; }
if [ ! -d "$NDK" ]; then
echo "$NDK does not exist."
return
fi
# Set this to your minSdkVersion.
export API=26
echo "Only choose one of these, depending on your device..."
echo "1) aarch64-linux-android ... which is most likely this one"
echo "2) armv7a-linux-androideabi"
echo "3) i686-linux-android"
echo "4) x86_64-linux-android"
echo -n "Select target: "
read REPLY
case $REPLY in
"1")
export TARGET=aarch64-linux-android
;;
"2")
export TARGET=armv7a-linux-androideabi
;;
"3")
export TARGET=i686-linux-android
;;
"4")
export TARGET=x86_64-linux-android
;;
esac
echo "TARGET=${TARGET}"
echo "API=${API}"
export AR=${TOOLCHAIN}/bin/llvm-ar
export CC=${TOOLCHAIN}/bin/${TARGET}${API}-clang
export AS=${CC}
export CXX=${TOOLCHAIN}/bin/${TARGET}${API}-clang++
export LD=${TOOLCHAIN}/bin/ld
export RANLIB=${TOOLCHAIN}/bin/llvm-ranlib
export STRIP=${TOOLCHAIN}/bin/llvm-strip
# content for ".gitattributes"
export GATRR="* text eol=lf\n*.txt text\n*.png binary\n"
# ############################################################################
# Step 2.1 - RSYNC - https://rsync.samba.org/
# https://download.samba.org/pub/rsync/src/rsync-3.3.0.tar.gz
# ############################################################################
# replace base filename in the below string after download:
export RSYNC_VERSION="rsync-3.3.0"
cd ${SRC_ROOT}
7z x -so ${RSYNC_VERSION}* | tar xf -
# remove broken and/or unneeded rsync symlink
rm ${RSYNC_VERSION}/md2man
# rename the directory so we don't need to change the git remote names
export RSYNC="upstream-rsync"
# Prep rsync
mkdir -p ${RSYNC}/app/src/main/cpp/
mv ${RSYNC_VERSION} ${RSYNC}/app/src/main/cpp/rsync
cd ${RSYNC}
echo -e "${GATRR}" >.gitattributes
git init .
git add * .gitattributes
git commit -a -m "${RSYNC_VERSION}"
cd ${SRC_ROOT}
# Configure rsync
cd ${SRC_ROOT}/${RSYNC}/app/src/main/cpp/rsync
./configure --host $TARGET --disable-openssl --disable-xxhash --disable-zstd --disable-lz4 \
--disable-md2man --disable-roll-simd --disable-md5-asm --disable-roll-asm \
--enable-largefile
cd ${SRC_ROOT}
# Add remote: "upstream-rsync" pointing to the location used above
git remote add upstream-rsync c:/tmp/sshd4a-tarballs/upstream-rsync
git fetch upstream-rsync
git merge --allow-unrelated-histories upstream-rsync/dev
# All changes are (should be) marked with SSHD4A_*
# Merge and solve conflicts as usual.
cd ${SRC_ROOT}/${RSYNC}/app/src/main/cpp/
./prebuild-rsyn.sh
# Update gradle.build: android.defaultConfig buildConfigField("String", "VERSION_RSYNC"...
# Commit and build...
# ############################################################################
# Step 2.2 - OPENSSH - https://github.com/openssh/openssh-portable
# https://mirror.ox.ac.uk/pub/OpenBSD/OpenSSH/portable/openssh-9.7p1.tar.gz
# ############################################################################
# replace base filename in the below string after download:
export OPENSSH_VERSION="openssh-9.7p1"
cd ${SRC_ROOT}
7z x -so ${OPENSSH_VERSION}* | tar xf -
# rename the directory so we don't need to change the git remote names
export OPENSSH="upstream-openssh"
# Prep openssh
mkdir -p ${OPENSSH}/app/src/main/cpp/
mv ${OPENSSH_VERSION} ${OPENSSH}/app/src/main/cpp/openssh
cd ${OPENSSH}
echo -e "${GATRR}" >.gitattributes
git init .
git add * .gitattributes
git commit -a -m "${OPENSSH_VERSION}"
cd ${SRC_ROOT}
# Configure openssh
cd ${SRC_ROOT}/${OPENSSH}/app/src/main/cpp/openssh
# autoreconf is normally in /usr/bin
autoreconf
./configure --host $TARGET --disable-lastlog --disable-utmp --disable-wtmp \
--enable-largefile --without-openssl
cd ${SRC_ROOT}
# Add remote: "upstream-openssh" pointing to the location used above
git remote add upstream-openssh c:/tmp/sshd4a-tarballs/upstream-openssh
git fetch upstream-openssh
git merge --allow-unrelated-histories upstream-openssh/dev
# All changes are (should be) marked with SSHD4A_*
# Merge and solve conflicts as usual.
# Update gradle.build: android.defaultConfig buildConfigField("String", "VERSION_OPENSSL"...
# Commit and build...
# ############################################################################
# Step 2.3 - DROPBEAR - https://matt.ucc.asn.au/dropbear/dropbear.html
# https://matt.ucc.asn.au/dropbear/dropbear-2024.85.tar.bz2
# ############################################################################
# replace base filename in the below string after download:
export DROPBEAR_VERSION="dropbear-2024.85"
cd ${SRC_ROOT}
7z x -so ${DROPBEAR_VERSION}* | tar xf -
# rename the directory so we don't need to change the git remote names
export DROPBEAR="upstream-dropbear"
# Prep dropbear
mkdir -p ${DROPBEAR}/app/src/main/cpp/
mv ${DROPBEAR_VERSION} ${DROPBEAR}/app/src/main/cpp/dropbear
cd ${DROPBEAR}
echo -e "${GATRR}" >.gitattributes
git init .
# ignore warnings about txt files in "rsa-testvectors"
git add * .gitattributes
git commit -a -m "${DROPBEAR_VERSION}"
cd ${SRC_ROOT}
# Configure dropbear
cd ${SRC_ROOT}/${DROPBEAR}/app/src/main/cpp/dropbear
./configure --host $TARGET --disable-syslog --disable-lastlog \
--disable-utmp --disable-wtmp \
--enable-bundled-libtom --enable-largefile
cd ${SRC_ROOT}
# Add remote: "upstream-dropbear" pointing to the location used above
git remote add upstream-dropbear c:/tmp/sshd4a-tarballs/upstream-dropbear
git fetch upstream-dropbear
git merge --allow-unrelated-histories upstream-dropbear/dev
# All changes are (should be) marked with SSHD4A_*
# Merge and solve conflicts as usual.
cd ${SRC_ROOT}/${DROPBEAR}/app/src/main/cpp
./prebuild-dropbear.sh
# Update gradle.build: android.defaultConfig buildConfigField("String", "VERSION_DROPBEAR"...
# Commit and build...
# ############################################################################
config.h changes - should not be needed to reapply these after a code drop
as the config.h should be untouched.
------------------------------------------------------------------------------
# ${SRC_ROOT}/${RSYNC}/app/src/main/cpp/rsync/config.h
------------------------------------------------------------------------------
- armv7: extra "#define _FILE_OFFSET_BITS 64"
which can be added to the 64 bit versions without any issue. Done.
- armv7 versus 64 using #if defined(__aarch64__) || defined(__x86_64__ ) ...
#define HAVE_LONG_DOUBLE 1 <==> absent
#define HAVE_LONG_DOUBLE_WIDER 1 <==> absent
#define SIZEOF_CHARP 8 <==> 4
#define SIZEOF_LONG 8 <==> 4
#define SIZEOF_TIME_T 8 <==> 4
------------------------------------------------------------------------------
# ${SRC_ROOT}/${RSYNC}/app/src/main/cpp/dropbear/config.h
------------------------------------------------------------------------------
- aarch64 and x86_64 were identical
- armv7: extra "#define _FILE_OFFSET_BITS 64"
which can be added to the 64 bit versions without any issue. Done.
------------------------------------------------------------------------------
# ${SRC_ROOT}/${RSYNC}/app/src/main/cpp/openssh/config.h
------------------------------------------------------------------------------
- aarch64 and x86_64 were identical
- armv7: extra "#define _FILE_OFFSET_BITS 64"
which can be added to the 64 bit versions without any issue. Done.
- armv7 versus 64 using #if defined(__aarch64__) || defined(__x86_64__ ) ...
#define SIZEOF_LONG_INT 8 <=> 4
#define SIZEOF_TIME_T 8 <=> 4
- added manually:
// configure presumes openbsd only, but android needs it.
#define HAVE_ATTRIBUTE__SENTINEL__ 1
// configure fails to find it due to android using an "#include_next"
#define HAVE_MALLOC 1
// see "openbsd-compat/explicit_bzero.c" workaround
#define HAVE_BZERO 1
# ############################################################################
Setup signing:
Edit your "~/.gradle/gradle.properties" and add a line:
Sshd4a.properties=/path/to/Sshd4a.properties
Edit/create the file "/path/to/Sshd4a.properties":
sign.storeFile=/path/to/myKeystore.jks
sign.storePassword=myPass
sign.keyAlias=myAlias
sign.keyPassword=myPass
# ############################################################################