forked from FPGAwars/libusb-cross-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-windows_x86_64.sh
97 lines (70 loc) · 2.04 KB
/
build-windows_x86_64.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
##############################################
# libusb builder for Windows 64 bits #
##############################################
BUILD=x86-unknown-linux-gnu
HOST=x86_64-w64-mingw32
TARGET=x86_64-w64-mingw32
NAME=libusb
ARCH=windows_x86_64
PREFIX=$HOME/.$ARCH
VERSION=4
PACKNAME=$NAME-$ARCH-$VERSION
BUILD_DIR=build_$ARCH
PACK_DIR=packages
TARBALL=$PWD/$BUILD_DIR/$PACKNAME.tar.gz
ZIPBALL=$PWD/$BUILD_DIR/$PACKNAME.zip
ZIPEXAMPLE=listdevs-example-$ARCH-$VERSION.zip
GITREPO=https://github.com/libusb/libusb.git
# Store current dir
WORK=$PWD
# -- TARGET: CLEAN. Remove the build dir and the generated packages
# -- then exit
if [ "$1" == "clean" ]; then
echo "-----> CLEAN"
# Remove the build directory
rm -f -r $BUILD_DIR
# Removed the packages generated
rm -f $PWD/$PACK_DIR/$NAME-$ARCH-*.tar.gz
rm -f $PWD/$PACK_DIR/$NAME-$ARCH-*.zip
rm -f $PWD/$PACK_DIR/$EXAMPLE-$ARCH-*.zip
#-- Remove the installed libusb
cd $PREFIX
rm -f $PREFIX/bin/libusb-1.0.dll
rm -f -r $PREFIX/include/libusb-1.0
rm -f $PREFIX/lib/libusb-1*
rm -f $PREFIX/lib/pkgconfig/libusb-1*
exit
fi
# Install dependencies
echo "Instalando DEPENDENCIAS:"
sudo apt-get install mingw-w64 libtool autoconf
# Clone the libusb repo
git -C $NAME pull || git clone $GITREPO
# Create the packages directory
mkdir -p $PACK_DIR
# Enter into the build directory
mkdir -p $BUILD_DIR ; cd $BUILD_DIR
# Copy the upstream libusb into the build dir
cp -r $WORK/$NAME .
# Prepare for building
cd $NAME
./autogen.sh
# Configure cross compilation
./configure --build=$BUILD --host=$HOST --target=$TARGET --prefix=$PREFIX
# let's cross compile!
make
# Install libusb
make install
# Cross-compile one example
cd examples
$HOST-gcc -o listdevs.exe listdevs.c -I $PREFIX/include/libusb-1.0 -L $PREFIX/lib -static -lusb-1.0
# Zip the .exe file and move it to the main directory
zip $ZIPEXAMPLE listdevs.exe
mv $ZIPEXAMPLE $WORK/$PACK_DIR
# Create the tarball
cd $PREFIX
tar vzcf $TARBALL *
mv $TARBALL $WORK/$PACK_DIR
# Create the zipball
zip -r $ZIPBALL *
mv $ZIPBALL $WORK/$PACK_DIR