-
Notifications
You must be signed in to change notification settings - Fork 17
/
cross-compile
executable file
·165 lines (127 loc) · 3.56 KB
/
cross-compile
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
#!/bin/bash -e
#
# StegoTorus Windows cross-compile script
#
# Copyright (C)2013 Farsight Security, Inc.
# written by Jeroen Massar <[email protected]>
#
# Make sure that CFLAGS/LDFLAGS etc is not set...
CXLog() {
echo "======================================"
echo "======================================"
echo "=== $@"
echo "======================================"
echo "======================================"
}
CXLog "Setting up cross-compile environment"
CXHOME=$(pwd)
MPFX=i586-mingw32msvc
AR=${MPFX}-ar
CC=${MPFX}-gcc
RANLIB=${MPFX}-ranlib
OBJDUMP=${MPFX}-objdump
PREFIX=~/.cross/mingw
SRC=/${PREFIX}/src/
CROSSCFG="--build=amd64-pc-linux-gnu --host=${MPFX}"
LINKCFG="--enable-static --disable-shared"
PKGCONFIG="${PREFIX}/bin/${MPFX}-pkg-config"
DEBSRC="${PREFIX}/deb-src"
CXLog "Our MingW Prefix = ${PREFIX}"
if [ "$(which ${CC})X" = "X" ];
then
echo >&2 "Error: Please install mingw: apt-get install mingw32"
exit 1
fi
mkdir -p ${PREFIX} 2>/dev/null
if [ ! -d ${PREFIX} ];
then
echo >&2 "No ${PREFIX}, got sufficient permissions?"
echo >&2 "Please create ${PREFIX} as root and chown it to a normal user"
exit 1
fi
CXLog "Preparing environment"
mkdir -p ${PREFIX}/bin ${PREFIX}/lib/pkgconfig
cat >${PKGCONFIG} <<HERE
#!/bin/sh
PREFIX=${PREFIX}
export PKG_CONFIG_LIBDIR=\${PREFIX}/lib/pkgconfig
exec pkg-config "\$@"
HERE
chmod +x ${PKGCONFIG}
##############################################################################
cxenv() {
CC="${CC} -I/${PREFIX}/include -L/${PREFIX}/lib" AR=${AR} RANLIB=${RANLIB} PKG_CONFIG=${PKGCONFIG} $@
}
##############################################################################
cxbuild() {
NAME=$1
shift
OPTS=$@
CONF="configure ${CROSSCFG} ${LINKCFG}"
# zlib's configure does not understand --build and --host
if [ "${SOURCE}" = "zlib" ];
then
CONF="configure"
fi
# OpenSSL has it's own Configure
if [ "${SOURCE}" = "openssl" ];
then
# Undo Debian patches and touch Makefile otherwise it is too old
quilt pop -a
touch Makefile
CONF="Configure"
fi
CXLog "Configuring and making ${NAME}..."
cxenv ./${CONF} --prefix=${PREFIX} ${OPTS} && cxenv make && cxenv make install
CXLog "done (${NAME})"
}
##############################################################################
cxlib() {
CXLIB=$1
SOURCE=$2
OPTS=$3
if [ -f ${PREFIX}/lib/${CXLIB}.a ];
then
CXLog "Avoiding rebuild of ${CXLIB}, already exists"
else
CXLog "Retrieving ${CXLIB} (${SOURCE})"
mkdir -p ${DEBSRC}/${CXLIB}
cd ${DEBSRC}/${CXLIB}
rm -rf ${SOURCE}-*
apt-get source ${SOURCE}
cd ${SOURCE}-*
cxbuild ${CXLIB} ${OPTS}
fi
}
##############################################################################
cxlib libz zlib "--static"
cxlib libevent libevent "${CROSSCFG} ${LINKCFG}"
cxlib libcrypto openssl "--openssldir=${PREFIX} no-shared no-idea no-mdc2 no-rc5 zlib enable-tlsext no-ssl2 mingw"
cxlib libjansson jansson "${CROSSCFG} ${LINKCFG}"
#JEL:
# jel needs some tlc before it will cross-compile
#cd ${CXHOME}/../jel/
#rm -rf build 2>/dev/null
#mkdir build &&
#cd build &&
#cxenv cmake .. &&
#cxenv make
#cxenv make install
##############################################################################
cd ${CXHOME}
# Do we have a configure script?
if [ ! -f configure ];
then
# Clean, thus generate configure etc
autoreconf -i
fi
# Do we have a Makefile?
if [ ! -f Makefile ];
then
automake
else
# Not clean, thus clean it
make clean
fi
cxbuild stegotorus
exit 0