forked from arduino/OpenOCD-build-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile_cross.sh
executable file
·145 lines (119 loc) · 4.4 KB
/
compile_cross.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
#!/bin/bash -ex
# Copyright (c) 2016 Arduino LLC
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
if [ x$CROSS_COMPILER == x ]; then
CROSS_COMPILER=${CROSS_COMPILE}-gcc
else
export CC=$CROSS_COMPILER
fi
ARCH=`$CROSS_COMPILER -v 2>&1 | awk '/Target/ { print $2 }'`
mkdir -p distrib/$ARCH
cd distrib/$ARCH
PREFIX=`pwd`
cd -
#disable pkg-config
export PKG_CONFIG_PATH=`pwd`
if [[ ${ARCH} == *mingw* ]]; then
export CFLAGS="-mno-ms-bitfields"
fi
if [[ ${ARCH} == *linux* ]]; then
cd eudev-3.1.5
export UDEV_DIR=`pwd`
./autogen.sh
./configure --enable-static --disable-shared --disable-blkid --disable-kmod --disable-manpages --host=${CROSS_COMPILE}
make clean
make -j4
cd ..
export CFLAGS="-I$UDEV_DIR/src/libudev/"
export LDFLAGS="-L$UDEV_DIR/src/libudev/.libs/"
export LIBS="-ludev"
fi
cd libusb-1.0.20
export LIBUSB_DIR=`pwd`
./configure --enable-static --disable-shared --host=${CROSS_COMPILE}
make clean
make
cd ..
export LIBUSB1_CFLAGS="-I$LIBUSB_DIR/libusb/"
export LIBUSB1_LIBS="-L$LIBUSB_DIR/libusb/.libs/ -lusb-1.0 -lpthread"
export LIBUSB_1_0_CFLAGS="-I$LIBUSB_DIR/libusb/"
export LIBUSB_1_0_LIBS="-L$LIBUSB_DIR/libusb/.libs/ -lusb-1.0 -lpthread"
cd libusb-compat-0.1.5
export LIBUSB0_DIR=`pwd`
./bootstrap.sh
./configure --enable-static --disable-shared --host=${CROSS_COMPILE}
make clean
make
cd ..
export libusb_CFLAGS="-I$LIBUSB_DIR/libusb/"
export libusb_LIBS="-L$LIBUSB_DIR/libusb/.libs/ -lusb-1.0 -lpthread"
export libudev_CFLAGS="-I$UDEV_DIR/src/libudev/"
export libudev_LIBS="-L$UDEV_DIR/src/libudev/.libs/ -ludev"
cd hidapi
./bootstrap
export HIDAPI_DIR=`pwd`
./configure --enable-static --disable-shared --host=${CROSS_COMPILE}
make clean
make -j4
cd ..
cd libftdi1-1.4
export LIBFTDI1_DIR=`pwd`
if [ -d build ]; then
rm -rf build
fi
mkdir build && cd build
if [[ ${ARCH} == *mingw* ]]; then
LIBFTDI1_EXTRAFLAGS="-DBUILD_SHARED_LIBS=OFF -DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CROSSCOMPILING=1 -DCMAKE_C_FLAGS=-fpermissive"
fi
cmake -DCMAKE_C_COMPILER=${CROSS_COMPILER} -DBUILD_TESTS=no -DDOCUMENTATION=no -DEXAMPLES=no -DFTDIPP=no -DFTDI_EEPROM=no -DLINK_PYTHON_LIBRARY=no -DPYTHON_BINDINGS=no -DCMAKE_INSTALL_PREFIX=$LIBFTDI1_DIR $LIBFTDI1_EXTRAFLAGS ..
make clean
make ftdi1-static
cd ..
cd ..
if [[ ${ARCH} == *darwin* ]]; then
x86_64-apple-darwin13-ranlib $LIBFTDI1_DIR/build/src/libftdi1.a
fi
cd OpenOCD
./bootstrap
export LIBUSB0_CFLAGS="-I$LIBUSB0_DIR/libusb/"
export LIBUSB0_LIBS="-L$LIBUSB0_DIR/libusb/.libs/ -lusb -lpthread"
export LIBUSB1_CFLAGS="-I$LIBUSB_DIR/libusb/"
export LIBUSB1_LIBS="-L$LIBUSB_DIR/libusb/.libs/ -lusb-1.0 -lpthread"
export LIBFTDI_CFLAGS="-I$LIBFTDI1_DIR/src/"
export LIBFTDI_LIBS="-L$LIBFTDI1_DIR/build/src/ -lftdi1 -lpthread"
export HIDAPI_CFLAGS="-I$HIDAPI_DIR/hidapi/"
if [[ ${ARCH} == *linux* ]]; then
export HIDAPI_LIBS="-L$HIDAPI_DIR/linux/.libs/ -L$HIDAPI_DIR/libusb/.libs/ -lhidapi-hidraw -lhidapi-libusb"
fi
if [[ ${ARCH} == *darwin* ]]; then
export HIDAPI_LIBS="-L$HIDAPI_DIR/mac/.libs/ -L$HIDAPI_DIR/libusb/.libs/ -lhidapi"
fi
if [[ ${ARCH} == *mingw* ]]; then
export HIDAPI_LIBS="-L$HIDAPI_DIR/windows/.libs/ -L$HIDAPI_DIR/libusb/.libs/ -lhidapi"
fi
if [[ ${ARCH} == *mingw* ]]; then
OPENOCD_COMPILE_SWITCHES="--enable-remote-bitbang --enable-stlink --enable-usb-blaster-2 --enable-ti-icdi --enable-jlink --enable-usbprog --enable-cmsis-dap"
else
OPENOCD_COMPILE_SWITCHES="--enable-remote-bitbang --enable-stlink --enable-usb-blaster-2 --enable-ti-icdi --enable-jlink --enable-usbprog --enable-cmsis-dap --enable-jtag_vpi --enable-ioutil"
fi
if [[ ${ARCH} == *linux* ]]; then
OPENOCD_COMPILE_SWITCHES="$OPENOCD_COMPILE_SWITCHES --enable-sysfsgpio"
fi
export CFLAGS="-DHAVE_LIBUSB_ERROR_NAME"
PKG_CONFIG_PATH=`pwd` ./configure $OPENOCD_COMPILE_SWITCHES --disable-werror --prefix=$PREFIX --host=${CROSS_COMPILE}
make clean
CFLAGS=-static make
make install