/
Makefile
222 lines (162 loc) · 6.8 KB
/
Makefile
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
215
216
217
218
219
220
221
222
#
# This Makefile attempts to build OpenConnect and its dependencies for Android
#
# It doesn't do a stunning job of tracking changes in the dependencies and
# automatically rebuilding them, but it's good enough for getting them built
# and installed into its own local sysroot.
#
# As long as you have the Android NDK toolchain on your path, you should then
# be able to edit fairly much anything in place and rebuild it locally.
#
# It should also be fairly simple to extend this to cross-compile for any target
NDK := /opt/android-sdk-linux_x86/android-ndk-r8d/
ARCH := arm
APIVER := 14
TRIPLET := arm-linux-androideabi
GCCVER := 4.6
NDK_SYSROOT := $(NDK)/platforms/android-$(APIVER)/arch-$(ARCH)
OC_SYSROOT := $(shell pwd)/sysroot
OPENSSL_VER := 1.0.1e
PATH := $(NDK)/toolchains/$(TRIPLET)-$(GCCVER)/prebuilt/linux-x86/bin:$(PATH)
PKG_CONFIG_LIBDIR=$(OC_SYSROOT)/lib/pkgconfig
export PATH PKG_CONFIG_LIBDIR
MAKEINSTALL=$(MAKE) INSTALL=$(shell pwd)/install_symlink.sh
CONFIGURE_ARGS := --host=$(TRIPLET) --prefix=$(OC_SYSROOT) \
--disable-shared --enable-static \
CFLAGS="--sysroot=$(NDK_SYSROOT) -I$(OC_SYSROOT)/include" \
LDFLAGS="-L$(OC_SYSROOT)/lib"
all: openconnect
#####################################################################
#
# Build libxml2 with minimal configuration for OpenConnect
#
LIBXML2_VER := 2.9.0
LIBXML2_DIR := libxml2-$(LIBXML2_VER)
libxml2-$(LIBXML2_VER).tar.gz:
curl ftp://xmlsoft.org/libxml2/libxml2-$(LIBXML2_VER).tar.gz -o $@.tmp && mv $@.tmp $@
$(LIBXML2_DIR)/configure: libxml2-$(LIBXML2_VER).tar.gz
tar xfz $<
touch $@
$(LIBXML2_DIR)/Makefile: $(LIBXML2_DIR)/configure
cd libxml2-$(LIBXML2_VER) && ./configure $(CONFIGURE_ARGS) \
--without-c14n -without-catalog --without-debug --without-docbook \
--without-fexceptions --without-ftp --without-history \
--without-html --without-http --without-iconv --without-iconv \
--without-iso8859x --without-legacy --without-pattern \
--without-push --without-regexps --without-run-debug \
--without-sax1 --without-schemas --without-schematron \
--without-threads --without-valid --without-xinclude \
--without-xpath --without-xptr --without-zlib --without-lzma \
--without-coverage --without-python
$(LIBXML2_DIR)/libxml2.la: $(LIBXML2_DIR)/Makefile
$(MAKE) -C $(LIBXML2_DIR) libxml2.la
$(LIBXML2_DIR)/libxml-2.0.pc: $(LIBXML2_DIR)/Makefile
$(MAKE) -C $(LIBXML2_DIR) libxml-2.0.pc
$(OC_SYSROOT)/lib/libxml2.la: $(LIBXML2_DIR)/libxml2.la
$(MAKEINSTALL) -C $(LIBXML2_DIR) install-libLTLIBRARIES
$(OC_SYSROOT)/lib/pkgconfig/libxml-2.0.pc: $(LIBXML2_DIR)/libxml-2.0.pc
$(MAKEINSTALL) -C $(LIBXML2_DIR) install-data
LIBXML_DEPS := $(OC_SYSROOT)/lib/libxml2.la $(OC_SYSROOT)/lib/pkgconfig/libxml-2.0.pc
libxml: $(LIBXML_DEPS)
#####################################################################
#
# Build OpenSSL for Android
#
OPENSSL_VER := 1.0.1e
OPENSSL_DIR := openssl-$(OPENSSL_VER)
openssl-$(OPENSSL_VER).tar.gz:
curl http://www.openssl.org/source/openssl-$(OPENSSL_VER).tar.gz -o $@.tmp && mv $@.tmp $@
$(OPENSSL_DIR)/Configure: openssl-$(OPENSSL_VER).tar.gz
tar xfz $<
cd openssl-$(OPENSSL_VER) && patch -p1 < ../0001-Check-DTLS_BAD_VER-for-version-number.patch
touch $(OPENSSL_DIR)/Configure # Make sure it's newer than Makefile and tarball
$(OPENSSL_DIR)/Makefile: $(OPENSSL_DIR)/Configure
cd $(OPENSSL_DIR) && perl Configure --prefix=$(OC_SYSROOT) \
--cross-compile-prefix=$(TRIPLET)- no-shared \
android-armv7:"gcc --sysroot=$(NDK_SYSROOT)"
$(OPENSSL_DIR)/libssl.a: $(OPENSSL_DIR)/Makefile
$(MAKE) -C $(OPENSSL_DIR)
$(OC_SYSROOT)/lib/libssl.a: $(OPENSSL_DIR)/libssl.a
# Do this manually instead of using 'make install' since we want symlinks
mkdir -p $(OC_SYSROOT)/include/openssl
ln -sf $(shell pwd)/$(OPENSSL_DIR)/include/openssl/*.h $(OC_SYSROOT)/include/openssl
mkdir -p $(OC_SYSROOT)/lib/pkgconfig
ln -sf $(shell pwd)/$(OPENSSL_DIR)/*.pc $(OC_SYSROOT)/lib/pkgconfig
ln -sf $(shell pwd)/$(OPENSSL_DIR)/*.a $(OC_SYSROOT)/lib
OPENSSL_DEPS := $(OC_SYSROOT)/lib/libssl.a
openssl: $(OPENSSL_DEPS)
#####################################################################
#
# Build GNU MP
#
GMP_VER := 5.1.1
GMP_DIR := gmp-$(GMP_VER)
gmp-$(GMP_VER).tar.bz2:
curl ftp://ftp.gmplib.org/pub/gmp/gmp-$(GMP_VER).tar.bz2 -o $@.tmp && mv $@.tmp $@
$(GMP_DIR)/configure: gmp-$(GMP_VER).tar.bz2
tar xfj $<
touch $@
$(GMP_DIR)/Makefile: $(GMP_DIR)/configure
cd gmp-$(GMP_VER) && ./configure $(CONFIGURE_ARGS)
$(GMP_DIR)/libgmp.la: $(GMP_DIR)/Makefile
$(MAKE) -C $(GMP_DIR)
$(OC_SYSROOT)/lib/libgmp.la: $(GMP_DIR)/libgmp.la
$(MAKEINSTALL) -C $(GMP_DIR) install
GMP_DEPS := $(OC_SYSROOT)/lib/libgmp.la
gmp: $(GMP_DEPS)
#####################################################################
#
# Build nettle
#
NETTLE_VER := 2.6
NETTLE_DIR := nettle-$(NETTLE_VER)
nettle-$(NETTLE_VER).tar.gz:
curl http://www.lysator.liu.se/~nisse/archive/nettle-$(NETTLE_VER).tar.gz -o $@.tmp && mv $@.tmp $@
$(NETTLE_DIR)/configure: nettle-$(NETTLE_VER).tar.gz
tar xfz $<
touch $@
$(NETTLE_DIR)/Makefile: $(NETTLE_DIR)/configure $(GMP_DEPS)
cd nettle-$(NETTLE_VER) && ./configure $(CONFIGURE_ARGS)
$(NETTLE_DIR)/libnettle.a: $(NETTLE_DIR)/Makefile
$(MAKE) -C $(NETTLE_DIR) SUBDIRS=
$(OC_SYSROOT)/lib/libnettle.a: $(NETTLE_DIR)/libnettle.a
$(MAKEINSTALL) -C $(NETTLE_DIR) SUBDIRS= install
NETTLE_DEPS := $(OC_SYSROOT)/lib/libnettle.a
nettle: $(NETTLE_DEPS)
#####################################################################
#
# Build GnuTLS
#
#GNUTLS_VER := 3.1.9
GNUTLS_DIR := gnutls
gnutls-$(GNUTLS_VER).tar.xz:
curl ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1/$@ -o $@.tmp && mv $@.tmp $@
#$(GNUTLS_DIR)/configure: gnutls-$(GNUTLS_VER).tar.xz
# xz -d < $< | tar xf -
# touch $@
$(GNUTLS_DIR)/configure.ac:
git clone --reference /home/dwmw2/git/gnutls git://gitorious.org/gnutls/gnutls.git
$(GNUTLS_DIR)/configure: $(GNUTLS_DIR)/configure.ac
rm tests/suite/mini-eagain2.c
touch Changelog
cd $(GNUTLS_DIR) && autoreconf -fvi
$(GNUTLS_DIR)/Makefile: $(GNUTLS_DIR)/configure $(NETTLE_DEPS)
cd $(GNUTLS_DIR) && ./configure $(CONFIGURE_ARGS) --disable-threads \
--disable-doc --disable-openssl-compatibility --disable-cxx
$(GNUTLS_DIR)/lib/libgnutls.la: $(GNUTLS_DIR)/Makefile
$(MAKE) -C $(GNUTLS_DIR)
$(OC_SYSROOT)/lib/libgnutls.la: $(GNUTLS_DIR)/lib/libgnutls.la
$(MAKEINSTALL) -C $(GNUTLS_DIR) install
GNUTLS_DEPS := $(OC_SYSROOT)/lib/libgnutls.la
gnutls: $(GNUTLS_DEPS)
#####################################################################
#
# Build OpenConnect for Android
#
ocbuild/Makefile: $(GNUTLS_DEPS) $(LIBXML_DEPS) ../configure
mkdir -p ocbuild
cd ocbuild && ../../configure $(CONFIGURE_ARGS) \
CFLAGS="--sysroot=$(NDK_SYSROOT) -DNO_BROKEN_DTLS_CHECK -DANDROID" \
GNUTLS_LIBS="$(shell PKG_CONFIG_LIBDIR=$(OC_SYSROOT)/lib/pkgconfig pkg-config --static --libs gnutls)"
openconnect: ocbuild/Makefile
make -C ocbuild