aboutsummaryrefslogtreecommitdiffstats
path: root/extras/cross-compile-libs
blob: 984c5979d5edcc625dadb8eae1624d89496949d4 (plain) (blame)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
#
# cross-compile win32 libraries for syslog-win32
# on exit libraries are in cross-libs directory
#
# required environment variables: DISTFILES
# honoured environment variables: CFLAGS, HOST
#

#
# define distfiles
#
libiconv=libiconv-1.9.2.tar.gz
gettext=gettext-0.14.1.tar.gz
zlib=zlib-1.2.2.tar.bz2
regex=regex-0.12.tar.gz
glib=glib-2.6.3.tar.bz2

function distfiles()
{
	echo $libiconv
	echo $gettext
	echo $zlib
	echo $regex
	echo $glib
}

#
# check DISTFILES and distfiles
#
if [ -z "$DISTFILES" ] ; then
	echo "You should specify location of source tarballs with the help of DISTFILES environment variable"
	exit 1
fi

for file in `distfiles` ; do
	if [ -f "$DISTFILES"/$file ] ; then continue ; fi
	echo $file not found
	exit 1
done

#
# set environment variables if not set yet
#
if [ -z "$CFLAGS" ] ; then
	export CFLAGS="-Os -g"
fi

if [ -z "$HOST" ] ; then
	export HOST=i686-pc-mingw32
fi

#
# a wrapper for subsequent commands
#
function run()
{
	echo "$@"
	"$@" || exit 1
}

#
# unpack routine
#
function unpack_tarball()
{
	if [[ zip == ${1:(-3)} ]] ; then
		run unzip "$1"
	else
		if [[ bz2 == ${1:(-3)} ]] ; then arch=j
		elif [[ gz == ${1:(-2)} ]] ; then arch=z
		elif [[ tar == ${1:(-3)} ]] ; then arch=
		else
			echo "Unknown distfile type"
			exit 1
		fi
		run tar -x${arch}f "$1"
	fi
}

#
# create build directories
#
export PREFIX=`pwd`/cross-libs
run mkdir -p cross-libs
run mkdir -p cross-build
run pushd cross-build

#
# build libiconv
#
unpack_tarball "$DISTFILES"/$libiconv
run pushd libiconv*
run ./configure --prefix="$PREFIX" --host=$HOST --disable-nls
run make
run make install
run popd
run rm -Rf libiconv*

#
# build gettext
#
unpack_tarball "$DISTFILES"/$gettext
run pushd gettext*/gettext-runtime
CPPFLAGS=-I"$PREFIX"/include LDFLAGS=-L"$PREFIX"/lib \
run ./configure --prefix="$PREFIX" --host=$HOST --enable-relocatable --with-libiconv-prefix="$PREFIX"
run make
run make install
run popd
run rm -Rf gettext*

#
# build zlib
# TO DO: use original makefile; dllname must be like in official windoze distro
#
unpack_tarball "$DISTFILES"/$zlib
run pushd zlib*
cat >configure.ac <<EOF
AC_INIT(zlib,1.2.2)
AM_INIT_AUTOMAKE
AC_CANONICAL_HOST
AC_PROG_CC
AC_PROG_LIBTOOL
AC_OUTPUT(Makefile)
EOF
cat >Makefile.am <<EOF
lib_LTLIBRARIES = libz.la
libz_la_SOURCES = adler32.c compress.c crc32.c deflate.c gzio.c \
                  infback.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c
include_HEADERS = zlib.h
libz_la_LDFLAGS = -no-undefined -release 1
EOF
run aclocal
run libtoolize
run autoconf
run automake --foreign --add-missing
run ./configure --prefix="$PREFIX" --host=$HOST
run make
run make install
run popd
run rm -Rf zlib*

#
# build regex
# NOT NEEDED
#
unpack_tarball "$DISTFILES"/$regex
run pushd regex*
cat >configure.ac <<EOF
AC_INIT(regex,0.12)
AM_INIT_AUTOMAKE
AC_CANONICAL_HOST
AC_PROG_CC
AC_PROG_LIBTOOL
AC_OUTPUT(Makefile)
EOF
cat >Makefile.am <<EOF
lib_LTLIBRARIES = libregex.la
libregex_la_SOURCES = regex.c
include_HEADERS = regex.h
libregex_la_LDFLAGS = -no-undefined
EOF
run rm -f configure.in
run aclocal
run libtoolize
run autoconf
run automake --foreign --add-missing
run ./configure --prefix="$PREFIX" --host=$HOST
run make
run make install
run popd
run rm -Rf regex*

#
# build glib
#
unpack_tarball "$DISTFILES"/$glib
run pushd glib*
#
# according to glib documentation, win32.cache is needed to skip tests that cannot be run in cross-compile environment
#
cat >win32.cache <<EOF
glib_cv_long_long_format=I64
glib_cv_stack_grows=no
EOF
run chmod a-w win32.cache
#
# remove policy that does not allow us to build static library for win32
#
run patch -Np1 -i ../../glib-static-win32.patch
run aclocal --force
run libtoolize --force
run autoconf --force
run automake --foreign --add-missing --force
OBJDUMP=$HOST-objdump CFLAGS='-Os -g' \
CPPFLAGS=-I"$PREFIX"/include \
LDFLAGS=-L"$PREFIX"/lib \
run ./configure --prefix="$PREFIX" --host=$HOST --with-libintl --disable-gtk-doc --cache-file=win32.cache --enable-static
WINDRES=$HOST-windres run make
run make install
run popd
run rm -Rf glib*
#
# explanations:
# - setting OBJDUMP is required for libtool's file format checking
# - WINDRES is required for resource compiling
#

#
# strip libraries and cleanup
#
run popd
$HOST-strip -s cross-libs/bin/*
run rmdir cross-build