-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-openocd-osx.sh
735 lines (596 loc) · 21.5 KB
/
build-openocd-osx.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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Script to build the OS X version of OpenOCD. It produces an install package
# that expands in "/Applications/GNU ARM Eclipse/OpenOCD".
# Prerequisites:
#
# MacPorts with the following ports installed:
#
# sudo port install libtool automake autoconf pkgconfig wget
# sudo port install cmake boost libconfuse swig-python
# sudo port install texinfo texlive
# ----- Prepare MacPorts environment -----
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
port version >/dev/null
if [ $? != 0 ]
then
echo "Mandatory MacPorts not found, quit."
exit 1
fi
# ----- Parse actions and command line options -----
ACTION_CLEAN=""
ACTION_GIT=""
TARGET_BITS="64"
while [ $# -gt 0 ]
do
if [ "$1" == "clean" ]
then
ACTION_CLEAN="$1"
elif [ "$1" == "pull" ]
then
ACTION_GIT="$1"
elif [ "$1" == "checkout-dev" ]
then
ACTION_GIT="$1"
elif [ "$1" == "checkout-stable" ]
then
ACTION_GIT="$1"
else
echo "Unknown action/option $1"
exit 1
fi
shift
done
# ----- Externally configurable variables -----
# The folder where the entire build procedure will run.
# If you prefer to build in a separate folder, define it before invoking
# the script.
if [ -d /media/Work ]
then
OPENOCD_WORK_FOLDER=${OPENOCD_WORK_FOLDER:-"/media/Work/openocd"}
else
OPENOCD_WORK_FOLDER=${OPENOCD_WORK_FOLDER:-${HOME}/Work/openocd}
fi
# The folder where OpenOCD will be installed.
INSTALL_FOLDER=${INSTALL_FOLDER:-"/Applications/GNU ARM Eclipse/OpenOCD"}
# PKG_CONFIG_PATH=${PKG_CONFIG_PATH:-""}
PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR:-""}
DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH:-""}
MAKE_JOBS=${MAKE_JOBS:-"-j8"}
# ----- Local variables -----
# For updates, please check the corresponding pages.
# http://www.intra2net.com/en/developer/libftdi/download.php
LIBFTDI="libftdi1-1.2"
# https://sourceforge.net/projects/libusb/files/libusb-compat-0.1/
LIBUSB0="libusb-compat-0.1.5"
# https://sourceforge.net/projects/libusb/files/libusb-1.0/
LIBUSB1="libusb-1.0.19"
# https://github.com/signal11/hidapi/downloads
HIDAPI="hidapi-0.7.0"
HIDAPI_TARGET="mac"
HIDAPI_OBJECT="hid.o"
OPENOCD_TARGET="osx"
OPENOCD_GIT_FOLDER="${OPENOCD_WORK_FOLDER}/gnuarmeclipse-openocd.git"
OPENOCD_DOWNLOAD_FOLDER="${OPENOCD_WORK_FOLDER}/download"
OPENOCD_BUILD_FOLDER="${OPENOCD_WORK_FOLDER}/build/${OPENOCD_TARGET}"
OPENOCD_INSTALL_FOLDER="${OPENOCD_WORK_FOLDER}/install/${OPENOCD_TARGET}"
OPENOCD_OUTPUT="${OPENOCD_WORK_FOLDER}/output"
WGET="wget"
WGET_OUT="-O"
# ----- Test if some tools are present -----
echo
echo "Test tools..."
echo
gcc --version
git --version
automake --version
cmake --version
# Process actions.
if [ "${ACTION_CLEAN}" == "clean" ]
then
# Remove most build and temporary folders
echo
echo "Remove most build folders..."
rm -rf "${OPENOCD_BUILD_FOLDER}"
rm -rf "${OPENOCD_INSTALL_FOLDER}"
rm -rf "${OPENOCD_WORK_FOLDER}/${LIBFTDI}"
rm -rf "${OPENOCD_WORK_FOLDER}/${LIBUSB0}"
rm -rf "${OPENOCD_WORK_FOLDER}/${LIBUSB1}"
rm -rf "${OPENOCD_WORK_FOLDER}/${HIDAPI}"
echo
echo "Clean completed. Proceed with a regular build."
exit 0
fi
if [ "${ACTION_GIT}" == "pull" ]
then
if [ -d "${OPENOCD_GIT_FOLDER}" ]
then
echo
if [ "${USER}" == "ilg" ]
then
echo "Enter SourceForge password for git pull"
fi
cd "${OPENOCD_GIT_FOLDER}"
git pull
git submodule update
rm -rf "${OPENOCD_BUILD_FOLDER}/openocd"
# Prepare autotools.
echo
echo "bootstrap..."
cd "${OPENOCD_GIT_FOLDER}"
./bootstrap
echo
echo "Pull completed. Proceed with a regular build."
exit 0
else
echo "No git folder."
exit 1
fi
fi
if [ "${ACTION_GIT}" == "checkout-dev" ]
then
if [ -d "${OPENOCD_GIT_FOLDER}" ]
then
echo
if [ "${USER}" == "ilg" ]
then
echo "Enter SourceForge password for git pull"
fi
cd "${OPENOCD_GIT_FOLDER}"
git pull
git checkout gnuarmeclipse-dev
git submodule update
rm -rf "${OPENOCD_BUILD_FOLDER}/openocd"
# Prepare autotools.
echo
echo "bootstrap..."
cd "${OPENOCD_GIT_FOLDER}"
./bootstrap
echo
echo "Pull completed. Proceed with a regular build."
exit 0
else
echo "No git folder."
exit 1
fi
fi
if [ "${ACTION_GIT}" == "checkout-stable" ]
then
if [ -d "${OPENOCD_GIT_FOLDER}" ]
then
echo
if [ "${USER}" == "ilg" ]
then
echo "Enter SourceForge password for git pull"
fi
cd "${OPENOCD_GIT_FOLDER}"
git pull
git checkout gnuarmeclipse
git submodule update
rm -rf "${OPENOCD_BUILD_FOLDER}/openocd"
# Prepare autotools.
echo
echo "bootstrap..."
cd "${OPENOCD_GIT_FOLDER}"
./bootstrap
echo
echo "Pull completed. Proceed with a regular build."
exit 0
else
echo "No git folder."
exit 1
fi
fi
# ----- Begin of common part --------------------------------------------------
# Create the work folder.
mkdir -p "${OPENOCD_WORK_FOLDER}"
# ----- Get the GNU ARM Eclipse OpenOCD git repository -----
# The custom OpenOCD branch is available from the dedicated Git repository
# which is part of the GNU ARM Eclipse project hosted on SourceForge.
# Generally this branch follows the official OpenOCD master branch,
# with updates after every OpenOCD public release.
if [ ! -d "${OPENOCD_GIT_FOLDER}" ]
then
cd "${OPENOCD_WORK_FOLDER}"
if [ "${USER}" == "ilg" ]
then
# Shortcut for ilg, who has full access to the repo.
echo
echo "Enter SourceForge password for git clone"
git clone ssh://[email protected]/p/gnuarmeclipse/openocd gnuarmeclipse-openocd.git
else
# For regular read/only access, use the git url.
git clone http://git.code.sf.net/p/gnuarmeclipse/openocd gnuarmeclipse-openocd.git
fi
# Change to the gnuarmeclipse branch. On subsequent runs use "git pull".
cd "${OPENOCD_GIT_FOLDER}"
git checkout gnuarmeclipse
git submodule update
# ---- Prepare autotools -----
echo
echo "bootstrap..."
cd "${OPENOCD_GIT_FOLDER}"
./bootstrap
fi
# Get the current Git branch name, to know if we are building the stable or
# the development release.
cd "${OPENOCD_GIT_FOLDER}"
OPENOCD_GIT_HEAD=$(git symbolic-ref -q --short HEAD)
# ----- Build the USB libraries -----
# Both USB libraries are available from a single project LIBUSB
# http://www.libusb.info
# with source files ready to download from SourceForge
# https://sourceforge.net/projects/libusb/files
# Download the new USB library.
LIBUSB1_ARCHIVE="${LIBUSB1}.tar.bz2"
if [ ! -f "${OPENOCD_DOWNLOAD_FOLDER}/${LIBUSB1_ARCHIVE}" ]
then
mkdir -p "${OPENOCD_DOWNLOAD_FOLDER}"
cd "${OPENOCD_DOWNLOAD_FOLDER}"
"${WGET}" "http://sourceforge.net/projects/libusb/files/libusb-1.0/${LIBUSB1}/${LIBUSB1_ARCHIVE}" \
"${WGET_OUT}" "${LIBUSB1_ARCHIVE}"
fi
# Unpack the new USB library.
if [ ! -d "${OPENOCD_WORK_FOLDER}/${LIBUSB1}" ]
then
cd "${OPENOCD_WORK_FOLDER}"
tar -xjvf "${OPENOCD_DOWNLOAD_FOLDER}/${LIBUSB1_ARCHIVE}"
fi
# Build and install the new USB library.
if [ ! \( -d "${OPENOCD_BUILD_FOLDER}/${LIBUSB1}" \) -o \
! \( -f "${OPENOCD_INSTALL_FOLDER}/lib/libusb-1.0.a" -o \
-f "${OPENOCD_INSTALL_FOLDER}/lib64/libusb-1.0.a" \) ]
then
rm -rf "${OPENOCD_BUILD_FOLDER}/${LIBUSB1}"
mkdir -p "${OPENOCD_BUILD_FOLDER}/${LIBUSB1}"
mkdir -p "${OPENOCD_INSTALL_FOLDER}"
cd "${OPENOCD_BUILD_FOLDER}/${LIBUSB1}"
# Configure
CFLAGS="-Wno-non-literal-null-conversion -m${TARGET_BITS}" \
"${OPENOCD_WORK_FOLDER}/${LIBUSB1}/configure" \
--prefix="${OPENOCD_INSTALL_FOLDER}"
# Build
make ${MAKE_JOBS} clean install
fi
# http://www.libusb.org
# Download the old USB library.
LIBUSB0_ARCHIVE="${LIBUSB0}.tar.bz2"
if [ ! -f "${OPENOCD_DOWNLOAD_FOLDER}/${LIBUSB0_ARCHIVE}" ]
then
mkdir -p "${OPENOCD_DOWNLOAD_FOLDER}"
cd "${OPENOCD_DOWNLOAD_FOLDER}"
"${WGET}" "http://sourceforge.net/projects/libusb/files/libusb-compat-0.1/${LIBUSB0}/${LIBUSB0_ARCHIVE}" \
"${WGET_OUT}" "${LIBUSB0_ARCHIVE}"
fi
# Unpack the old USB library.
if [ ! -d "${OPENOCD_WORK_FOLDER}/${LIBUSB0}" ]
then
cd "${OPENOCD_WORK_FOLDER}"
tar -xjvf "${OPENOCD_DOWNLOAD_FOLDER}/${LIBUSB0_ARCHIVE}"
fi
# Build and install the old USB library.
if [ ! \( -d "${OPENOCD_BUILD_FOLDER}/${LIBUSB0}" \) -o \
! \( -f "${OPENOCD_INSTALL_FOLDER}/lib/libusb.a" -o \
-f "${OPENOCD_INSTALL_FOLDER}/lib64/libusb.a" \) ]
then
rm -rf "${OPENOCD_BUILD_FOLDER}/${LIBUSB0}"
mkdir -p "${OPENOCD_BUILD_FOLDER}/${LIBUSB0}"
mkdir -p "${OPENOCD_INSTALL_FOLDER}"
cd "${OPENOCD_BUILD_FOLDER}/${LIBUSB0}"
# Configure
CFLAGS="-m${TARGET_BITS}" \
\
PKG_CONFIG_LIBDIR=\
"${OPENOCD_INSTALL_FOLDER}/lib/pkgconfig":\
"${OPENOCD_INSTALL_FOLDER}/lib64/pkgconfig" \
\
"${OPENOCD_WORK_FOLDER}/${LIBUSB0}/configure" \
--prefix="${OPENOCD_INSTALL_FOLDER}"
# Build
make ${MAKE_JOBS} clean install
fi
# ----- Build the FTDI library -----
# There are two versions of the FDDI library; we recommend using the
# open source one, available from intra2net.
# http://www.intra2net.com/en/developer/libftdi/
# Download the FTDI library.
LIBFTDI_ARCHIVE="${LIBFTDI}.tar.bz2"
if [ ! -f "${OPENOCD_DOWNLOAD_FOLDER}/${LIBFTDI_ARCHIVE}" ]
then
mkdir -p "${OPENOCD_DOWNLOAD_FOLDER}"
cd "${OPENOCD_DOWNLOAD_FOLDER}"
"${WGET}" "http://www.intra2net.com/en/developer/libftdi/download/${LIBFTDI_ARCHIVE}" \
"${WGET_OUT}" "${LIBFTDI_ARCHIVE}"
fi
# Unpack the FTDI library.
if [ ! -d "${OPENOCD_WORK_FOLDER}/${LIBFTDI}" ]
then
cd "${OPENOCD_WORK_FOLDER}"
tar -xjvf "${OPENOCD_DOWNLOAD_FOLDER}/${LIBFTDI_ARCHIVE}"
cd "${OPENOCD_WORK_FOLDER}/${LIBFTDI}"
# Patch to prevent the use of system libraries and force the use of local ones.
patch -p0 < "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/patches/${LIBFTDI}-cmake-FindUSB1.patch"
fi
# Build and install the FTDI library.
if [ ! \( -d "${OPENOCD_BUILD_FOLDER}/${LIBFTDI}" \) -o \
! \( -f "${OPENOCD_INSTALL_FOLDER}/lib/libftdi1.a" -o \
-f "${OPENOCD_INSTALL_FOLDER}/lib64/libftdi1.a" \) ]
then
rm -rf "${OPENOCD_BUILD_FOLDER}/${LIBFTDI}"
mkdir -p "${OPENOCD_BUILD_FOLDER}/${LIBFTDI}"
mkdir -p "${OPENOCD_INSTALL_FOLDER}"
echo
echo "cmake libftdi..."
cd "${OPENOCD_BUILD_FOLDER}/${LIBFTDI}"
# cmake
CFLAGS="-m${TARGET_BITS}" \
\
PKG_CONFIG_LIBDIR=\
"${OPENOCD_INSTALL_FOLDER}/lib/pkgconfig":\
"${OPENOCD_INSTALL_FOLDER}/lib64/pkgconfig" \
\
cmake \
-DCMAKE_INSTALL_PREFIX="${OPENOCD_INSTALL_FOLDER}" \
-DBUILD_TESTS:BOOL=off \
-DFTDIPP:BOOL=off \
-DPYTHON_BINDINGS:BOOL=off \
-DEXAMPLES:BOOL=off \
-DDOCUMENTATION:BOOL=off \
-DFTDI_EEPROM:BOOL=off \
"${OPENOCD_WORK_FOLDER}/${LIBFTDI}"
# Build
make ${MAKE_JOBS} clean install
fi
# ----- Build the HDI library -----
# This is just a simple wrapper over libusb.
# http://www.signal11.us/oss/hidapi/
# Download the HDI library.
HIDAPI_ARCHIVE="${HIDAPI}.zip"
if [ ! -f "${OPENOCD_DOWNLOAD_FOLDER}/${HIDAPI_ARCHIVE}" ]
then
mkdir -p "${OPENOCD_DOWNLOAD_FOLDER}"
cd "${OPENOCD_DOWNLOAD_FOLDER}"
"${WGET}" "https://github.com/downloads/signal11/hidapi/${HIDAPI_ARCHIVE}" \
"${WGET_OUT}" "${HIDAPI_ARCHIVE}"
fi
# Unpack the HDI library.
if [ ! -d "${OPENOCD_WORK_FOLDER}/${HIDAPI}" ]
then
cd "${OPENOCD_WORK_FOLDER}"
unzip "${OPENOCD_DOWNLOAD_FOLDER}/${HIDAPI_ARCHIVE}"
fi
if [ ! \( -d "${OPENOCD_BUILD_FOLDER}/${HIDAPI}" \) -o \
! \( -f "${OPENOCD_INSTALL_FOLDER}/lib/libhid.a" \) ]
then
rm -rf "${OPENOCD_BUILD_FOLDER}/${HIDAPI}"
mkdir -p "${OPENOCD_BUILD_FOLDER}/${HIDAPI}"
cp -r "${OPENOCD_WORK_FOLDER}/${HIDAPI}/"* \
"${OPENOCD_BUILD_FOLDER}/${HIDAPI}"
echo
echo "make libhid..."
cd "${OPENOCD_BUILD_FOLDER}/${HIDAPI}/${HIDAPI_TARGET}"
CFLAGS="-m${TARGET_BITS}" \
\
PKG_CONFIG_LIBDIR=\
"${OPENOCD_INSTALL_FOLDER}/lib/pkgconfig":\
"${OPENOCD_INSTALL_FOLDER}/lib64/pkgconfig": \
\
make clean "${HIDAPI_OBJECT}"
# Make just compiles the file. Create the archive.
# No dynamic/shared libs involved.
ar -r libhid.a ${HIDAPI_OBJECT}
ranlib libhid.a
mkdir -p "${OPENOCD_INSTALL_FOLDER}/lib"
cp -v libhid.a \
"${OPENOCD_INSTALL_FOLDER}/lib"
mkdir -p "${OPENOCD_INSTALL_FOLDER}/lib/pkgconfig"
sed -e "s|XXX|${OPENOCD_INSTALL_FOLDER}|" \
"${OPENOCD_GIT_FOLDER}/gnuarmeclipse/pkgconfig/${HIDAPI}-${HIDAPI_TARGET}.pc" \
> "${OPENOCD_INSTALL_FOLDER}/lib/pkgconfig/hidapi.pc"
mkdir -p "${OPENOCD_INSTALL_FOLDER}/include/hidapi"
cp -v "${OPENOCD_WORK_FOLDER}/${HIDAPI}/hidapi/hidapi.h" \
"${OPENOCD_INSTALL_FOLDER}/include/hidapi"
fi
# On first run, create the build folder.
mkdir -p "${OPENOCD_BUILD_FOLDER}/openocd"
# ----- End of common part ----------------------------------------------------
# Configure OpenOCD. Use (more or less) the same options as Freddie Chopin.
if [ ! \( -d "${OPENOCD_BUILD_FOLDER}/openocd" \) -o \
! \( -f "${OPENOCD_BUILD_FOLDER}/openocd/config.h" \) ]
then
echo
echo "configure..."
mkdir -p "${OPENOCD_BUILD_FOLDER}/openocd"
cd "${OPENOCD_BUILD_FOLDER}/openocd"
# All variables below are passed on the command line before 'configure'.
# Be sure all these lines end in '\' to ensure lines are concatenated.
CPPFLAGS="-m${TARGET_BITS}" \
\
PKG_CONFIG_LIBDIR=\
"${OPENOCD_INSTALL_FOLDER}/lib/pkgconfig":\
"${OPENOCD_INSTALL_FOLDER}/lib64/pkgconfig" \
\
DYLD_LIBRARY_PATH=\
"${OPENOCD_INSTALL_FOLDER}/lib":\
"${DYLD_LIBRARY_PATH}" \
\
"${OPENOCD_GIT_FOLDER}/configure" \
--prefix="${OPENOCD_INSTALL_FOLDER}/openocd" \
--datarootdir="${OPENOCD_INSTALL_FOLDER}" \
--infodir="${OPENOCD_INSTALL_FOLDER}/openocd/info" \
--localedir="${OPENOCD_INSTALL_FOLDER}/openocd/locale" \
--mandir="${OPENOCD_INSTALL_FOLDER}/openocd/man" \
--docdir="${OPENOCD_INSTALL_FOLDER}/openocd/doc" \
--enable-aice \
--disable-amtjtagaccel \
--enable-armjtagew \
--enable-cmsis-dap \
--enable-ftdi \
--disable-gw16012 \
--enable-jlink \
--disable-jtag_vpi \
--enable-opendous \
--enable-openjtag_ftdi \
--enable-osbdm \
--enable-legacy-ft2232_libftdi \
--disable-parport \
--disable-parport-ppdev \
--disable-parport-giveio \
--enable-presto_libftdi \
--enable-remote-bitbang \
--enable-rlink \
--enable-stlink \
--enable-ti-icdi \
--enable-ulink \
--enable-usb-blaster-2 \
--enable-usb_blaster_libftdi \
--enable-usbprog \
--enable-vsllink
fi
# ----- Full build, with documentation -----
# The bindir and pkgdatadir are required to configure bin and scripts folders
# at the same level in the hierarchy.
cd "${OPENOCD_BUILD_FOLDER}/openocd"
make ${MAKE_JOBS} bindir="bin" pkgdatadir="" all pdf html
# Always clear the destination folder, to have a consistent package.
echo
echo "remove install..."
rm -rf "${OPENOCD_INSTALL_FOLDER}/openocd"
# ----- Full install, including documentation -----
echo
echo "make install..."
cd "${OPENOCD_BUILD_FOLDER}/openocd"
make install-strip install-pdf install-html install-man
# ----- Copy dynamic libraries to the install bin folder -----
# Post-process dynamic libraries paths to be relative to executable folder.
# otool -L "${OPENOCD_INSTALL_FOLDER}/openocd/bin/openocd"
install_name_tool -change "libftdi1.2.dylib" "@executable_path/libftdi1.2.dylib" \
"${OPENOCD_INSTALL_FOLDER}/openocd/bin/openocd"
install_name_tool -change "${OPENOCD_INSTALL_FOLDER}/lib/libusb-1.0.0.dylib" \
"@executable_path/libusb-1.0.0.dylib" "${OPENOCD_INSTALL_FOLDER}/openocd/bin/openocd"
install_name_tool -change "${OPENOCD_INSTALL_FOLDER}/lib/libusb-0.1.4.dylib" \
"@executable_path/libusb-0.1.4.dylib" "${OPENOCD_INSTALL_FOLDER}/openocd/bin/openocd"
otool -L "${OPENOCD_INSTALL_FOLDER}/openocd/bin/openocd"
DLIB="libftdi1.2.dylib"
cp "${OPENOCD_INSTALL_FOLDER}/lib/libftdi1.2.2.0.dylib" \
"${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
# otool -L "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
install_name_tool -id "${DLIB}" "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
install_name_tool -change "${OPENOCD_INSTALL_FOLDER}/lib/libusb-1.0.0.dylib" \
"@executable_path/libusb-1.0.0.dylib" "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
otool -L "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
DLIB="libusb-0.1.4.dylib"
cp "${OPENOCD_INSTALL_FOLDER}/lib/libusb-0.1.4.dylib" \
"${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
# otool -L "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
install_name_tool -id "${DLIB}" "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
install_name_tool -change "${OPENOCD_INSTALL_FOLDER}/lib/libusb-1.0.0.dylib" \
"@executable_path/libusb-1.0.0.dylib" "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
otool -L "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
DLIB="libusb-1.0.0.dylib"
cp "${OPENOCD_INSTALL_FOLDER}/lib/libusb-1.0.0.dylib" \
"${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
# otool -L "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
install_name_tool -id "${DLIB}" "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
otool -L "${OPENOCD_INSTALL_FOLDER}/openocd/bin/${DLIB}"
# ----- Copy the license files -----
echo
echo "copy license files..."
mkdir -p "${OPENOCD_INSTALL_FOLDER}/openocd/license/openocd"
/usr/bin/install -c -m 644 "${OPENOCD_GIT_FOLDER}/AUTHORS" \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/openocd"
/usr/bin/install -c -m 644 "${OPENOCD_GIT_FOLDER}/COPYING" \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/openocd"
/usr/bin/install -c -m 644 "${OPENOCD_GIT_FOLDER}/"NEWS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/openocd"
/usr/bin/install -c -m 644 "${OPENOCD_GIT_FOLDER}/"README* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/openocd"
mkdir -p "${OPENOCD_INSTALL_FOLDER}/openocd/license/${HIDAPI}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${HIDAPI}/"AUTHORS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${HIDAPI}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${HIDAPI}/"LICENSE* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${HIDAPI}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${HIDAPI}/"README* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${HIDAPI}"
mkdir -p "${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBFTDI}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBFTDI}/"AUTHORS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBFTDI}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBFTDI}/"COPYING* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBFTDI}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBFTDI}/"LICENSE* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBFTDI}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBFTDI}/"README* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBFTDI}"
mkdir -p "${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB1}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB1}/"AUTHORS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB1}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB1}/"COPYING* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB1}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB1}/"NEWS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB1}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB1}/"README* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB1}"
mkdir -p "${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB0}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB0}/"AUTHORS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB0}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB0}/"COPYING* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB0}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB0}/"LICENSE* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB0}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB0}/"NEWS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB0}"
/usr/bin/install -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB0}/"README* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB0}"
# ----- Copy the GNU ARM Eclipse info files -----
echo
echo "copy info files..."
/usr/bin/install -c -m 644 "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/info/INFO-osx.txt" \
"${OPENOCD_INSTALL_FOLDER}/openocd/INFO.txt"
mkdir -p "${OPENOCD_INSTALL_FOLDER}/openocd/gnuarmeclipse"
/usr/bin/install -c -m 644 "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/info/BUILD-osx.txt" \
"${OPENOCD_INSTALL_FOLDER}/openocd/gnuarmeclipse/BUILD.txt"
/usr/bin/install -c -m 644 "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/info/CHANGES.txt" \
"${OPENOCD_INSTALL_FOLDER}/openocd/gnuarmeclipse/"
/usr/bin/install -c -m 644 "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/scripts/build-openocd-osx.sh" \
"${OPENOCD_INSTALL_FOLDER}/openocd/gnuarmeclipse/"
# ----- Create the distribution installer -----
mkdir -p "${OPENOCD_OUTPUT}"
# The UTC date part in the name of the archive.
OUTFILE_DATE=${OUTFILE_DATE:-$(date -u +%Y%m%d%H%M)}
if [ "${OPENOCD_GIT_HEAD}" == "gnuarmeclipse" ]
then
OUTFILE_VERSION=$(cat "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/VERSION")-${OUTFILE_DATE}
elif [ "${OPENOCD_GIT_HEAD}" == "gnuarmeclipse-dev" ]
then
OUTFILE_VERSION=$(cat "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/VERSION-dev")-${OUTFILE_DATE}-dev
fi
OPENOCD_INSTALLER="${OPENOCD_OUTPUT}/gnuarmeclipse-openocd-\
${OPENOCD_TARGET}-${OUTFILE_VERSION}.pkg"
echo
echo "create installer package..."
echo
# Create the installer package, with content from the
# ${OPENOCD_INSTALL_FOLDER}/openocd folder.
# The "${INSTALL_FOLDER:1}" is a substring that skips first char.
cd "${OPENOCD_WORK_FOLDER}"
pkgbuild --identifier ilg.gnuarmeclipse.openocd \
--root "${OPENOCD_INSTALL_FOLDER}/openocd" \
--version "${OUTFILE_VERSION}" \
--install-location "${INSTALL_FOLDER:1}/${OUTFILE_VERSION}" \
"${OPENOCD_INSTALLER}"
echo
ls -l "${OPENOCD_INSTALL_FOLDER}/openocd/bin"
# Check if the application starts (if all dynamic libraries are available).
echo
"${OPENOCD_INSTALL_FOLDER}/openocd/bin/openocd" --version
RESULT="$?"
echo
if [ "${RESULT}" == "0" ]
then
echo "Build completed."
echo "File ${OPENOCD_INSTALLER} created."
else
echo "Buld failed."
fi
exit 0