-
Notifications
You must be signed in to change notification settings - Fork 110
/
build-unix.sh
executable file
·134 lines (126 loc) · 4.11 KB
/
build-unix.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
#!/usr/bin/env sh
# -----------------------------------------------------------------------------
# Name: CAJ2PDF Qt
# Description: CAJ 转 PDF 转换器
# Author: Sainnhe Park <i@sainnhe.dev>
# Website: https://caj2pdf-qt.sainnhe.dev
# License: GPL3
# -----------------------------------------------------------------------------
# 项目根目录
BASEDIR="$( cd "$( dirname "$0" )" && pwd )"
cd "${BASEDIR}"
# 初始化 Git 仓库,清理缓存,检查依赖
_init() {
if [ "$(uname)" = Darwin ]; then
git submodule update --init --recursive caj2pdf mupdf
else
git submodule update --init --recursive caj2pdf
fi
git clean -dfx -- .
cd "${BASEDIR}/caj2pdf"
git clean -dfx -- .
git checkout -- .
cd "${BASEDIR}/mupdf"
git clean -dfx -- .
git checkout -- .
[ -x "$(command -v cc)" ] || echo "C compiler not found"
[ -x "$(command -v c++)" ] || echo "C++ compiler not found"
[ -x "$(command -v git)" ] || echo "Command 'git' not found"
[ -x "$(command -v python3)" ] || echo "Command 'python3' not found"
[ -x "$(command -v cmake)" ] || echo "Command 'cmake' not found"
[ -x "$(command -v make)" ] || echo "Command 'make' not found"
[ -x "$(command -v pkg-config)" ] || echo "Command 'pkg-config' not found"
pkg-config --cflags jbig2dec &> /dev/null || echo "Can't find jbig2dec"
[ -x "$(command -v qmake)" ] || echo "Qt not installed"
if [ "$(uname)" = Darwin ]; then
[ -x "$(command -v macdeployqt)" ] || echo "Command 'macdeployqt' not found"
else
[ -x "$(command -v mutool)" ] || echo "Command 'mutool' not found"
fi
}
# 构建 caj2pdf 命令行版本
_cli() {
cd "${BASEDIR}/caj2pdf"
git clean -dfx -- .
git checkout -- .
cd "${BASEDIR}/caj2pdf/lib"
cc -Wall -fPIC --shared -o libjbigdec.so jbigdec.cc JBigDecode.cc
cc -Wall `pkg-config --cflags jbig2dec` -fPIC -shared -o libjbig2codec.so decode_jbig2data_x.cc `pkg-config --libs jbig2dec`
cd "${BASEDIR}/caj2pdf"
git apply ../patches/caj2pdf.diff
python3 -m venv venv
"${BASEDIR}/caj2pdf/venv/bin/python" -m pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
"${BASEDIR}/caj2pdf/venv/bin/python" -m pip install pyinstaller -i https://mirrors.aliyun.com/pypi/simple
"${BASEDIR}/caj2pdf/venv/bin/pyinstaller" -F caj2pdf
git checkout -- .
}
# 构建 mupdf
_mupdf() {
cd "${BASEDIR}/mupdf"
git clean -dfx -- .
git checkout -- .
git apply ../patches/mupdf.diff
if [ -x "$(command -v nproc)" ]; then
make --jobs=$(nproc) release
elif [ -x "$(command -v gnproc)" ]; then
make --jobs=$(gnproc) release
else
make release
fi
git checkout -- .
}
# 构建 qt
_qt() {
cd "${BASEDIR}"
rm -rf build
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ..
if [ -x "$(command -v nproc)" ]; then
cmake --build . --parallel $(nproc)
elif [ -x "$(command -v gnproc)" ]; then
cmake --build . --parallel $(gnproc)
else
cmake --build .
fi
}
# 打包程序
_package() {
cd "${BASEDIR}"
rm -rf dist
mkdir dist
if [ "$(uname)" = Darwin ]; then
cp -r build/caj2pdf.app dist/
macdeployqt dist/caj2pdf.app
mkdir dist/caj2pdf.app/Contents/MacOS/external
cp mupdf/build/release/mutool dist/caj2pdf.app/Contents/MacOS/external/
cp caj2pdf/dist/caj2pdf dist/caj2pdf.app/Contents/MacOS/external/
cp caj2pdf/lib/*.so dist/caj2pdf.app/Contents/MacOS/external/
cp icons/convert.icns dist/caj2pdf.app/Contents/Resources/
else
cp build/caj2pdf dist/
mkdir dist/external
ln -s $(which mutool) dist/external/
cp caj2pdf/dist/caj2pdf dist/external/
cp caj2pdf/lib/*.so dist/external/
fi
}
if [ "${1}" = init ]; then
_init
elif [ "${1}" = cli ]; then
_cli
elif [ "${1}" = mupdf ]; then
_mupdf
elif [ "${1}" = qt ]; then
_qt
elif [ "${1}" = package ]; then
_package
else
_init
_cli
if [ "$(uname)" = Darwin ]; then
_mupdf
fi
_qt
_package
fi