-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-openocd.sh
executable file
·149 lines (120 loc) · 4.57 KB
/
build-openocd.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
#!/bin/bash
# Dependencies:
#
# git
# gcc
# cmake
# autotools
# pkg-config
#
# Linux: libudev-dev
# macOS: Homebrew (https://brew.sh)
# Windows: MSYS2 (https://www.msys2.org)
#
# MSYS2 installation notes:
# https://github.com/orlp/dev-on-windows/wiki/Installing-GCC--&-MSYS2
set -ex
# OPENOCD_GIT_URL=https://github.com/particle-iot/openocd
# OPENOCD_GIT_TAG=0b88dcc59c51e3999d56dfa90eec945cff54c9d8
LIBUSB_GIT_URL=https://github.com/libusb/libusb.git
LIBUSB_GIT_TAG=v1.0.24
HIDAPI_GIT_URL=https://github.com/libusb/hidapi.git
HIDAPI_GIT_TAG=hidapi-0.14.0
LIBFTDI_GIT_URL=git://developer.intra2net.com/libftdi
LIBFTDI_GIT_TAG=v1.5
CAPSTONE_GIT_URL=https://github.com/capstone-engine/capstone.git
CAPSTONE_GIT_TAG=5.0.1
CAPSTONE_CONFIG="CAPSTONE_BUILD_CORE_ONLY=yes CAPSTONE_SHARED=yes"
# Environment-specific settings
cmake_generator="Unix Makefiles"
cmake_command=cmake
if [[ $OSTYPE == darwin* ]]; then
export MACOSX_DEPLOYMENT_TARGET=10.7
elif [[ $OSTYPE == msys ]]; then
cmake_generator="MSYS Makefiles"
cmake_command=/mingw64/bin/cmake
fi
# This script's directory
script_dir=$(cd $(dirname $0) && pwd)
cd $script_dir
# Build directory
build_dir=$script_dir/.build
rm -rf $build_dir && mkdir -p $build_dir
# Temporary installation directory for dependencies
local_dir=$script_dir/.local
rm -rf $local_dir && mkdir -p $local_dir
# Destination directory for OpenOCD files
target_dir=$script_dir/openocd
rm -rf $target_dir && mkdir -p $target_dir
# Path to local pkg-config files
export PKG_CONFIG_PATH=$local_dir/lib/pkgconfig
# Do this just for MacOS
if [[ $OSTYPE == darwin* ]]; then
echo "Building capstone"
echo $target_dir
cd $build_dir
git clone $CAPSTONE_GIT_URL capstone && cd capstone
git checkout $CAPSTONE_GIT_TAG
git submodule update --init --recursive
make install PREFIX=$local_dir $CAPSTONE_CONFIG
fi
echo "Building libusb"
cd $build_dir
git clone $LIBUSB_GIT_URL libusb && cd libusb
git checkout $LIBUSB_GIT_TAG
git submodule update --init --recursive
./bootstrap.sh
./configure --prefix=$local_dir
make && make install
echo "Building hidapi"
cd $build_dir
git clone $HIDAPI_GIT_URL hidapi && cd hidapi
git checkout $HIDAPI_GIT_TAG
git submodule update --init --recursive
./bootstrap
./configure --prefix=$local_dir
make && make install
echo "Building libftdi"
cd $build_dir
git clone $LIBFTDI_GIT_URL libftdi && cd libftdi
git checkout $LIBFTDI_GIT_TAG
git submodule update --init --recursive
mkdir .build && cd .build
$cmake_command .. -G "$cmake_generator" -DCMAKE_INSTALL_PREFIX:PATH=$local_dir -DFTDI_EEPROM=OFF -DEXAMPLES=OFF
make && make install
echo "Building openocd"
cd $script_dir
# git clone $OPENOCD_GIT_URL openocd && cd openocd
# git checkout $OPENOCD_GIT_TAG
git submodule update --init --recursive
./bootstrap
./configure --prefix=$target_dir --disable-werror --without-capstone
make && make install
# Copy dependencies to libexec for Mac and Linux, and set the Runtime Library Search Path
# For Windows, copy the dlls to the bin directory since Windows will search for them there
if [[ $OSTYPE == linux-gnu ]]; then
mkdir -p $target_dir/libexec
cp -P $local_dir/lib/*.so $local_dir/lib/*.so.* $target_dir/libexec
# Set the Runtime Library Search Path for Linux to load dependencies from libexec
patchelf --set-rpath '$ORIGIN/../libexec' $target_dir/bin/openocd
elif [[ $OSTYPE == darwin* ]]; then
mkdir -p $target_dir/libexec
cp -P -R $local_dir/lib/*.dylib $target_dir/libexec
# Set the Runtime Library Search Path for Mac to load dependencies from libexec
install_name_tool -add_rpath '@loader_path/../libexec' $target_dir/bin/openocd
install_name_tool -add_rpath @loader_path/libexec $target_dir/bin/openocd
install_name_tool -add_rpath @executable_path/../libexec $target_dir/bin/openocd
# Re-link libraries
install_name_tool -change libftdi1.2.dylib @rpath/libftdi1.2.dylib $target_dir/bin/openocd
install_name_tool -change /Users/runner/work/openocd/openocd/.local/lib/libusb-1.0.0.dylib @rpath/libusb-1.0.0.dylib $target_dir/bin/openocd
install_name_tool -change /Users/runner/work/openocd/openocd/.local/lib/libhidapi.0.dylib @rpath/libhidapi.0.dylib $target_dir/bin/openocd
# link libusb-1.0.0.dylib to libftdi1.2.dylib
install_name_tool -change /usr/local/opt/libusb/lib/libusb-1.0.0.dylib @rpath/libusb-1.0.0.dylib $target_dir/libexec/libftdi1.2.dylib
elif [[ $OSTYPE == msys ]]; then
cp $local_dir/bin/*.dll $target_dir/bin
# MinGW runtime libraries
mingw_dir=$(dirname $(which gcc))
cp $mingw_dir/libwinpthread-1.dll $target_dir/bin
# This library seems to be available only on 32-bit platforms
cp $mingw_dir/libgcc_s_dw2-1.dll $target_dir/bin || true
fi