-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.sh
More file actions
214 lines (183 loc) · 6.39 KB
/
Copy pathbuild.sh
File metadata and controls
214 lines (183 loc) · 6.39 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
#!/bin/bash -i
# This scrip can be used to build PdfiumAndroid library and its dependent libraries(libpng and libfreetype2).
check_required_tools() {
# Check for cmake
if ! command -v cmake &> /dev/null; then
echo "Error: cmake is not installed or not in PATH"
echo "Please install cmake using one of the following methods:"
echo " - macOS: brew install cmake"
echo " - Ubuntu/Debian: sudo apt-get install cmake"
echo " - Or download from https://cmake.org/download/"
exit 1
fi
# Check for git
if ! command -v git &> /dev/null; then
echo "Error: git is not installed or not in PATH"
echo "Please install git to continue"
exit 1
fi
# Check for wget
if ! command -v wget &> /dev/null; then
echo "Error: wget is not installed or not in PATH"
echo "Please install wget to continue"
exit 1
fi
}
# Set NDK_ROOT if not already set
if [ -z "${NDK_ROOT}" ]; then
echo "Error: NDK_ROOT environment variable is not set."
echo "Please set NDK_ROOT to point to your Android NDK installation."
echo "Example: export NDK_ROOT=/path/to/android-ndk"
exit 1
fi
# Check for required tools before proceeding
check_required_tools
export BUILD_ROOT="builddir"
rm -fr ${BUILD_ROOT}
# LIST OF ARCHS TO BE BUILT.
if [ -z "${BUILD_ARCHS}" ]; then
# If no environment variable is defined, use all archs.
BUILD_ARCHS="x86 armeabi-v7a x86_64 arm64-v8a"
fi
check_command_result() {
local exit_code=$?
local command=$1
echo "exit code = ${exit_code}"
if [ ${exit_code} -ne 0 ]; then
echo "${command} failed. Exiting."
exit 1
fi
}
build_libpng() {
rm -fr libpng
git clone https://github.com/pnggroup/libpng
cd libpng
git checkout v1.6.44
cd ..
for ABI in ${BUILD_ARCHS}; do
export BUILD_DIR=${BUILD_ROOT}/libpng/${ABI}
rm -fr ${BUILD_DIR} &&
cmake -B ${BUILD_DIR} -S libpng \
-DCMAKE_ANDROID_NDK=${NDK_ROOT} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_ARCH_ABI=${ABI} \
-DBUILD_SHARED_LIBS:BOOL=true \
-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON \
-DANDROID_ABI=${ABI} \
-DCMAKE_SYSTEM_NAME=Android
check_command_result "configuring libpng"
cmake --build ${BUILD_DIR} -j10
check_command_result "building libpng"
ls -lh ${BUILD_DIR}/*.so
cp ${BUILD_DIR}/libpng16.so src/main/jni/lib/${ABI}/libmodpng.so
done
}
build_libfreetype2() {
FREETYPE_VERSION=2.13.3
rm -fr freetype-${FREETYPE_VERSION}.tar.gz freetype-${FREETYPE_VERSION}
wget https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.gz
tar -xvzf freetype-${FREETYPE_VERSION}.tar.gz
export SRC_DIR=freetype-${FREETYPE_VERSION}
for ABI in ${BUILD_ARCHS}; do
export BUILD_DIR=${BUILD_ROOT}/${SRC_DIR}/${ABI}
rm -fr ${BUILD_DIR} &&
cmake -B ${BUILD_DIR} -S ${SRC_DIR} \
-DCMAKE_ANDROID_NDK=${NDK_ROOT} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_ARCH_ABI=${ABI} \
-DBUILD_SHARED_LIBS:BOOL=true \
-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON \
-DANDROID_ABI=${ABI} \
-DCMAKE_SYSTEM_NAME=Android
check_command_result "configuring freetype"
cmake --build ${BUILD_DIR} -j10
check_command_result "building freetype"
ls -lh ${BUILD_DIR}/*.so
cp ${BUILD_DIR}/libfreetype.so src/main/jni/lib/${ABI}/libmodft2.so
done
}
build_pdfiumAndroid() {
for ABI in ${BUILD_ARCHS}; do
cmake -B ${BUILD_ROOT}/pdfiumAndroid/${ABI}/ \
-S . \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_NDK=${NDK_ROOT} \
-DCMAKE_ANDROID_NDK=${NDK_ROOT} \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_ANDROID_ARCH_ABI=${ABI} \
-DANDROID_ABI=${ABI} \
-DANDROID_PLATFORM=android-26 \
-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON
check_command_result "configuring pdfiumAndroid"
cmake --build ${BUILD_ROOT}/pdfiumAndroid/${ABI}/ -j10
check_command_result "building pdfiumAndroid"
done
}
deploy_to_mega() {
local mega_path=$1
target_folder=${mega_path}/sdk/src/main/jniLibs
for ABI in ${BUILD_ARCHS}; do
cp -fv src/main/jni/lib/${ABI}/libmodpng.so ${target_folder}/${ABI}/
cp -fv src/main/jni/lib/${ABI}/libmodft2.so ${target_folder}/${ABI}/
cp -fv src/main/jni/lib/${ABI}/libmodpdfium.so ${target_folder}/${ABI}/
cp -fv src/main/jni/lib/${ABI}/libmodpdfium.so ${target_folder}/${ABI}/
cp -fv builddir/pdfiumAndroid/${ABI}/libjniPdfium.so ${target_folder}/${ABI}/
done
}
print_usage() {
echo "Build script for PdfiumAndroid library and its dependent libraries(libpng and libfreetype2)."
echo " And deploy the library to MEGA code directly."
echo "Usage: $0 [options]"
echo "Example 1: build everything and deploy to MEGA code"
echo " bash build.sh --build-png --build-freetype --deploy-to-mega /PATH/TO/MEGA/CODE"
echo "Example 2: build only pdfiumAndroid and deploy to MEGA code"
echo " bash build.sh --deploy-to-mega /PATH/TO/MEGA/CODE"
echo "Options:"
echo " --build-png [Optional] Build libpng"
echo " --build-freetype [Optional] Build libfreetype2"
echo " --deploy-to-mega <path> [Optional] Deploy to the specified MEGA code path"
echo " --help Display this help message"
}
# Parse optional parameters
BUILD_PNG=false
BUILD_FREETYPE=false
MEGA_CODE_PATH=""
for arg in "$@"; do
case $arg in
--build-png)
BUILD_PNG=true
shift
;;
--build-freetype)
BUILD_FREETYPE=true
shift
;;
--deploy-to-mega)
MEGA_CODE_PATH="$2"
shift 2
;;
--help)
print_usage
exit 0
;;
esac
done
# Call the functions based on the parameters
if [ "$BUILD_PNG" = true ]; then
echo "building libpng"
build_libpng
fi
if [ "$BUILD_FREETYPE" = true ]; then
echo "building freetype"
build_libfreetype2
fi
build_pdfiumAndroid
if [ -n "$MEGA_CODE_PATH" ]; then
if [ -d "$MEGA_CODE_PATH" ]; then
deploy_to_mega "$MEGA_CODE_PATH"
else
echo "Directory $MEGA_CODE_PATH does not exist."
exit 1
fi
fi
echo "Build finished Ok"