1# Google Android makefile for curl and libcurl
2#
3# Place the curl source (including this makefile) into external/curl/ in the
4# Android source tree.  Then build them with 'make curl' or just 'make libcurl'
5# from the Android root. Tested with Android versions 1.5, 2.1-2.3
6#
7# Note: you must first create a curl_config.h file by running configure in the
8# Android environment. The only way I've found to do this is tricky. Perform a
9# normal Android build with libcurl in the source tree, providing the target
10# "showcommands" to make. The build will eventually fail (because curl_config.h
11# doesn't exist yet), but the compiler commands used to build curl will be
12# shown. Now, from the external/curl/ directory, run curl's normal configure
13# command with flags that match what Android itself uses. This will mean
14# putting the compiler directory into the PATH, putting the -I, -isystem and
15# -D options into CPPFLAGS, putting the -W, -m, -f, -O and -nostdlib options
16# into CFLAGS, and putting the -Wl, -L and -l options into LIBS, along with the
17# path to the files libgcc.a, crtbegin_dynamic.o, and ccrtend_android.o.
18# Remember that the paths must be absolute since you will not be running
19# configure from the same directory as the Android make.  The normal
20# cross-compiler options must also be set. Note that the -c, -o, -MD and
21# similar flags must not be set.
22#
23# To see all the LIBS options, you'll need to do the "showcommands" trick on an
24# executable that's already buildable and watch what flags Android uses to link
25# it (dhcpcd is a good choice to watch). You'll also want to add -L options to
26# LIBS that point to the out/.../obj/lib/ and out/.../obj/system/lib/
27# directories so that additional libraries can be found and used by curl.
28#
29# The end result will be a configure command that looks something like this
30# (the environment variable A is set to the Android root path which makes the
31# command shorter):
32#
33#  A=`realpath ../..` && \
34#  PATH="$A/prebuilt/linux-x86/toolchain/arm-eabi-X/bin:$PATH" \
35#  ./configure --host=arm-linux CC=arm-eabi-gcc \
36#  CPPFLAGS="-I $A/system/core/include ..." \
37#  CFLAGS="-nostdlib -fno-exceptions -Wno-multichar ..." \
38#  LIBS="$A/prebuilt/linux-x86/toolchain/arm-eabi-X/lib/gcc/arm-eabi/X\
39#  /interwork/libgcc.a ..."
40#
41# Finally, copy the file COPYING to NOTICE so that the curl license gets put
42# into the right place (but see the note about this below).
43#
44# Dan Fandrich
45# November 2011
46
47LOCAL_PATH:= $(call my-dir)
48
49common_CFLAGS := -Wpointer-arith -Wwrite-strings -Wunused -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long -Wfloat-equal -Wno-multichar -Wsign-compare -Wno-format-nonliteral -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wno-system-headers -DHAVE_CONFIG_H
50
51#########################
52# Build the libcurl library
53
54include $(CLEAR_VARS)
55include $(LOCAL_PATH)/lib/Makefile.inc
56CURL_HEADERS := \
57	curlbuild.h \
58	curl.h \
59	curlrules.h \
60	curlver.h \
61	easy.h \
62	mprintf.h \
63	multi.h \
64	stdcheaders.h \
65	typecheck-gcc.h
66
67LOCAL_SRC_FILES := $(addprefix lib/,$(CSOURCES))
68LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/
69LOCAL_CFLAGS += $(common_CFLAGS)
70
71LOCAL_COPY_HEADERS_TO := libcurl/curl
72LOCAL_COPY_HEADERS := $(addprefix include/curl/,$(CURL_HEADERS))
73
74LOCAL_MODULE:= libcurl
75LOCAL_MODULE_TAGS := optional
76
77# Copy the licence to a place where Android will find it.
78# Actually, this doesn't quite work because the build system searches
79# for NOTICE files before it gets to this point, so it will only be seen
80# on subsequent builds.
81ALL_PREBUILT += $(LOCAL_PATH)/NOTICE
82$(LOCAL_PATH)/NOTICE: $(LOCAL_PATH)/COPYING | $(ACP)
83	$(copy-file-to-target)
84
85include $(BUILD_STATIC_LIBRARY)
86
87
88#########################
89# Build the curl binary
90
91include $(CLEAR_VARS)
92include $(LOCAL_PATH)/src/Makefile.inc
93LOCAL_SRC_FILES := $(addprefix src/,$(CURL_CFILES))
94
95LOCAL_MODULE := curl
96LOCAL_MODULE_TAGS := optional
97LOCAL_STATIC_LIBRARIES := libcurl
98LOCAL_SYSTEM_SHARED_LIBRARIES := libc
99
100LOCAL_C_INCLUDES += $(LOCAL_PATH)/include $(LOCAL_PATH)/lib
101
102# This may also need to include $(CURLX_ONES) in order to correctly link
103# if libcurl is changed to be built as a dynamic library
104LOCAL_CFLAGS += $(common_CFLAGS)
105
106include $(BUILD_EXECUTABLE)
107
108