-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathbuild-for-windows.sh
executable file
·109 lines (98 loc) · 2.46 KB
/
build-for-windows.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
#!/bin/sh
PWD=$(pwd)
SRC_DIR=$PWD/src
BUILD_DIR=$PWD/build
DOWNLOAD_DIR=$PWD/dl
BINDIR_X86=$BUILD_DIR/x86
BINDIR_X64=$BUILD_DIR/x64
LIBS_DIR=$BUILD_DIR/libs
LIBSDIR_X86=$LIBS_DIR/x86
LIBSDIR_X64=$LIBS_DIR/x64
LIBUSB_VER="1.0.27"
LIBUSB_URL="https://github.com/libusb/libusb/releases/download/v${LIBUSB_VER}/libusb-${LIBUSB_VER}.tar.bz2"
LIBUSB_DIR=""
check_mingw(){
if [ ! -x "$(command -v i686-w64-mingw32-gcc)" ] || [ ! -x "$(command -v x86_64-w64-mingw32-gcc)" ]; then
echo 'Error: mingw-w64 is not installed.' >&2
exit 1
fi
}
prepare_dirs(){
if [ ! -d $BUILD_DIR ]; then
mkdir -p $BUILD_DIR || exit 1
fi
if [ ! -d $DOWNLOAD_DIR ]; then
mkdir -p $DOWNLOAD_DIR || exit 1
fi
if [ ! -d $BINDIR_X86 ]; then
mkdir -p $BINDIR_X86 || exit 1
fi
if [ ! -d $BINDIR_X64 ]; then
mkdir -p $BINDIR_X64 || exit 1
fi
if [ ! -d $LIBS_DIR ]; then
mkdir -p $LIBS_DIR || exit 1
fi
if [ ! -d $LIBSDIR_X86 ]; then
mkdir -p $LIBSDIR_X86 || exit 1
fi
if [ ! -d $LIBSDIR_X64 ]; then
mkdir -p $LIBSDIR_X64 || exit 1
fi
return 0
}
download_files(){
if [ -d $DOWNLOAD_DIR ] && [ ! -d $DOWNLOAD_DIR/libusb-$LIBUSB_VER ]; then
cd $DOWNLOAD_DIR; \
wget $LIBUSB_URL; \
tar xf libusb-$LIBUSB_VER.tar.bz2
fi
LIBUSB_DIR=$(cd $DOWNLOAD_DIR/libusb-$LIBUSB_VER && pwd)
return 0
}
build_depends_x86(){
if [ -d $LIBUSB_DIR ]; then
cd $LIBUSB_DIR; \
./configure --host=i686-w64-mingw32 --prefix=$LIBSDIR_X86; \
make clean; \
make; \
make install
fi
return 0
}
build_depends_x64(){
if [ -d $LIBUSB_DIR ]; then
cd $LIBUSB_DIR; \
./configure --host=x86_64-w64-mingw32 --prefix=$LIBSDIR_X64; \
make clean; \
make; \
make install
fi
return 0
}
build_target_x86(){
make -C $SRC_DIR CC=i686-w64-mingw32-gcc STRIP=i686-w64-mingw32-strip WINDRES=i686-w64-mingw32-windres CONFIG_STATIC=yes TARGET_OS=MinGW LIBS_BASE=$LIBSDIR_X86 strip && mv $SRC_DIR/*.exe $BINDIR_X86
make -C $SRC_DIR TARGET_OS=MinGW clean
return 0
}
build_target_x64(){
make -C $SRC_DIR CC=x86_64-w64-mingw32-gcc STRIP=x86_64-w64-mingw32-strip WINDRES=x86_64-w64-mingw32-windres CONFIG_STATIC=yes TARGET_OS=MinGW LIBS_BASE=$LIBSDIR_X64 strip && mv $SRC_DIR/*.exe $BINDIR_X64
make -C $SRC_DIR TARGET_OS=MinGW clean
return 0
}
#clean_all(){
# if [ -d $BUILD_DIR ]; then
# rm -rf $BUILD_DIR || exit 1
# elif [ -d $DOWNLOAD_DIR ]; then
# rm -rf $DOWNLOAD_DIR || exit 1
# fi
# return 0
#}
check_mingw
prepare_dirs
download_files
build_depends_x86
build_depends_x64
build_target_x86
build_target_x64
#clean_all