-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-openocd-linux.sh
859 lines (709 loc) · 25.4 KB
/
build-openocd-linux.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
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Script to build the GNU/Linux version of OpenOCD.
# Developed on Debian 7.
# Also tested on:
# Ubuntu 14.04 LTS
# Manjaro 0.8.11
# Fedora 21.
#
# Prerequisites:
#
# sudo apt-get install git libtool autoconf automake autotools-dev pkg-config
# sudo apt-get install texinfo texlive doxygen
# sudo apt-get install cmake libudev-dev
# sudo apt-get install libconfuse-dev g++ libboost1.49-dev
# ----- Determine distribution name and word size -----
set +e
DISTRO_NAME=$(lsb_release -si | tr "[:upper:]" "[:lower:]")
set -e
if [ ! -z "${DISTRO_NAME}" ]
then
echo $(lsb_release -i)
else
echo "Please install the lsb core package and rerun."
DISTRO_NAME="linux"
fi
if [ "$(uname -m)" == "x86_64" ]
then
DISTRO_BITS="64"
DISTRO_MACHINE="x86_64"
elif [ "$(uname -m)" == "i686" ]
then
DISTRO_BITS="32"
DISTRO_MACHINE="i386"
else
echo "Unknown uname -m $(uname -m)"
exit 1
fi
# ----- Parse actions and command line options -----
ACTION_CLEAN=""
ACTION_GIT=""
ACTION_INSTALL=""
TARGET_BITS="${DISTRO_BITS}"
while [ $# -gt 0 ]
do
if [ "$1" == "clean" ]
then
ACTION_CLEAN="$1"
elif [ "$1" == "pull" ]
then
ACTION_GIT="$1"
elif [ "$1" == "install" ]
then
ACTION_INSTALL="$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 /root/Host/Work ]
then
OPENOCD_WORK_FOLDER=${OPENOCD_WORK_FOLDER:-"/root/Host/Work/openocd"}
elif [ -d /media/psf/Home/Work ]
then
OPENOCD_WORK_FOLDER=${OPENOCD_WORK_FOLDER:-"/media/psf/Home/Work/openocd"}
elif [ -d /media/${USER}/Work ]
then
OPENOCD_WORK_FOLDER=${OPENOCD_WORK_FOLDER:-"/media/${USER}/Work/openocd"}
elif [ -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 is installed.
# If you prefer to install in different location, like in your home folder,
# define it before invoking the script.
SYSTEM_INSTALL_FOLDER=${SYSTEM_INSTALL_FOLDER:-"/opt/gnuarmeclipse"}
# PKG_CONFIG_PATH=${PKG_CONFIG_PATH:-""}
PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR:-""}
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-""}
MAKE_JOBS=${MAKE_JOBS:-"-j4"}
# ----- 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="linux"
HIDAPI_OBJECT="hid-libusb.o"
# OpenOCD build defs
OPENOCD_TARGET="${DISTRO_NAME}${TARGET_BITS}"
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 -----
gcc --version
git --version >/dev/null
automake --version >/dev/null
cmake --version >/dev/null
readelf --version >/dev/null
# 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_INSTALL}" == "install" ]
then
# Always clear the destination folder, to have a consistent package.
rm -rfv "${SYSTEM_INSTALL_FOLDER}/openocd"
mkdir -p "${SYSTEM_INSTALL_FOLDER}"
# Transfer the install folder to the final destination.
# Use tar to preserve rights.
cd "${OPENOCD_INSTALL_FOLDER}"
tar c -z --owner root --group root -f - openocd | tar x -z -f - -C "${SYSTEM_INSTALL_FOLDER}"
# Display some information about the created application.
echo
echo "Libraries:"
readelf -d "${OPENOCD_INSTALL_FOLDER}/openocd/bin/openocd" | grep -i 'library'
# Check if the application starts (if all dynamic libraries are available).
echo
"${SYSTEM_INSTALL_FOLDER}/openocd/bin/openocd" --version
RESULT="$?"
echo
if [ "${RESULT}" == "0" ]
then
echo "Installed. (Configure openocd_path to ${SYSTEM_INSTALL_FOLDER}/openocd/bin)."
else
echo "Install failed."
fi
exit 0
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 the same options as Freddie Chopin.
if [ ! \( -d "${OPENOCD_BUILD_FOLDER}/openocd" \) -o \
! \( -f "${OPENOCD_BUILD_FOLDER}/openocd/config.h" \) ]
then
echo
echo "configure..."
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.
# On some machines libftdi ends in lib64, so we refer both lib & lib64
CPPFLAGS="-m${TARGET_BITS}" \
LDFLAGS='-Wl,-rpath=\$$ORIGIN -lpthread' \
\
PKG_CONFIG_LIBDIR=\
"${OPENOCD_INSTALL_FOLDER}/lib/pkgconfig":\
"${OPENOCD_INSTALL_FOLDER}/lib64/pkgconfig" \
\
LD_LIBRARY_PATH=\
"${OPENOCD_INSTALL_FOLDER}/lib":\
"${OPENOCD_INSTALL_FOLDER}/lib64":\
"${LD_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 \
--enable-amtjtagaccel \
--enable-armjtagew \
--enable-cmsis-dap \
--enable-ftdi \
--enable-gw16012 \
--enable-jlink \
--enable-jtag_vpi \
--enable-opendous \
--enable-openjtag_ftdi \
--enable-osbdm \
--enable-legacy-ft2232_libftdi \
--enable-parport \
--disable-parport-ppdev \
--enable-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
# Note: a very important detail here is LDFLAGS='-Wl,-rpath=\$$ORIGIN which
# adds a special record to the ELF file asking the loader to search for the
# libraries first in the same folder where the executable is located. The
# task is complicated due to the multiple substitutions that are done on
# the way, and need to be escaped.
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 -----
echo
echo "copy shared libs..."
ILIB=$(find "${OPENOCD_INSTALL_FOLDER}/lib"* -type f -name 'libusb-1.0.so.*.*' -print)
if [ ! -z "${ILIB}" ]
then
echo "Found ${ILIB}"
ILIB_BASE="$(basename ${ILIB})"
/usr/bin/install -v -c -m 644 "${ILIB}" \
"${OPENOCD_INSTALL_FOLDER}/openocd/bin"
ILIB_SHORT="$(echo $ILIB_BASE | sed -e 's/\([[:alnum:]]*\)[.]\([[:alnum:]]*\)[.]\([[:digit:]]*\)[.].*/\1.\2.\3/')"
(cd "${OPENOCD_INSTALL_FOLDER}/openocd/bin"; ln -sv "${ILIB_BASE}" "${ILIB_SHORT}")
ILIB_SHORT="$(echo $ILIB_BASE | sed -e 's/\([[:alnum:]]*\)[.]\([[:alnum:]]*\)[.]\([[:digit:]]*\)[.].*/\1.\2/')"
(cd "${OPENOCD_INSTALL_FOLDER}/openocd/bin"; ln -sv "${ILIB_BASE}" "${ILIB_SHORT}")
fi
ILIB=$(find "${OPENOCD_INSTALL_FOLDER}/lib"* -type f -name 'libusb-0.1.so.*.*' -print)
if [ ! -z "${ILIB}" ]
then
echo "Found ${ILIB}"
ILIB_BASE="$(basename ${ILIB})"
/usr/bin/install -v -c -m 644 "${ILIB}" \
"${OPENOCD_INSTALL_FOLDER}/openocd/bin"
ILIB_SHORT="$(echo $ILIB_BASE | sed -e 's/\([[:alnum:]]*\)[.]\([[:alnum:]]*\)[.]\([[:digit:]]*\)[.].*/\1.\2.\3/')"
(cd "${OPENOCD_INSTALL_FOLDER}/openocd/bin"; ln -sv "${ILIB_BASE}" "${ILIB_SHORT}")
ILIB_SHORT="$(echo $ILIB_BASE | sed -e 's/\([[:alnum:]]*\)[.]\([[:alnum:]]*\)[.]\([[:digit:]]*\)[.].*/\1.\2/')"
(cd "${OPENOCD_INSTALL_FOLDER}/openocd/bin"; ln -sv "${ILIB_BASE}" "${ILIB_SHORT}")
fi
ILIB=$(find "${OPENOCD_INSTALL_FOLDER}/lib"* -type f -name 'libftdi1.so.*.*' -print)
if [ ! -z "${ILIB}" ]
then
echo "Found ${ILIB}"
ILIB_BASE="$(basename ${ILIB})"
/usr/bin/install -v -c -m 644 "${ILIB}" \
"${OPENOCD_INSTALL_FOLDER}/openocd/bin"
ILIB_SHORT="$(echo $ILIB_BASE | sed -e 's/\([[:alnum:]]*\)[.]\([[:alnum:]]*\)[.]\([[:digit:]]*\)[.].*/\1.\2.\3/')"
(cd "${OPENOCD_INSTALL_FOLDER}/openocd/bin"; ln -sv "${ILIB_BASE}" "${ILIB_SHORT}")
ILIB_SHORT="$(echo $ILIB_BASE | sed -e 's/\([[:alnum:]]*\)[.]\([[:alnum:]]*\)[.]\([[:digit:]]*\)[.].*/\1.\2/')"
(cd "${OPENOCD_INSTALL_FOLDER}/openocd/bin"; ln -sv "${ILIB_BASE}" "${ILIB_SHORT}")
fi
# Add libudev.so locally.
ILIB=$(find /lib/${DISTRO_MACHINE}-linux-gnu /usr/lib/${DISTRO_MACHINE}-linux-gnu -type f -name 'libudev.so.*.*' -print)
if [ ! -z "${ILIB}" ]
then
echo "Found ${ILIB}"
ILIB_BASE="$(basename ${ILIB})"
/usr/bin/install -v -c -m 644 "${ILIB}" \
"${OPENOCD_INSTALL_FOLDER}/openocd/bin"
ILIB_SHORT="$(echo $ILIB_BASE | sed -e 's/\([[:alnum:]]*\)[.]\([[:alnum:]]*\)[.]\([[:digit:]]*\)[.].*/\1.\2.\3/')"
(cd "${OPENOCD_INSTALL_FOLDER}/openocd/bin"; ln -sv "${ILIB_BASE}" "${ILIB_SHORT}")
ILIB_SHORT="$(echo $ILIB_BASE | sed -e 's/\([[:alnum:]]*\)[.]\([[:alnum:]]*\)[.]\([[:digit:]]*\)[.].*/\1.\2/')"
(cd "${OPENOCD_INSTALL_FOLDER}/openocd/bin"; ln -sv "${ILIB_BASE}" "${ILIB_SHORT}")
else
echo
echo 'WARNING: libudev.so not copied locally!'
if [ "${USER}" == "ilg" ]
then
exit 1
fi
fi
# Add librt.so.1 locally, to be sure it is available always.
ILIB=$(find /lib/${DISTRO_MACHINE}-linux-gnu /usr/lib/${DISTRO_MACHINE}-linux-gnu -type f -name 'librt-*.so' -print | grep -v i686)
if [ ! -z "${ILIB}" ]
then
echo "Found ${ILIB}"
ILIB_BASE="$(basename ${ILIB})"
/usr/bin/install -v -c -m 644 "${ILIB}" \
"${OPENOCD_INSTALL_FOLDER}/openocd/bin"
(cd "${OPENOCD_INSTALL_FOLDER}/openocd/bin"; ln -sv "${ILIB_BASE}" "librt.so.1")
(cd "${OPENOCD_INSTALL_FOLDER}/openocd/bin"; ln -sv "${ILIB_BASE}" "librt.so")
else
echo
echo "WARNING: librt.so not copied locally!"
if [ "${USER}" == "ilg" ]
then
exit 1
fi
fi
# ----- Copy the license files -----
echo
echo "copy license files..."
mkdir -p "${OPENOCD_INSTALL_FOLDER}/openocd/license/openocd"
/usr/bin/install -v -c -m 644 "${OPENOCD_GIT_FOLDER}/AUTHORS" \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/openocd"
/usr/bin/install -v -c -m 644 "${OPENOCD_GIT_FOLDER}/COPYING" \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/openocd"
/usr/bin/install -v -c -m 644 "${OPENOCD_GIT_FOLDER}/"NEWS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/openocd"
/usr/bin/install -v -c -m 644 "${OPENOCD_GIT_FOLDER}/"README* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/openocd"
mkdir -p "${OPENOCD_INSTALL_FOLDER}/openocd/license/${HIDAPI}"
/usr/bin/install -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${HIDAPI}/"AUTHORS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${HIDAPI}"
/usr/bin/install -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${HIDAPI}/"LICENSE* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${HIDAPI}"
/usr/bin/install -v -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 -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBFTDI}/"AUTHORS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBFTDI}"
/usr/bin/install -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBFTDI}/"COPYING* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBFTDI}"
/usr/bin/install -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBFTDI}/"LICENSE* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBFTDI}"
/usr/bin/install -v -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 -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB1}/"AUTHORS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB1}"
/usr/bin/install -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB1}/"COPYING* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB1}"
/usr/bin/install -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB1}/"NEWS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB1}"
/usr/bin/install -v -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 -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB0}/"AUTHORS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB0}"
/usr/bin/install -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB0}/"COPYING* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB0}"
/usr/bin/install -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB0}/"LICENSE* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB0}"
/usr/bin/install -v -c -m 644 "${OPENOCD_WORK_FOLDER}/${LIBUSB0}/"NEWS* \
"${OPENOCD_INSTALL_FOLDER}/openocd/license/${LIBUSB0}"
/usr/bin/install -v -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 -v -c -m 644 "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/info/INFO-linux.txt" \
"${OPENOCD_INSTALL_FOLDER}/openocd/INFO.txt"
mkdir -p "${OPENOCD_INSTALL_FOLDER}/openocd/gnuarmeclipse"
/usr/bin/install -v -c -m 644 "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/info/BUILD-linux.txt" \
"${OPENOCD_INSTALL_FOLDER}/openocd/gnuarmeclipse/BUILD.txt"
/usr/bin/install -v -c -m 644 "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/info/CHANGES.txt" \
"${OPENOCD_INSTALL_FOLDER}/openocd/gnuarmeclipse/"
/usr/bin/install -v -c -m 644 "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/scripts/$(basename $0)" \
"${OPENOCD_INSTALL_FOLDER}/openocd/gnuarmeclipse/"
# ----- Create the distribution archive ----
mkdir -p "${OPENOCD_OUTPUT}"
# Increment the revision with each new release.
OUTFILE_VERSION=$(cat "${OPENOCD_GIT_FOLDER}/gnuarmeclipse/VERSION")
# 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_ARCHIVE="${OPENOCD_OUTPUT}/gnuarmeclipse-openocd-\
${OPENOCD_TARGET}-${OUTFILE_VERSION}.tgz"
echo
echo "create tgz archive..."
echo
cd "${OPENOCD_INSTALL_FOLDER}"
mkdir ${OUTFILE_VERSION}
mv openocd/* ${OUTFILE_VERSION}
mv ${OUTFILE_VERSION} openocd
tar czf "${OPENOCD_ARCHIVE}" --owner root --group root openocd
# Display some information about the created application.
echo
echo "Libraries:"
readelf -d "${OPENOCD_INSTALL_FOLDER}/openocd/${OUTFILE_VERSION}/bin/openocd" | grep -i 'library'
echo
ls -l "${OPENOCD_INSTALL_FOLDER}/openocd/${OUTFILE_VERSION}/bin"
# Check if the application starts (if all dynamic libraries are available).
echo
"${OPENOCD_INSTALL_FOLDER}/openocd/${OUTFILE_VERSION}/bin/openocd" --version
RESULT="$?"
echo
if [ "${RESULT}" == "0" ]
then
echo "Build completed."
echo "File ${OPENOCD_ARCHIVE} created."
else
echo "Build failed."
fi
exit 0