forked from ryancog/ProffieConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·306 lines (262 loc) · 8.86 KB
/
Copy pathinit.sh
File metadata and controls
executable file
·306 lines (262 loc) · 8.86 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
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#!/bin/sh
# ProffieConfig, All-In-One Proffieboard Management Utility
# Copyright (C) 2024 Ryan Ogurek
ROOT_DIR=`dirname -- \` readlink -f -- "$0" \``
cd $ROOT_DIR
echo "Detecting platform..."
if [ "$OSTYPE" == "linux-gnu" ]; then
BUILD_PLATFORM=linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
BUILD_PLATFORM=macOS
else
echo "Unsupported build platform: $OSTYPE"
exit 1
fi
echo "Platform: ${BUILD_PLATFORM}"
if [ "$1" == "--CROSS_WIN32" ]; then
TARGET_PLATFORM=win32
else
TARGET_PLATFORM=${BUILD_PLATFORM}
fi
if [ "${TARGET_PLATFORM}" != "${BUILD_PLATFORM}" ]; then echo "Target Platform: ${TARGET_PLATFORM}"; fi
if [ "${TARGET_PLATFORM}" == "macOS" ]; then
export CXXFLAGS="-mmacosx-version-min=11.0"
export CFLAGS="-mmacosx-version-min=11.0"
export LDFLAGS="-mmacosx-version-min=11.0"
fi
check_exec() {
if [ ! -z "$2" ] && [ "$BUILD_PLATFORM" != "$2" ]; then
return
fi
if ! command -v $1 &> /dev/null; then
echo "Err: ${1} is missing, please install it!"
exit 1
fi
}
# Linux, macOS, Windows
SWITCH_VAL=""
platform_switch() {
if [ "$TARGET_PLATFORM" == "linux" ]; then
SWITCH_VAL=$1
elif [ "$TARGET_PLATFORM" == "macOS" ]; then
SWITCH_VAL=$2
elif [ "$TARGET_PLATFORM" == "win32" ]; then
SWITCH_VAL=$3
fi
}
check_exec chrpath linux
check_exec otool macOS
check_exec git
check_exec libtool
check_exec automake
check_exec autoconf
check_exec autogen
check_exec nasm
do_with_log() {
# 1: Human process name
# 2: Command
# 3: log
echo " ${1}..."
if ! ${2} &> ${3}.log; then
echo "Error! Check ${3}.log."
exit 1
fi
}
patch_rpaths() {
if [ "$TARGET_PLATFORM" == "linux" ]; then
for lib in `ls -1 | grep '.*.so.*'`; do
if ! [ -L ${lib} ]; then
SONAME=`readelf -d ${lib} | grep SONAME | sed -n 's/.*\[\([^]]*\)\].*/\1/p'`
mv -f ${lib} ${SONAME}
ln -sf ${SONAME} `echo ${SONAME} | sed -n 's/\(lib.*\.so\).*/\1/p'`
chrpath -r '$ORIGIN/../lib' $SONAME &> /dev/null
else
rm ${lib}
fi
done
elif [ "$TARGET_PLATFORM" == "macOS" ]; then
# set install_name of libs correctly
#
# Basically it's just changing the link names of all the libs (and their dependencies) to @rpath/[name] that way
# the install location can be dynamically changed when building the actual application(s).
WX_LIBNAMES=`ls -1 | grep '.*\.dylib$'`
for lib in ${WX_LIBNAMES}; do
if ! [ -L $lib ]; then
NEWNAME=`otool -D ${lib} | sed -n '2s/.*\/\(lib[A-Za-z\_]*\).*/\1.dylib/p'`
mv -f ${lib} $NEWNAME
install_name_tool -id @rpath/${NEWNAME} ${NEWNAME}
for dep in `otool -L ${NEWNAME} | grep '/libwx' | sed -n 's/\t\(.*\) (.*/\1/p'`; do
CLEANED_DEP_NAME=`echo "${dep}" | sed -n 's/.*\/\(lib[A-Za-z\_]*\).*/\1.dylib/p'`
install_name_tool -change ${dep} @rpath/${CLEANED_DEP_NAME} ${NEWNAME}
done
else
rm ${lib}
fi
done
fi
}
echo "Initializing 3rd party repositories..."
git submodule update --init
echo "Setting up libtomcrypt..."
cd 3rdparty/tomcrypt
platform_switch "build-linux" "build-macOS" "build-win32"
if [ -d $SWITCH_VAL ]; then
echo "Tomcrypt already built, skipping! (Remove 'build' directory to reset)"
else
unset CROSS_COMPILE
if [ "$TARGET_PLATFORM" == "win32" ]; then
export CROSS_COMPILE=x86_64-w64-mingw32.static-
fi
make clean &> /dev/null
# OLD_CFLAGS=$CFLAGS
# OLD_CXXFLAGS=$CXXFLAGS
# if [ "${TARGET_PLATFORM}" == "macOS" ]; then
# export CFLAGS="${OLD_CFLAGS} -arch x86_64"
# export CXXFLAGS="${OLD_CXXFLAGS} -arch x86_64"
# fi
OLD_LDFLAGS=$LDFLAGS
export LDFLAGS="${OLD_LDFLAGS} -s"
do_with_log \
"Building shared" \
"make -f makefile.shared -j`nproc --all`" \
build
export LDFLAGS=$OLD_LDFLAGS
do_with_log \
"Building static" \
"make -j`nproc --all`" \
build
# if [ "${TARGET_PLATFORM}" == "macOS" ]; then
# export CFLAGS="${OLD_CFLAGS} -arch arm64"
# export CXXFLAGS="${OLD_CXXFLAGS} -arch arm64"
# mv libtomcrypt.dylib libtomcrypt_x86_64.dylib
# mv libtomcrypt.a libtomcrypt_x86_64.a
# export LDFLAGS="-s"
# do_with_log \
# "Building shared for arm" \
# "make -f makefile.shared -j`nproc --all`" \
# build
# unset LDFLAGS
# do_with_log \
# "Building static for arm" \
# "make -j`nproc --all`" \
# build
# export CFLAGS=$OLD_CFLAGS
# export CXXFLAGS=$OLD_CXXFLAGS
# fi
mkdir -p $SWITCH_VAL
if [ "$TARGET_PLATFORM" == "win32" ]; then
unset CROSS_COMPILE
mv tomcrypt.dll build-win32/tomcrypt.dll
mv libtomcrypt.a build-win32/libtomcrypt.a
elif [ "$TARGET_PLATFORM" == "linux" ]; then
mv libtomcrypt.so build-linux/libtomcrypt.so
mv libtomcrypt.a build-linux/libtomcrypt.a
elif [ "$TARGET_PLATFORM" == "macOS" ]; then
mv libtomcrypt.dylib build-macOS/libtomcrypt.dylib
mv libtomcrypt.a build-macOS/libtomcrypt.a
# lipo -create -output build-macOS/libtomcrypt.dylib libtomcrypt.dylib libtomcrypt_x86_64.dylib
# lipo -create -output build-macOS/libtomcrypt.a libtomcrypt.a libtomcrypt_x86_64.a
echo " Patching tomcrypt lib with @rpath..."
install_name_tool -id "@rpath/libtomcrypt.dylib" build-macOS/libtomcrypt.dylib
fi
fi
cd $ROOT_DIR
# echo "Setting up ffmpeg..."
# cd 3rdparty/ffmpeg
#
# if [ -d install-${TARGET_PLATFORM} ]; then
# echo "ffmpeg already built, skipping! (Remove install-${TARGET_PLATFORM} to reset)"
# else
# do_with_log \
# "Configuring" \
# "./configure --disable-programs --disable-doc --disable-static --enable-shared --enable-rpath --disable-filters --disable-bsfs --disable-network --disable-indevs --disable-outdevs --disable-protocols --enable-protocol=file --enable-lto --prefix=`pwd`/install-${TARGET_PLATFORM}" \
# configure
#
# do_with_log \
# "Building" \
# "make -j`nproc --all`" \
# build
#
# do_with_log \
# "Installing" \
# "make install" \
# install
#
# platform_switch "install-linux/lib" "" ""
# cd $SWITCH_VAL
# patch_rpaths
# fi
# cd $ROOT_DIR
echo "Preparing wxWidgets..."
cd 3rdparty/wxWidgets
do_with_log \
"Initializing repository" \
"git submodule update --init" \
repoinit
WX_INSTALL_PREFIX=`pwd`/install-$TARGET_PLATFORM
# Use --enable-debug if needed
WX_FLAGS='--without-opengl --disable-unsafe-conv-in-wxstring --disable-sys-libs --with-macosx-version-min=11.0'
if [ "$TARGET_PLATFORM" == "linux" ]; then
WX_HOST='x86_64-linux'
WX_PLATFORM_FLAGS='--with-gtk=3'
elif [ "$TARGET_PLATFORM" == "macOS" ]; then
WX_HOST='x86_64-apple-darwin'
WX_PLATFORM_FLAGS='--with-osx'
elif [ "$TARGET_PLATFORM" == "win32" ]; then
WX_HOST='x86_64-w64-mingw32.static'
WX_PLATFORM_FLAGS='--with-msw'
VENDOR=win32
fi
if [ "$BUILD_PLATFORM" == "linux" ]; then
WX_BUILD='x86_64-linux'
elif [ "$BUILD_PLATFORM" == "macOS" ]; then
WX_BUILD='x86_64-apple-darwin'
fi
WX_BUILD_DIR=build-$TARGET_PLATFORM
if [ -d install-${TARGET_PLATFORM}-static ]; then
echo " wxWidgets static already built, skipping! (Remove install-${TARGET_PLATFORM}-static to reset)"
else
rm -rf $WX_BUILD_DIR-static
rm -rf $WX_INSTALL_PREFIX-static
mkdir -p $WX_BUILD_DIR-static
cd $WX_BUILD_DIR-static
do_with_log \
"Configuring static" \
"../configure --prefix=$WX_INSTALL_PREFIX-static --host=$WX_HOST --build=$WX_BUILD --disable-shared $WX_FLAGS $WX_PLATFORM_FLAGS" \
configure
do_with_log \
"Building static" \
"make -j`nproc --all`" \
build
do_with_log \
"Installing static" \
"make install" \
install
cd ..
fi
if [ -d install-${TARGET_PLATFORM}-shared ]; then
echo " wxWidgets shared already built, skipping! (Remove install-${TARGET_PLATFORM}-shared to reset)"
else
rm -rf $WX_BUILD_DIR-shared
rm -rf $WX_INSTALL_PREFIX-shared
mkdir -p $WX_BUILD_DIR-shared
cd $WX_BUILD_DIR-shared
do_with_log \
"Configuring shared" \
"../configure --prefix=$WX_INSTALL_PREFIX-shared --host=$WX_HOST --build=$WX_BUILD --enable-shared $WX_FLAGS $WX_PLATFORM_FLAGS" \
configure
do_with_log \
"Building shared" \
"make -j`nproc --all`" \
build
do_with_log \
"Installing shared" \
"make install" \
install
cd ..
platform_switch "${WX_INSTALL_PREFIX}-shared/lib64" "${WX_INSTALL_PREFIX}-shared/lib" ""
cd $SWITCH_VAL
patch_rpaths
fi
cd $ROOT_DIR
echo "Done!"