-
Notifications
You must be signed in to change notification settings - Fork 468
/
build.sh
executable file
·161 lines (142 loc) · 5.49 KB
/
build.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
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
#!/bin/bash
set -e
ARG1_VAL_LOWER="$(echo ${1} | tr [:upper:] [:lower:])"
ARG2_VAL_LOWER="$(echo ${2} | tr [:upper:] [:lower:])"
ARG3_VAL_LOWER="$(echo ${3} | tr [:upper:] [:lower:])"
BUILD_DIR="build"
MAKE_DEB=""
MAKE_RPM=""
MAKE_APPIMAGE=""
BUNDLED_SPDLOG_FMT=""
NO_TESTS=""
RET_VAL=""
[ -d ${BUILD_DIR} ] || mkdir ${BUILD_DIR}
f_any_argument_matches () {
if [ "${ARG1_VAL_LOWER}" == "$1" ] || [ "${ARG2_VAL_LOWER}" == "$1" ] || [ "${ARG3_VAL_LOWER}" == "$1" ]
then
RET_VAL="1"
elif [ -n "$2" ] && ( [ "${ARG1_VAL_LOWER}" == "$2" ] || [ "${ARG2_VAL_LOWER}" == "$2" ] || [ "${ARG3_VAL_LOWER}" == "$2" ] )
then
RET_VAL="2"
elif [ -n "$3" ] && ( [ "${ARG1_VAL_LOWER}" == "$3" ] || [ "${ARG2_VAL_LOWER}" == "$3" ] || [ "${ARG3_VAL_LOWER}" == "$3" ] )
then
RET_VAL="3"
else
RET_VAL=""
fi
}
f_any_argument_matches "help" "--help" "-h"
if [ -n "${RET_VAL}" ]
then
echo "$0 [dbg|debug|rel|release] [notest|notests] [bundledspdfmt] [deb|debian] [rpm] [appimage]"
exit 0
fi
[[ "${MSYSTEM}" =~ "MINGW" ]] && IS_MSYS2_BUILD="Y"
f_any_argument_matches "notests" "notest"
[ -n "${RET_VAL}" ] && NO_TESTS="Y"
f_any_argument_matches "deb" "debian"
[ -n "${RET_VAL}" ] && MAKE_DEB="Y"
f_any_argument_matches "rpm"
[ -n "${RET_VAL}" ] && MAKE_RPM="Y"
f_any_argument_matches "appimage" "appimg"
[ -n "${RET_VAL}" ] && MAKE_APPIMAGE="Y"
f_any_argument_matches "bundledspdlog" "bundledfmt" "bundledspdfmt"
[ -n "${RET_VAL}" ] && BUNDLED_SPDLOG_FMT="Y"
if [ -n "${MAKE_DEB}" ] || [ -n "${MAKE_RPM}" ] || [ -n "${MAKE_APPIMAGE}" ]
then
DEFAULT_BUILD_TYPE="Release"
else
DEFAULT_BUILD_TYPE="Debug"
fi
f_any_argument_matches "debug" "dbg"
if [ -n "${RET_VAL}" ]
then
CMAKE_BUILD_TYPE="Debug"
else
f_any_argument_matches "release" "rel"
[ -n "${RET_VAL}" ] && CMAKE_BUILD_TYPE="Release" || CMAKE_BUILD_TYPE=${DEFAULT_BUILD_TYPE}
fi
echo "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
if [ -f /etc/lsb-release ]
then
DISTRIB_ID="$(grep DISTRIB_ID /etc/lsb-release | awk -F= '{print $2}')"
DISTRIB_RELEASE="$(grep DISTRIB_RELEASE /etc/lsb-release | awk -F= '{print $2}')"
elif [ -f /etc/debian_version ]
then
DISTRIB_ID="Debian"
if grep -q sid /etc/debian_version
then
DISTRIB_RELEASE="$(cat /etc/debian_version | awk -F/ '{print $1}' | tr -d '\n')"
else
DISTRIB_RELEASE="$(cat /etc/debian_version | awk -F. '{print $1}' | tr -d '\n')"
fi
elif [ -f /etc/fedora-release ]
then
DISTRIB_ID="Fedora"
DISTRIB_RELEASE="$(cat /etc/fedora-release | awk '{print $3}' | tr -d '\n')"
elif [ -f /etc/os-release ]
then
DISTRIB_ID="$(grep ^ID= /etc/os-release | awk -F\" '{print $2}')"
DISTRIB_RELEASE="$(grep ^VERSION_ID= /etc/os-release | awk -F\" '{print $2}')"
fi
if [ -n "${DISTRIB_ID}" ] && [ -n "${DISTRIB_RELEASE}" ]
then
echo "Building on ${DISTRIB_ID} ${DISTRIB_RELEASE}"
if [ "${DISTRIB_ID}${DISTRIB_RELEASE}" == "Ubuntu18.04" ] || [ "${DISTRIB_ID}${DISTRIB_RELEASE}" == "Debian10" ]
then
BUNDLED_SPDLOG_FMT="Y"
fi
fi
[ -n "${BUNDLED_SPDLOG_FMT}" ] && EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DUSE_SHARED_FMT_SPDLOG=''"
[[ "$OSTYPE" == "darwin"* ]] && export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig" && NO_TESTS="Y"
if [ -n "${NO_TESTS}" ]
then
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DBUILD_TESTING=''"
else
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DBUILD_TESTING='ON' -DINSTALL_GTEST=''"
fi
cd ${BUILD_DIR}
cmake .. -DCMAKE_C_COMPILER=gcc \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
${EXTRA_CMAKE_FLAGS} -GNinja
[[ "$OSTYPE" == "darwin"* ]] && NUM_JOBS="$(($(sysctl -n hw.ncpu)/2))" || NUM_JOBS="$(($(nproc --all)/2))"
echo "Starting ninja build with up to ${NUM_JOBS} parallel jobs..."
ninja -j ${NUM_JOBS}
if [ -n "${MAKE_DEB}" ]
then
cpack -G DEB
PACKAGE_VERSION="$(grep 'PACKAGE_VERSION ' ../config.h | awk -F\" '{print $2}')"
TARGET_PACKAGE_NAME="cherrytree-${PACKAGE_VERSION}~${DISTRIB_ID}${DISTRIB_RELEASE}_amd64.deb"
mv -v cherrytree-${PACKAGE_VERSION}-Linux.deb ${TARGET_PACKAGE_NAME}
mv -v cherrytree-${PACKAGE_VERSION}-Linux.deb.sha256 ${TARGET_PACKAGE_NAME}.sha256
fi
if [ -n "${MAKE_RPM}" ]
then
cpack -G RPM
PACKAGE_VERSION="$(grep 'PACKAGE_VERSION ' ../config.h | awk -F\" '{print $2}')"
TARGET_PACKAGE_NAME="cherrytree-${PACKAGE_VERSION}~${DISTRIB_ID}${DISTRIB_RELEASE}_amd64.rpm"
mv -v cherrytree-${PACKAGE_VERSION}-Linux.rpm ${TARGET_PACKAGE_NAME}
mv -v cherrytree-${PACKAGE_VERSION}-Linux.rpm.sha256 ${TARGET_PACKAGE_NAME}.sha256
fi
if [ -n "${MAKE_APPIMAGE}" ]
then
# https://github.com/linuxdeploy/linuxdeploy-plugin-gtk
[ -f linuxdeploy-plugin-gtk.sh ] || wget -c "https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh"
[ -f linuxdeploy-x86_64.AppImage ] || wget -c "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
[ -f TinyTeX-1-v2022.04.04.tar.xz ] || wget -c "https://www.giuspen.net/software/TinyTeX-1-v2022.04.04.tar.xz"
chmod +x linuxdeploy-x86_64.AppImage linuxdeploy-plugin-gtk.sh
rm -rf AppDir
mkdir AppDir
tar xf TinyTeX-1-v2022.04.04.tar.xz -C AppDir/
mv AppDir/.TinyTeX AppDir/usr
mkdir -p AppDir/usr/share
[ -d /usr/share/gtksourceview-4 ] && cp -rv /usr/share/gtksourceview-4 AppDir/usr/share/ || echo "!! /usr/share/gtksourceview-4 NOT FOUND !!"
DESTDIR=AppDir ninja install
./linuxdeploy-x86_64.AppImage \
--appdir AppDir \
--plugin gtk \
--output appimage \
--icon-file ../icons/cherrytree.svg \
--desktop-file ../data/cherrytree.desktop
fi