forked from Obijuan/tools-usb-ftdi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-linux_armv7l.sh
198 lines (150 loc) · 5.28 KB
/
build-linux_armv7l.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
#######################################################################
# libusb and libftdi builder for Ubuntu phone (armhf) and raspberry
# (C) BQ. March-2016
# Written by Juan Gonzalez (Obijuan)
#######################################################################
VERSION=1
UPSTREAM=upstream
PACK_DIR=packages
ARCH=linux_armv7l
BUILD_DIR=build_$ARCH
PACKNAME=tools-usb-ftdi-$ARCH-$VERSION
TARBALL=$PACKNAME.tar.bz2
BUILD=x86-unknown-linux-gnu
HOST=arm-linux-gnueabihf
TARGET=arm-linux-gnueabihf
BUILD_DATA=build-data
# -- lIBUSB
LIBUSB_GIT_REPO=https://github.com/libusb/libusb/releases/download/v1.0.20
LIBUSB_FILENAME=libusb-1.0.20
LIBUSB_FILENAME_TAR=$LIBUSB_FILENAME.tar.bz2
# -- LIBFTDI
LIBFTDI_REPO=https://www.intra2net.com/en/developer/libftdi/download
LIBFTDI_FILENAME=libftdi1-1.2
LIBFTDI_FILENAME_TAR=$LIBFTDI_FILENAME.tar.bz2
# -- DEBUG
COMPILE_LIBUSB=1
COMPILE_LISTDEVS=1
COMPILE_LIBFTDI=1
COMPILE_FIND_ALL=1
# --------------------- LIBUSB ----------------------------------------
# Store current dir
WORK=$PWD
PREFIX=$WORK/$BUILD_DIR
# -- TARGET: CLEAN. Remove the build dir and the generated packages
# -- then exit
if [ "$1" == "clean" ]; then
echo "-----> CLEAN"
# -- Remove the build dir
rm -rf $WORK/$BUILD_DIR
# -- Remove the packages dir
rm -rf $WORK/$PACK_DIR
exit
fi
# Install dependencies
echo "Instalando DEPENDENCIAS:"
sudo apt-get install libtool autoconf gcc-arm-linux-gnueabihf \
g++-arm-linux-gnueabihf libc6-dev-armhf-cross
# Create the upstream folder
mkdir -p $UPSTREAM
# Create the packages directory
mkdir -p $PACK_DIR
mkdir -p $PACK_DIR/$BUILD_DIR
mkdir -p $PACK_DIR/$BUILD_DIR/bin
# Create the build dir
mkdir -p $BUILD_DIR
#-- Download the src tarball, if it has not been done yet
cd $UPSTREAM
test -e $LIBUSB_FILENAME_TAR ||
(echo ' ' && \
echo '--> DOWNLOADING LIBUSB source package' && \
wget $LIBUSB_GIT_REPO/$LIBUSB_FILENAME_TAR)
#-- Extract the src files, if it has not been done yet
test -e $LIBUSB_FILENAME ||
(echo ' ' && \
echo '--> UNCOMPRESSING LIBUSB package' && \
tar vjxf $LIBUSB_FILENAME_TAR)
#-- Copy the upstream libusb into the build dir
cd $WORK
test -d $BUILD_DIR/$LIBUSB_FILENAME ||
(echo ' ' && \
echo '--> COPYING LIBUSB upstream into build_dir' && \
cp -r $UPSTREAM/$LIBUSB_FILENAME $BUILD_DIR)
#-- Apply the patch to the libusb
cp $WORK/$BUILD_DATA/configure.ac.libusb $BUILD_DIR/$LIBUSB_FILENAME/configure.ac
# -- Create the lib and include files
cd $BUILD_DIR
mkdir -p lib
mkdir -p include
# ---------------------------- Building the LIBUSB library
if [ $COMPILE_LIBUSB == "1" ]; then
cd $LIBUSB_FILENAME
#-- Generate the new configure from configure.ac patched
autoconf
# Prepare for building
# No udev used
./configure --prefix=$PREFIX --build=$BUILD --host=$HOST \
--target=$TARGET
# Compile!
make
# -- Copy the dev files into $BUILD_DIR/include $BUILD_DIR/lbs
make install
if [ $COMPILE_LISTDEVS == "1" ]; then
#-- Compile the listdevs-example
cd examples
$HOST-gcc -o listdevs listdevs.c -I $WORK/$BUILD_DIR/include/libusb-1.0/ \
-L $WORK/$BUILD_DIR/lib -L /usr/arm-linux-gnueabihf/lib/ \
-static -lusb-1.0 -lpthread
# -- Copy the executable into the packages/bin dir
cp listdevs $WORK/$PACK_DIR/$BUILD_DIR/bin
fi
fi
# ------------------------ LIBFTDI --------------------------------------
#-- Download the src tarball, if it has not been done yet
cd $WORK/$UPSTREAM
test -e $LIBFTDI_FILENAME_TAR ||
(echo ' ' && \
echo '--> DOWNLOADING LIBFTDI source package' && \
wget $LIBFTDI_REPO/$LIBFTDI_FILENAME_TAR)
#-- Extract the src files, if it has not been done yet
test -e $LIBFTDI_FILENAME ||
(echo ' ' && \
echo '--> UNCOMPRESSING LIBFTDI package' && \
tar vjxf $LIBFTDI_FILENAME_TAR)
#-- Copy the upstream libusb into the build dir
cd $WORK
test -d $BUILD_DIR/$LIBFTDI_FILENAME ||
(echo ' ' && \
echo '--> COPYING LIBFTDI upstream into build_dir' && \
cp -r $UPSTREAM/$LIBFTDI_FILENAME $BUILD_DIR)
cp $WORK/$BUILD_DATA/$ARCH/toolchain-armhf.cmake.libftdi \
$WORK/$BUILD_DIR/$LIBFTDI_FILENAME/toolchain-armhf.cmake
# ---------------------------- Building the LIBFTDI library
if [ $COMPILE_LIBFTDI == "1" ]; then
cd $BUILD_DIR/$LIBFTDI_FILENAME
mkdir -p build
cd build
# -- Configure the compilation
cmake -DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_TOOLCHAIN_FILE=toolchain-armhf.cmake \
-DLIBUSB_LIBRARIES=$WORK/$BUILD_DIR/lib/libusb-1.0.so \
-DLIBFTDI_LIBRARY_DIRS=$WORK/$BUILD_DIR/lib \
-DLIBUSB_INCLUDE_DIR=$WORK/$BUILD_DIR/include/libusb-1.0 ..
# -- Let's compile
make
# -- Installation
make install
if [ $COMPILE_FIND_ALL == "1" ]; then
# -- Compile the find_all example
cd ../examples
$HOST-gcc -o find_all find_all.c -I $PREFIX/include/libftdi1/ \
-L $PREFIX/lib -L /usr/arm-linux-gnueabihf/lib/ \
-static -lftdi1 -lusb-1.0 -lpthread
# -- Copy the executable into the packages/bin dir
cp find_all $WORK/$PACK_DIR/$BUILD_DIR/bin
fi
fi
# ---------------------------------- Create the package
cd $WORK/$PACK_DIR/$BUILD_DIR
tar vjcf $TARBALL bin
mv $TARBALL ..