-
Notifications
You must be signed in to change notification settings - Fork 1
/
kicad-app.sh
executable file
·379 lines (326 loc) · 8.78 KB
/
kicad-app.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
#!/bin/sh
# -----
# Options
# -----
THREADS=5
OSX_SDK_VER=10.12
BASE=`pwd`
COMPILER=clang
WX_SRC_URL="http://downloads.sourceforge.net/project/wxpython/wxPython/3.0.2.0/wxPython-src-3.0.2.0.tar.bz2"
WX_SRC_NAME=wxPython-src-3.0.2.0.tar.bz2
KICAD_GIT=https://git.launchpad.net/kicad
I18N_GIT=https://github.com/KiCad/kicad-i18n.git
LIBRARY_GIT=https://github.com/KiCad/kicad-library.git
KICAD_SRC=kicad
I18N_DIR=i18n
LIBRARY_DIR=library
KICAD_BUILD_DIR=build
KICAD_BIN=bin
SUPPORT_BIN=support
KICAD_SETTINGS=(
"-DDEFAULT_INSTALL_PATH=/Library/Application Support/kicad"
"-DCMAKE_OSX_DEPLOYMENT_TARGET=$OSX_SDK_VER"
"-DwxWidgets_CONFIG_EXECUTABLE=$BASE/wx/bin/bin/wx-config"
"-DPYTHON_SITE_PACKAGE_PATH=$BASE/wx/bin/lib/python2.7/site-packages"
"-DCMAKE_INSTALL_PREFIX=$BASE/bin"
"-DCMAKE_BUILD_TYPE=Release"
"-DKICAD_USE_SCH_IO_MANAGER=ON"
"-DKICAD_INSTALL_DEMOS=OFF"
"-DKICAD_SPICE=ON"
"-DKICAD_USE_OCE=ON"
"-DOCE_DIR=$(brew --prefix oce)/OCE.framework/Versions/0.18/Resources/"
"-DKICAD_SCRIPTING=ON"
"-DKICAD_SCRIPTING_MODULES=ON"
"-DKICAD_SCRIPTING_WXPYTHON=ON"
"-DPYTHON_EXECUTABLE=$(which python)"
)
# -----
# End Options
# -----
check_compiler() {
printf "Checking for Compiler... "
if !(which cc > /dev/null); then
printf "Unable to find a compiler. Install a compiler and try again\n"
exit 1
else
printf "${COMPILER}\n"
fi
}
check_deps() {
printf "Checking for Brew... "
if !(which brew > /dev/null); then
printf "Unable to find Brew. See http://brew.sh to install\n"
else
printf "Done\n"
fi
printf "Checking Dependencies... "
if ! brew list gettext cmake glew cairo glm automake libtool oce swig libngspice> /dev/null; then
printf "Run brew install boost gettext cmake glew cairo glm automake libtool homebrew/science/oce swig libngspice\n"
exit 1
else
printf "Done\n"
fi
}
check_wx() {
cd wx
printf "Fetching wxPython... "
if [ ! -f $WX_SRC_NAME ]; then
printf "Downloading $WX_SRC_NAME"
curl -L -o $WX_SRC_NAME $WX_SRC_URL
else
printf "Done\n"
fi
printf "Extracting wxWidgets... "
if [ ! -d src ]; then
mkdir src
cd src
tar xf ../$WX_SRC_NAME --strip-components 1
patch -p0 < ../patches/wxwidgets-3.0.0_macosx.patch || exit 1
patch -p0 < ../patches/wxwidgets-3.0.0_macosx_bug_15908.patch || exit 1
patch -p0 < ../patches/wxwidgets-3.0.0_macosx_soname.patch || exit 1
patch -p0 < ../patches/wxwidgets-3.0.2_macosx_yosemite.patch || exit 1
patch -p0 < ../patches/wxwidgets-3.0.0_macosx_scrolledwindow.patch || exit 1
patch -p0 < ../patches/wxwidgets-3.0.2_macosx_retina_opengl.patch || exit 1
patch -p0 < ../patches/wxwidgets-3.0.2_macosx_magnify_event.patch || exit 1
patch -p0 < ../patches/wxwidgets-3.0.2_macosx_unicode_pasteboard.patch || exit 1
patch -p0 < ../patches/wxwidgets-3.0.2_macosx_sierra.patch || exit 1
cd ..
else
printf "Done\n"
fi
printf "Building wxWidgets... "
if [ ! -d build ]; then
mkdir build
cd build
export MAC_OS_X_VERSION_MIN_REQUIRED=$OSX_SDK_VER
../src/configure \
--prefix=`pwd`/../bin \
--with-opengl \
--enable-aui \
--enable-utf8 \
--enable-html \
--enable-stl \
--enable-monolithic \
--with-libjpeg=builtin \
--with-libpng=builtin \
--with-regex=builtin \
--with-libtiff=builtin \
--with-zlib=builtin \
--with-expat=builtin \
--without-liblzma \
--with-macosx-version-min=$OSX_SDK_VER \
--disable-mediactrl # Not compatible with macOS 10.12
cd ..
fi
if [ ! -d bin ]; then
cd build
make -j$THREADS
if [ $? == 0 ]; then
mkdir ../bin
make install
cd ..
else
cd ..
exit 1
fi
else
printf "Done\n"
fi
printf "Building wxPython... "
if [ ! -d bin/lib/python2.7/site-packages ]; then
cd src/wxPython
export MAC_OSX_VERSION_MIN_REQUIRED=$OSX_SDK_VER
WXPYTHON_BUILD_OPTS="WX_CONFIG=`pwd`/../../bin/bin/wx-config \
BUILD_BASE=`pwd`/../../build \
UNICODE=1 \
WXPORT=osx_cocoa"
WXPYTHON_PREFIX="--prefix=`pwd`/../../bin"
python setup.py build_ext $WXPYTHON_BUILD_OPTS
if [ $? == 0 ]; then
python setup.py install $WXPYTHON_PREFIX $WXPYTHON_BUILD_OPTS
else
cd ../../
exit 1
fi
cd ../../
else
printf "Done\n"
fi
cd ..
}
# Kicad
kicad_update() {
if [ ! -d $KICAD_SRC ]; then
git clone $KICAD_GIT $KICAD_SRC
else
git -C $KICAD_SRC checkout
git -C $KICAD_SRC pull
fi
}
kicad_patch() {
if [ -e $BASE/notes/kicad_patches ]; then
rm $BASE/notes/kicad_patches
fi
if [ -e $BASE/kicad_patches ]; then
for patch in `find $BASE/kicad_patches -type f -name \*.patch`; do
echo "Applying $patch"
patch -d $SRC -p0 < $patch
echo "`basename $patch`" >> $BASE/notes/kicad_patches
done
fi
}
kicad_build() {
if [ ! -d $KICAD_SRC ]; then
git clone $KICAD_GIT $KICAD_SRC
fi
if [ ! -d $KICAD_BUILD_DIR ]; then
mkdir $KICAD_BUILD_DIR
cd $KICAD_BUILD_DIR
cmake "${KICAD_SETTINGS[@]}" ../$KICAD_SRC
cd ..
fi
cd $KICAD_BUILD_DIR
make -j$THREADS
if [ -d ../$KICAD_BIN ]; then
rm -r ../$KICAD_BIN
fi
make install
cd ..
}
kicad_rebuild() {
if [ -d $KICAD_BUILD_DIR ]; then
rm -r $KICAD_BUILD_DIR
fi
kicad_build
}
i18n_update() {
if [ ! -d $I18N_DIR ]; then
mkdir $I18N_DIR
fi
cd $I18N_DIR
if [ ! -d src ]; then
git clone $I18N_GIT src
else
git -C src checkout
git -C src pull
fi
cd -
}
i18n_build() {
if [ ! -d $I18N_DIR ]; then
mkdir $I18N_DIR
fi
cd $I18N_DIR
#Fetch
if [ ! -d src ]; then
git clone $I18N_GIT src
fi
#build
mkdir -p build
cd build
if [ -d ../bin ]; then
rm -r ../bin
fi
mkdir -p ../bin
cmake -DCMAKE_INSTALL_PREFIX=../bin \
-DKICAD_I18N_PATH=../bin/internat \
-DGETTEXT_MSGMERGE_EXECUTABLE=$(brew --prefix gettext)/bin/msgmerge \
-DGETTEXT_MSGFMT_EXECUTABLE=$(brew --prefix gettext)/bin/msgfmt \
../src
make install
cd -
}
# Symbols/3d models
library_update() {
if [ ! -d $LIBRARY_DIR ]; then
mkdir $LIBRARY_DIR
fi
cd $LIBRARY_DIR
if [ ! -d src ]; then
git clone $LIBRARY_GIT src
else
git -C src checkout
git -C src pull
fi
cd -
}
library_build() {
if [ ! -d $LIBRARY_DIR ]; then
mkdir $LIBRARY_DIR
fi
cd $LIBRARY_DIR
if [ ! -d src ]; then
git clone $LIBRARY_GIT src
fi
mkdir -p build
cd build
if [ -d ../bin ]; then
rm -r ../bin
fi
mkdir -p ../bin
cmake -DCMAKE_INSTALL_PREFIX=../bin ../src
make install
cd -
}
package_kicad() {
echo "TODO"
}
clean() {
for folder in notes $KICAD_BUILD $KICAD_BIN $I18N_BUILD $SUPPORT_BIN; do
rm -r $folder
done
}
print_help() {
echo "Usage: $0 [-h] [command ...]"
echo
echo "Options"
echo " -h - Help"
#echo " -b - Git Branch to use"
echo
echo "Commands"
echo " check_compiler - Check that a c compiler is installed"
echo " check_deps - Check that brew requirements are installed"
echo " check_wx - Fetch, Patch and Build wxwidgets"
echo " kicad_fetch - Fetch or update the kicad sourcecode tree"
echo " kicad_build - Build kicad"
echo " kicad_rebuild - Fresh build of kicad"
echo " i18n_update - Update i18n tree"
echo " i18n_build - Build i18n"
echo " library_update - update schematic symbols and 3d models"
echo " library_build - build schematic symbols and 3d models"
echo
}
while getopts ":hb:" opt; do
case $opt in
b)
echo "Branch $OPTARG"
;;
h)
print_help
exit 0
;;
\?)
echo "Usage: $0 [-h] [command ...]"
exit 2
;;
esac
done
shift $(expr $OPTIND - 1 )
if [ $# -eq 0 ]; then
echo check_compiler
echo check_deps
echo check_wx
echo kicad_fetch
echo kicad_build
else
while [ $# -gt 0 ]; do
if [[ $(type -t $1) == function ]]; then
$1
else
echo "Unknown Command: $1"
echo "See -h for help"
echo
fi
shift
done
fi