forked from KiCad/KicadOSXBuilder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·484 lines (367 loc) · 16.5 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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
SCRIPT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BUILD_TYPE=Release # Set to the users desired build type
BUILD_ARCHITECTURES=() # The architectures to build for
BUILD_STEPS=() # Which steps to build
MAKE_THREAD_COUNT=0 # The number of threads for make to use
CPU_COUNT=4 # The number of CPUs (core) in the system (defaults to 4)
KICAD_DIRECTORY=kicad
LIBRARY_DIRECTORY=library
WXPYTHON_VERSION=2.9.4.0
WXPYTHON_SOURCE_DIRECTORY=wxPython-src-$WXPYTHON_VERSION
WXPYTHON_DOWNLOAD_URL=http://downloads.sourceforge.net/project/wxpython/wxPython/$WXPYTHON_VERSION/$WXPYTHON_SOURCE_DIRECTORY.tar.bz2
BUILD_DIRECTORY=$SCRIPT_DIRECTORY/build
PREFIX_DIRECTORY=$SCRIPT_DIRECTORY/output
PACKAGE_DIRECTORY=$SCRIPT_DIRECTORY/package
SOURCE_DIRECTORY=$SCRIPT_DIRECTORY/src
ARCHIVE_DIRECTORY=$SCRIPT_DIRECTORY/archive
PATCH_DIRECTORY=$SCRIPT_DIRECTORY/patches
print_usage()
{
if [ "$1" != "" ]; then
echo ""
echo "`tput bold`Unknown option $1.`tput sgr0`"
echo ""
fi
echo "usage: build.sh [-a|--arch <architecture_string>] [-c|--cpus <cpu_count>] [-d|--debug] [-h|--help]"
echo ""
echo "-a / --arch <architecture_string>: specify an architecture to build. You can specify"
echo " multiple instaces of this argument to specify multiple architectures. If this argument"
echo " is not specified the script will build a universal i386 and x86_64 application."
echo ""
echo "-c / --cpus <cpu_count>: specify the number of CPUs (or cores) in your system. The"
echo " build script will spawn twice at much build threads so that your system is optimally"
echo " used."
echo ""
echo "-d / --debug: build a debug configuration binary."
echo ""
echo "-h / --help: show help text."
echo ""
echo "-s / --steps: <steps>: Select which steps to execute, either a single step number in the range [1-8] or a comma separated"
echo " list of steps or a step number followed by a comma followed by "..." ( eg. 3,... ). The later"
echo " syntax executes the step provided plus the following steps up until the last."
echo ""
if [ "$1" != "" ]; then
exit 1
else
exit 0
fi
}
mrproper()
{
rm -rdf build build-debug output output-debug package package-debug
exit
}
while [ "$1" != "" ]; do
case $1 in
# This flag allow the user to specify a target architcture. There can be multiple occurences of this flag with different architectures.
-a | --arch )
shift
if [ "$1" == ppc ] || [ "$1" == i386 ] || [ "$1" == x86_64 ]; then
BUILD_ARCHITECTURES+=( $1 )
else
echo "Unknown architecture `tput bold`'$1'`tput sgr0`"
exit 1
fi
;;
# With this flag the user can supply the ammount of CPUs (cores) in his/her system
-c | --cpus )
shift
CPU_COUNT=$1
;;
# The user might select a debug build via this flag
-d | --debug )
BUILD_TYPE=Debug
;;
# Print the help text
-h | --help )
print_usage
;;
# clean all build products
-m | --mrproper )
mrproper
;;
# Select which steps to execute, either a single step number in the range [1-8] or a comma separated list of steps
# or a step number followed by a comma followed by "..." ( eg. 3,... ). The later syntax executes the step provided
# plus the following steps up until the last.
-s | --steps )
shift
IFS=',' read -a STEPS <<< "$1"
if [ ${#STEPS[*]} == 0 ]; then
echo "Error: The option '-s' requires at least one value to be passed!"
exit 1
fi
for STEP in ${STEPS[@]}
do
if [ $STEP != "..." ] && [ $STEP -gt 0 ] && [ $STEP -lt 9 ]; then
BUILD_STEPS+=( $STEP )
elif [ $STEP == "..." ]; then
if [ ${#BUILD_STEPS[*]} == 0 ]; then
echo "Error: '...' specified for -s without prior step number! "
exit 1
fi
LAST_STEP=${BUILD_STEPS[${#BUILD_STEPS[*]} - 1]}
for (( STEP_TO_ADD = ${BUILD_STEPS[${#BUILD_STEPS[*]} - 1]} + 1; STEP_TO_ADD <= 8; STEP_TO_ADD++ ))
do
BUILD_STEPS+=($STEP_TO_ADD)
done
else
echo "Error: Step number '$STEP' out of range 1-8"
exit 1
fi
done
;;
# "Catch-all" case for unrecognized commandline options
* )
print_usage $1
esac
shift
done
init()
{
if [ ${#BUILD_ARCHITECTURES[@]} == 0 ]; then
BUILD_ARCHITECTURES=( i386 x86_64 )
fi
if [ ${#BUILD_STEPS[@]} == 0 ]; then
BUILD_STEPS=( 1 2 3 4 5 6 7 8 )
fi
MAKE_THREAD_COUNT=-j$(($CPU_COUNT*2)) # use twice as many threads as CPUs (cores) are in the system
mkdir -p $BUILD_DIRECTORY
mkdir -p $PREFIX_DIRECTORY
mkdir -p $PACKAGE_DIRECTORY
mkdir -p $ARCHIVE_DIRECTORY
mkdir -p $SOURCE_DIRECTORY
if [ $BUILD_TYPE = Debug ]; then
WXWIDGETS_ADDITIONAL_FLAGS=--enable-debug
KICAD_BUILD_FLAGS="-DCMAKE_BUILD_TYPE=Debug"
BUILD_DIRECTORY=$BUILD_DIRECTORY-debug
PREFIX_DIRECTORY=$PREFIX_DIRECTORY-debug
PACKAGE_DIRECTORY=$PACKAGE_DIRECTORY-debug
REVISION_APPENDIX=-debug
fi
}
main()
{
init
case $BUILD_TYPE in
Release ) echo "BUILDING RELEASE BINARIES"
;;
Debug ) echo "BUILDING DEBUG BINARIES"
;;
esac
for STEP in ${BUILD_STEPS[*]}
do
step$STEP
done
}
exit_on_install_error()
{
echo "install error on $STEP_NAME STEP: $STEP_NUMBER"
exit 1
}
exit_on_build_error()
{
echo "build error on $STEP_NAME STEP: $STEP_NUMBER"
exit 2
}
print_step_starting_message()
{
echo ""
echo ""
echo "****************************************************************************"
echo "Starting step: $STEP_NAME"
echo "****************************************************************************"
echo ""
echo ""
}
step1()
{
unpack_patch_wxpython()
{
cd $SOURCE_DIRECTORY
echo "unpacking wxpython sources ..."
tar xfj $ARCHIVE_DIRECTORY/$WXPYTHON_SOURCE_DIRECTORY.tar.bz2 || exit_on_build_error
cd $WXPYTHON_SOURCE_DIRECTORY
echo "patching wxpython sources ..."
patch -p1 < $PATCH_DIRECTORY/wxpython-2.9.4.0-kicad.patch || exit_on_build_error
patch -p1 < $PATCH_DIRECTORY/wxwidgets-2.9.4.0_filehistory_osx.patch || exit_on_build_error
cd $SCRIPT_DIRECTORY
}
STEP_NAME="CHECK & UNPACK WXPYTHON ($WXPYTHON_SOURCE_DIRECTORY)"
STEP_NUMBER=1
print_step_starting_message
test -f $ARCHIVE_DIRECTORY/$WXPYTHON_SOURCE_DIRECTORY.tar.bz2 || curl -L $WXPYTHON_DOWNLOAD_URL -o $ARCHIVE_DIRECTORY/$WXPYTHON_SOURCE_DIRECTORY.tar.bz2 || exit_on_build_error
test -d $SOURCE_DIRECTORY/$WXPYTHON_SOURCE_DIRECTORY || unpack_patch_wxpython
}
step2()
{
if [ -d $SOURCE_DIRECTORY/$KICAD_DIRECTORY ]; then
STEP_NAME="GET KICAD SOURCES"
else
STEP_NAME="UPDATE KICAD SOURCES"
fi
STEP_NUMBER=2
print_step_starting_message
test -d $SOURCE_DIRECTORY/$KICAD_DIRECTORY || (cd $SOURCE_DIRECTORY; bzr branch lp:~cern-kicad/kicad/testing kicad ; cd ..) || exit_on_build_error
test -d $SOURCE_DIRECTORY/$KICAD_DIRECTORY && (cd $SOURCE_DIRECTORY/$KICAD_DIRECTORY; bzr pull; cd ..) || exit_on_build_error
test -d $SOURCE_DIRECTORY/$LIBRARY_DIRECTORY || (cd $SOURCE_DIRECTORY; bzr branch lp:~kicad-lib-committers/kicad/library ; cd ..) || exit_on_build_error
test -d $SOURCE_DIRECTORY/$LIBRARY_DIRECTORY && (cd $SOURCE_DIRECTORY/$LIBRARY_DIRECTORY; bzr pull; cd ..) || exit_on_build_error
}
step3()
{
STEP_NAME="BUILD WXWIDGETS"
STEP_NUMBER=3
print_step_starting_message
mkdir -p $BUILD_DIRECTORY/$WXPYTHON_SOURCE_DIRECTORY
cd $BUILD_DIRECTORY/$WXPYTHON_SOURCE_DIRECTORY
IFS_OLD=$IFS
IFS=,
UNIVERSAL_BINARY_STRING="${BUILD_ARCHITECTURES[*]}"
IFS=$IFS_OLD
test -f Makefile || $SOURCE_DIRECTORY/$WXPYTHON_SOURCE_DIRECTORY/configure --disable-debug \
--prefix=$PREFIX_DIRECTORY \
--enable-unicode \
--enable-std_string \
--enable-display \
--with-opengl \
--with-osx_cocoa \
--with-libjpeg \
--with-libtiff \
--with-libpng \
--with-zlib \
--enable-dnd \
--enable-clipboard \
--enable-webkit \
--enable-monolithic \
--enable-svg \
--with-expat \
--enable-universal-binary="${UNIVERSAL_BINARY_STRING}" \
$WXWIDGETS_ADDITIONAL_FLAGS || exit_on_build_error
make $MAKE_THREAD_COUNT || exit_on_build_error
make install || exit_on_build_error
cd $SCRIPT_DIRECTORY
}
step4()
{
STEP_NAME="BUILD WXPYTHON PYTHON EXTENSIONS"
STEP_NUMBER=4
print_step_starting_message
PY_OPTS="WXPORT=osx_cocoa UNICODE=1 INSTALL_MULTIVERSION=1 BUILD_GLCANVAS=1 BUILD_GIZMOS=1 BUILD_STC=1"
cd $SOURCE_DIRECTORY/$WXPYTHON_SOURCE_DIRECTORY/wxPython
python setup.py build_ext WX_CONFIG=$PREFIX_DIRECTORY/bin/wx-config $PY_OPTS || exit_on_build_error
python setup.py install --prefix=$PREFIX_DIRECTORY WX_CONFIG=$PREFIX_DIRECTORY/bin/wx-config $PY_OPTS || exit_on_build_error
cd $SCRIPT_DIRECTORY
}
step5()
{
STEP_NAME="BUILD KICAD"
STEP_NUMBER=5
print_step_starting_message
export PATH=$PREFIX_DIRECTORY/bin:$PATH
export wxWidgets_ROOT_DIR=$PREFIX_DIRECTORY
mkdir -p $BUILD_DIRECTORY/$KICAD_DIRECTORY
cd $BUILD_DIRECTORY/$KICAD_DIRECTORY
mkdir -p $PREFIX_DIRECTORY/python/site-packages
CMAKE_ARCHITECTURE_STRING=
for ARCHITECTURE in "${BUILD_ARCHITECTURES[@]}"
do
CMAKE_ARCHITECTURE_STRING=$CMAKE_ARCHITECTURE_STRING"${ARCHITECTURE};"
done
CMAKE_ARCHITECTURE_STRING=${CMAKE_ARCHITECTURE_STRING%;}
cmake $SOURCE_DIRECTORY/$KICAD_DIRECTORY -DKICAD_TESTING_VERSION=ON \
-DKICAD_SCRIPTING=ON \
-DKICAD_SCRIPTING_MODULES=ON \
-DKICAD_SCRIPTING_WXPYTHON=ON \
-DCMAKE_CXX_FLAGS=-D__ASSERTMACROS__ \
-DCMAKE_ASM_FLAGS="-arch i386 -arch x86_64" \
-DCMAKE_INSTALL_PREFIX=$PREFIX_DIRECTORY \
-DCMAKE_FIND_FRAMEWORK=LAST \
-DwxWidgets_CONFIG_EXECUTABLE=$PREFIX_DIRECTORY/bin/wx-config \
-DPYTHON_EXECUTABLE=`which python` \
-DPYTHON_SITE_PACKAGE_PATH=$PREFIX_DIRECTORY/python/site-packages \
-DPYTHON_PACKAGES_PATH=$PREFIX_DIRECTORY/python/site-packages \
-DCMAKE_OSX_ARCHITECTURES="${CMAKE_ARCHITECTURE_STRING}" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE
#dependencies on swig .i files are not well managed, so if we clear this
#then swig rebuilds the .cxx files
rm -f $BUILD_DIRECTORY/$KICAD_DIRECTORY/pcbnew/pcbnew_wrap.cxx
rm -f $BUILD_DIRECTORY/$KICAD_DIRECTORY/pcbnew/scripting/pcbnewPYTHON_wrap.cxx
make $MAKE_THREAD_COUNT install || exit_on_build_error
cd $SCRIPT_DIRECTORY
}
step6()
{
STEP_NAME="INSTALLING LIBRARY"
STEP_NUMBER=6
print_step_starting_message
mkdir -p $BUILD_DIRECTORY/$LIBRARY_DIRECTORY
cd $BUILD_DIRECTORY/$LIBRARY_DIRECTORY
cmake $SOURCE_DIRECTORY/$LIBRARY_DIRECTORY/ -DCMAKE_INSTALL_PREFIX=$PREFIX_DIRECTORY \
-DKICAD_TEMPLATES=$PREFIX_DIRECTORY/share/kicad/template \
-DKICAD_MODULES=$PREFIX_DIRECTORY/share/kicad/modules \
-DKICAD_LIBRARY=$PREFIX_DIRECTORY/share/kicad/library
make install
cd $SCRIPT_DIRECTORY
}
step7()
{
STEP_NAME="REPACKAGE *.app"
STEP_NUMBER=7
print_step_starting_message
INSTALL_NAME_TOOL="xcrun install_name_tool"
KICAD_FRAMEWORKS_PATH="@executable_path/../../../kicad.app/Contents/Frameworks/"
PYTHON_SITE_PKGS=$PREFIX_DIRECTORY/bin/kicad.app/Contents/Frameworks/python2.7/site-packages
mkdir -p $PYTHON_SITE_PKGS
FRAMEWORK_LIBS=$PREFIX_DIRECTORY/bin/kicad.app/Contents/Frameworks/
PCBNEW_EXES=$PREFIX_DIRECTORY/bin/pcbnew.app/Contents/MacOS
KICAD_EXES=$PREFIX_DIRECTORY/bin/kicad.app/Contents/MacOS
echo "copying kicad libs"
cp $BUILD_DIRECTORY/$KICAD_DIRECTORY/pcbnew/_pcbnew.so $PYTHON_SITE_PKGS
cp $BUILD_DIRECTORY/$KICAD_DIRECTORY/pcbnew/pcbnew.py $PYTHON_SITE_PKGS
cp -RfP $PREFIX_DIRECTORY/lib/libwx_osx_cocoau-2.9.4.0.0.dylib $FRAMEWORK_LIBS
cp -RfP $PREFIX_DIRECTORY/lib/libwx_osx_cocoau_gl-2.9.4.0.0.dylib $FRAMEWORK_LIBS
cd $FRAMEWORK_LIBS
ln -s libwx_osx_cocoau-2.9.4.0.0.dylib libwx_osx_cocoau-2.9.dylib
ln -s libwx_osx_cocoau-2.9.4.0.0.dylib libwx_osx_cocoau-2.9.4.dylib
ln -s libwx_osx_cocoau_gl-2.9.4.0.0.dylib libwx_osx_cocoau_gl-2.9.dylib
ln -s libwx_osx_cocoau_gl-2.9.4.0.0.dylib libwx_osx_cocoau_gl-2.9.4.dylib
$INSTALL_NAME_TOOL -id $KICAD_FRAMEWORKS_PATH/libwx_osx_cocoau-2.9.4.0.0.dylib $FRAMEWORK_LIBS/libwx_osx_cocoau-2.9.4.0.0.dylib
$INSTALL_NAME_TOOL -id $KICAD_FRAMEWORKS_PATH/libwx_osx_cocoau_gl-2.9.4.0.0.dylib $FRAMEWORK_LIBS/libwx_osx_cocoau_gl-2.9.4.0.0.dylib
$INSTALL_NAME_TOOL -change $PREFIX_DIRECTORY/lib/libwx_osx_cocoau-2.9.4.0.0.dylib $KICAD_FRAMEWORKS_PATH/libwx_osx_cocoau-2.9.4.0.0.dylib $FRAMEWORK_LIBS/libwx_osx_cocoau_gl-2.9.4.0.0.dylib
cd $SCRIPT_DIRECTORY
cp -rf $PREFIX_DIRECTORY/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx $PYTHON_SITE_PKGS
for APP in bitmap2component eeschema gerbview pcbnew pcb_calculator kicad cvpcb
do
echo repackaging $APP
cp -fP $BUILD_DIRECTORY/$KICAD_DIRECTORY/$APP/$APP.app/Contents/MacOS/$APP $PREFIX_DIRECTORY/bin/$APP.app/Contents/MacOS/$APP.bin
cp -fP $SCRIPT_DIRECTORY/patches/loader.sh $PREFIX_DIRECTORY/bin/$APP.app/Contents/MacOS/$APP
chmod a+x $PREFIX_DIRECTORY/bin/$APP.app/Contents/MacOS/$APP
echo "fixing references in $APP"
$INSTALL_NAME_TOOL -change $PREFIX_DIRECTORY/lib/libwx_osx_cocoau_gl-2.9.dylib $KICAD_FRAMEWORKS_PATH/libwx_osx_cocoau_gl-2.9.dylib $PREFIX_DIRECTORY/bin/$APP.app/Contents/MacOS/$APP.bin
$INSTALL_NAME_TOOL -change $PREFIX_DIRECTORY/lib/libwx_osx_cocoau-2.9.dylib $KICAD_FRAMEWORKS_PATH/libwx_osx_cocoau-2.9.dylib $PREFIX_DIRECTORY/bin/$APP.app/Contents/MacOS/$APP.bin
done
echo "fixing references in wxPython libs"
find $PREFIX_DIRECTORY -name "*.so" -exec $INSTALL_NAME_TOOL -change $PREFIX_DIRECTORY/lib/libwx_osx_cocoau-2.9.dylib $KICAD_FRAMEWORKS_PATH/libwx_osx_cocoau-2.9.dylib {} \;
find $PREFIX_DIRECTORY -name "*.so" -exec $INSTALL_NAME_TOOL -change $PREFIX_DIRECTORY/lib/libwx_osx_cocoau_gl-2.9.dylib $KICAD_FRAMEWORKS_PATH/libwx_osx_cocoau_gl-2.9.dylib {} \;
cd $SCRIPT_DIRECTORY
}
step8()
{
STEP_NAME="make a zip with all the apps"
STEP_NUMBER=8
print_step_starting_message
rm -rf $PACKAGE_DIRECTORY
mkdir -p $PACKAGE_DIRECTORY/KiCad/data/scripting/plugins
echo "copying apps"
cp -RfP $PREFIX_DIRECTORY/bin/*.app $PACKAGE_DIRECTORY/KiCad
cp patches/python $PACKAGE_DIRECTORY/KiCad
echo "copying kicad data"
cp -rf $PREFIX_DIRECTORY/share/kicad/* $PACKAGE_DIRECTORY/KiCad/data
cp -rf $SOURCE_DIRECTORY/kicad/pcbnew/scripting/plugins/* $PACKAGE_DIRECTORY/KiCad/data/scripting/plugins
cp -rf $PATCH_DIRECTORY/python $PACKAGE_DIRECTORY/KiCad/
REVNO=`cd $SOURCE_DIRECTORY/kicad; bzr revno`
cd $PACKAGE_DIRECTORY
zip -r -y kicad-scripting-osx-$REVNO$REVISION_APPENDIX.zip KiCad/*
cd $SCRIPT_DIRECTORY
}
main
echo "Done!! :-)"