-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·217 lines (171 loc) · 4.67 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
#!/bin/bash
set -x
LIBUSB_REPOS=https://github.com/libusb/libusb
LIBUSB_VERSION=1.0.23
LIBUSB_ARCHIVE=libusb-${LIBUSB_VERSION}.tar.bz2
HIDAPI_REPOS=https://github.com/libusb/hidapi
HIDAPI_VERSION=0.9.0
HIDAPI_ARCHIVE=hidapi-${HIDAPI_VERSION}.tar.gz
# OpenOCD version would be replaced with actual version
OPENOCD_VERSION=0.11.0
OPENOCD_MODVERSION=spr1
OPENOCDDIR=${OPENOCDDIR:-/tmp/openocd}
DISTDIR=/tmp/dist
OPENOCD_CONFIGOPTS="--disable-ftdi \
--disable-stlink \
--disable-ti-icdi \
--disable-ulink \
--disable-usb-blaster-2 \
--disable-ft232r \
--disable-vsllink \
--disable-xds110 \
--disable-osbdm \
--disable-opendous \
--disable-aice \
--disable-usbprog \
--disable-esp-usb-jtag \
--disable-nulink \
--disable-rlink \
--disable-armjtagew \
--enable-cmsis-dap \
--disable-kitprog \
--disable-usb-blaster \
--disable-presto \
--disable-openjtag \
--disable-buspirate \
--disable-jlink"
if [ ! -d $OPENOCDDIR ]; then
echo "OpenOCD source directory not found. Please clone OpenOCD first!"
exit 1
fi
if [ "$1" = "-h" ]; then
echo "$0 [win32|win64]"
exit 1
fi
# Determine native platform target
PLATFORM=`uname -s`
case "${PLATFORM}" in
Linux)
TARGET=linux64
;;
Darwin)
TARGET=macosx
;;
esac
# Take first option [win32|win64|linux32].
if [ "$1" = "win64" ]; then
CROSS_COMPILE="--host=x86_64-w64-mingw32"
TARGET=win64
fi
if [ "$1" = "win32" ]; then
CROSS_COMPILE="--host=i686-w64-mingw32"
TARGET=win32
fi
if [ "$1" = "linux32" ]; then
CROSS_COMPILE="--host=i686-linux-gnu"
TARGET=linux32
fi
if [ ! -z "${CROSS_COMPILE}" -a "${PLATFORM}" = "Darwin" ]; then
echo Sorry, windows cross compile not supported in mac.
exit 1
fi
rm -rf ${DISTDIR}
mkdir -p archives
# Download library sources
if [ ! -f archives/${LIBUSB_ARCHIVE} ]; then
curl -L ${LIBUSB_REPOS}/releases/download/v${LIBUSB_VERSION}/${LIBUSB_ARCHIVE} > archives/${LIBUSB_ARCHIVE}
fi
if [ ! -f archives/${HIDAPI_ARCHIVE} ]; then
curl -L ${HIDAPI_REPOS}/archive/${HIDAPI_ARCHIVE} > archives/${HIDAPI_ARCHIVE}
fi
# In MacOSX, we need to replace the dynamic library ID to be able to find
# from OpenOCD executable in installed place.
preinstall_lib()
{
name=`otool -D $1 | tail -n +2`
newname=${name/${DISTDIR}/@executable_path/..}
install_name_tool -id $newname $1
}
install_libusb()
{
SRCDIR=/tmp/libusb
rm -rf ${SRCDIR}
mkdir ${SRCDIR}
tar jxf archives/${LIBUSB_ARCHIVE} --strip-components=1 -C ${SRCDIR}
cd ${SRCDIR}
./configure --prefix=${DISTDIR} ${CROSS_COMPILE} || exit 1
make || exit 1
if [ "${PLATFORM}" = "Darwin" ]; then
preinstall_lib libusb/.libs/libusb-1.0.0.dylib
fi
make install || exit 1
cd -
}
install_hidapi()
{
SRCDIR=/tmp/hidapi
rm -rf ${SRCDIR}
mkdir ${SRCDIR}
tar zxf archives/${HIDAPI_ARCHIVE} --strip-components=1 -C ${SRCDIR}
# Do not use realpath, it can not used on macOS.
# This patch file is for macOS only.
PATCHFILE=$(pwd)/hidapi-00-configure.patch
cd ${SRCDIR}
if [ "${PLATFORM}" = "Darwin" ]; then
patch -p1 < $PATCHFILE
fi
./bootstrap || exit 1
PKG_CONFIG_PATH=${DISTDIR}/lib/pkgconfig \
./configure --prefix=${DISTDIR} ${CROSS_COMPILE} || exit 1
make || exit 1
if [ "${PLATFORM}" = "Darwin" ]; then
preinstall_lib mac/.libs/libhidapi.0.dylib
fi
make install || exit 1
cd -
}
install_openocd()
{
BUILDDIR=/tmp/build-openocd
cd $OPENOCDDIR
git clean -xdf
git -C jimtcl clean -xdf
./bootstrap || exit 1
cd -
mkdir -p $BUILDDIR
cd $BUILDDIR
LDFLAGS='-Wl,-rpath -Wl,"\$\$$ORIGIN/../lib"' \
PKG_CONFIG_PATH=${DISTDIR}/lib/pkgconfig \
$OPENOCDDIR/configure --prefix=${DISTDIR} ${CROSS_COMPILE} ${OPENOCD_CONFIGOPTS} || exit 1
make clean
make || exit 1
make install || exit 1
cd -
}
# Build and install openocd and libraries into temporary directory.
install_libusb
install_hidapi
install_openocd
# Get latest commit date for use package name
cd $OPENOCDDIR
LATEST_DATE=`git show --format=format:%ci -s | cut -f 1 -d ' ' | sed -e 's/-//g'`
if [ -e configure ]; then
# Get version from configure script
eval `grep PACKAGE_VERSION= configure`
OPENOCD_VERSION=$PACKAGE_VERSION
fi
cd -
# Create release archive
mkdir -p dist
package=openocd-${OPENOCD_VERSION}-${OPENOCD_MODVERSION}-${LATEST_DATE}
rm -rf ${package}
mv ${DISTDIR} ${package}
if [ "$TARGET" = "win32" -o "$TARGET" = "win64" ]; then
distfile=${package}-${TARGET}.zip
zip -q -r dist/${distfile} ${package}
else
distfile=${package}-${TARGET}.tar.bz2
tar cjf dist/${distfile} ${package}
fi
(cd dist; shasum -a 256 ${distfile} > ${distfile}.sha)
rm -rf ${package}