-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
executable file
·332 lines (276 loc) · 8.96 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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/bash
#
# build.sh
# GPhoto2.framework
# https://github.com/lnxbil/GPhoto2.framework
#
# Copyright (C) 2011-2020 Andreas Steinel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# On fishy behaviour, please uncomment this line
#set -ex
# loading configuration file
source ./config
###############################################################################
# Variables
###############################################################################
# Setting up paths relative to the FRAMEWORK_BASE
PREFIX=${FRAMEWORK_BASE}/prefix
MANPAGES=${PREFIX}/man/man1
LICENSES=${FRAMEWORK_BASE}/Resources/Licenses
LIBGPHOTOSVN=libgphoto2-SVN
# Compiler flags
export MACOSX_DEPLOYMENT_TARGET=10.15
export CFLAGS="-I${PREFIX}/include -mmacosx-version-min=10.15"
export CPPFLAGS="-I${PREFIX}/include"
#For building on the iPad with myreaddir library
#export LDFLAGS="-F/var/mobile/Frameworks -L/usr/lib -lmyreaddir"
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
export PATH=${PREFIX}/bin:/usr/local/bin/:/usr/bin:/bin:/usr/sbin:/sbin:${PATH}
export LD_LIBRARY_PATH=${PREFIX}/lib
export LDFLAGS="-L${PREFIX}/lib"
export CC="gcc $ARCH"
export CXX="g++ $ARCH"
export CPP=/usr/bin/cpp
export CXXCPP=/usr/bin/cpp
export CFLAGS="$CFLAGS -pipe"
export CXXFLAGS="$CXXFLAGS -pipe"
# other flags
export LANG=C
DATE=`date +%Y%m%d_%H%M%S `
DCORES=$(( `sysctl -n hw.ncpu` * 2 ))
###############################################################################
# Functions
###############################################################################
function download_files()
{
echo "+ Download and extracting files"
mkdir -p download
cd download
# build download list
cat <<EOF > download.list
http://ftpmirror.gnu.org/libtool/libtool-${LIBTOOL}.tar.gz
http://pkgconfig.freedesktop.org/releases/pkg-config-${PKGCONFIG}.tar.gz
https://github.com/libusb/libusb/releases/download/v${LIBUSB}/libusb-${LIBUSB}.tar.bz2
https://github.com/libusb/libusb-compat-0.1/archive/v${LIBUSBC}.tar.gz
https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${LIBJPEG}.tar.gz
EOF
if [ $LIBGPHOTO != "SVN" ]
then
cat <<EOF >> download.list
https://github.com/gphoto/libgphoto2/archive/libgphoto2-${LIBGPHOTO}-release.tar.gz
EOF
else
if [ -d $LIBGPHOTOSVN ]
then
cd $LIBGPHOTOSVN
svn up -q
autoreconf --install --symlink
else
svn checkout -q https://gphoto.svn.sourceforge.net/svnroot/gphoto/trunk/libgphoto2 $LIBGPHOTOSVN
cd $LIBGPHOTOSVN
autoreconf --install --symlink
cd $OLDPWD
fi
fi
# Downloading required files as compressed tar archives
wget --timeout 5 --tries 2 -c -i download.list > download.log 2>&1
# get downloaded file list
GZFILES=`ls -1 *.tar.gz *.tgz 2>/dev/null`
BZFILES=`ls -1 *.tar.bz2 *.tbz 2>/dev/null`
# uncompress each file
for i in $GZFILES; do tar -zxf $i; done
for i in $BZFILES; do tar -jxf $i; done
cd ..
}
function check_wget()
{
if ! which wget >/dev/null 2>&1
then
echo "Please get 'wget' as downloader"
exit 1
fi
}
function check_permissions()
{
echo "+ Checking permissions on $FRAMEWORK_BASE"
TMPFILE=`mktemp -t GPhoto.framework`
# FRAMEWORK_BASE directory has to exist
if ! [ -d $FRAMEWORK_BASE ]
then
if ! mkdir -p $FRAMEWORK_BASE 2>/dev/null
then
echo -n "FRAMEWORK_BASE '$FRAMEWORK_BASE' does not exist, try to create it . . . FAILED!"
echo ""
echo "Please try to create the directory manually as root (e.g. with sudo):"
echo " sudo mkdir -m 777 -p $FRAMEWORK_BASE"
exit 1
fi
fi
# FRAMEWORK_BASE directory has to be writeable
if ! touch $FRAMEWORK_BASE/test 2>/dev/null
then
echo "Check if the FRAMEWORK_BASE is writeable . . . . . . . . . . . FAILED!"
echo ""
echo "Please try to fix it manuall as root (e.g. with sudo)"
echo " sudo chmod 777 $FRAMEWORK_BASE"
exit 1
fi
}
function compile_me_real()
{
CONFIGURE="./configure --prefix=$PREFIX --enable-shared --disable-iconv --enable-osx-universal-binary --disable-nls "
cd $1
echo "--------------------------------------------------------------------------------"
echo "Starting to build $1"
echo "--------------------------------------------------------------------------------"
echo "- Cleaning"
make -s clean || true
echo "- Configuring"
if ! [ -f "configure" ]
then
echo "Running autoreconf"
autoreconf -fiv
fi
echo "Running '$CONFIGURE'"
$CONFIGURE
[ $? -gt 0 ] && return 1
echo "- Building"
make -s -j${DCORES} all
[ $? -gt 0 ] && return 1
echo "- Installing"
make install -s
[ $? -gt 0 ] && return 1
make install-lib -s
make install-headers -s
echo "- Finishing"
cd ..
}
function compile_me()
{
echo " - Building $1"
MYPWD=$PWD
mkdir -p $MYPWD/logs
# strip / is present and append _buildlog-$DATE.log
LOGFILE=$(echo $1 | cut -d/ -f1)_buildlog-$DATE.log
compile_me_real $1 >logs/$LOGFILE 2>&1
if [ $? -gt 0 ]
then
cd ..
echo ""
echo "An error occured"
echo "(Full Log at $MYPWD/logs/$LOGFILE):"
echo ""
tail -20 $MYPWD/logs/$LOGFILE
exit 1
fi
# Copying Licensing information
if [ -e $1/COPYING ]
then
cp -a $1/COPYING $LICENSES/$1
fi
}
function build()
{
# Cleaning up
rm -rf ${FRAMEWORK_BASE}/*
mkdir -p $MANPAGES $LICENSES
# switch to work directory
cd download
echo "+ Start building at `date` with ${DCORES} threads"
compile_me "libtool-${LIBTOOL}"
compile_me "pkg-config-${PKGCONFIG}"
compile_me "libusb-${LIBUSB}"
compile_me "libusb-compat-0.1-${LIBUSBC}"
compile_me "libjpeg-turbo-${LIBJPEG}"
compile_me "libgphoto2-libgphoto2-${LIBGPHOTO}-release"
echo "+ Finished building at `date`"
}
function cleanup_build()
{
echo "+ Cleaning up framework directory"
# Cleaning up unneccessary files
rm -rf ${PREFIX}/{share,man,bin} \
${PREFIX}/lib/pkgconfig \
${PREFIX}/lib/udev \
${PREFIX}/lib/libgphoto2/print-camera-list
find $PREFIX/lib/ -iname "*.a" | xargs rm -f
find $PREFIX/lib/ -iname "*.la" | xargs rm -f
}
function linking_headers()
{
echo "+ Linking headers"
# Linking GPhoto2 Headers
mkdir -p $FRAMEWORK_BASE/Headers
for i in $PREFIX/include/gphoto2/*h
do
file=$(basename $i)
ln -fs ../prefix/include/gphoto2/$file $FRAMEWORK_BASE/Headers/$file
done
# Links libusb and ltdl
ln -fs ../prefix/include/usb.h $FRAMEWORK_BASE/Headers
ln -fs ../prefix/include/ltdl.h $FRAMEWORK_BASE/Headers
}
function build_framework_infrastructure()
{
echo "+ Building Apple Framework infrastructure"
# Build versions directory
mkdir -p $FRAMEWORK_BASE/Versions/Current
ln -fs ../../prefix/lib/libgphoto2.dylib $FRAMEWORK_BASE/Versions/Current/GPhoto2
ln -fs prefix/lib/libgphoto2.dylib $FRAMEWORK_BASE/GPhoto2
# Populate Info.plist
cat <<EOF > $FRAMEWORK_BASE/Resources/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>GPhoto2</string>
<key>CFBundleIdentifier</key>
<string>com.github.lnxbil.gphoto2.framework</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>GPhoto2</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>${LIBGPHOTO}</string>
<key>CFBundleVersion</key>
<string>${LIBGPHOTO}</string>
</dict>
</plist>
EOF
}
function main()
{
echo "Build Process of the GPhoto2.framework"
echo "https://github.com/lnxbil/GPhoto2.framework"
echo ""
check_wget
check_permissions
download_files
build
cleanup_build
linking_headers
build_framework_infrastructure
}
###############################################################################
# Main
###############################################################################
# Running main
main