1# -*- mode: makefile -*-
2# Copyright (C) 2013 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16#
17# Definitions for building the Conscrypt Java library, native code,
18# and associated tests.
19#
20
21#
22# Common definitions for host and target.
23#
24
25# Conscrypt is divided into modules.
26#
27# The structure is:
28#
29#   src/
30#       main/               # To be shipped on every device.
31#            java/          # Java source for library code.
32#            native/        # C++ source for library code.
33#            resources/     # Support files.
34#       test/               # Built only on demand, for testing.
35#            java/          # Java source for tests.
36#            native/        # C++ source for tests (rare).
37#            resources/     # Support files.
38#
39# All subdirectories are optional (hence the "2> /dev/null"s below).
40
41LOCAL_PATH := $(call my-dir)
42
43local_javac_flags:=-Xmaxwarns 9999999
44#local_javac_flags+=-Xlint:all -Xlint:-serial,-deprecation,-unchecked
45
46core_cflags := -Wall -Wextra -Werror -Wunused
47core_cppflags := -std=gnu++11 -Wall -Wextra -Werror -Wunused
48
49# libnativehelper's UniquePtr is deprecated but changing to std::unique_ptr has
50# been rejected here in the past:
51# https://android-review.googlesource.com/#/c/113096/
52core_cppflags += -Wno-error=deprecated-declarations
53
54#
55# Build for the target (device).
56#
57
58include $(CLEAR_VARS)
59LOCAL_CPP_EXTENSION := cc
60LOCAL_SRC_FILES := src/gen/native/generate_constants.cc
61LOCAL_MODULE := conscrypt_generate_constants
62LOCAL_SHARED_LIBRARIES := libcrypto-host libssl-host
63LOCAL_CXX_STL := none
64include $(BUILD_HOST_EXECUTABLE)
65
66conscrypt_generate_constants_exe := $(LOCAL_INSTALLED_MODULE)
67conscrypt_gen_java_files := $(TARGET_OUT_COMMON_GEN)/conscrypt/NativeConstants.java
68
69$(conscrypt_gen_java_files): $(conscrypt_generate_constants_exe)
70	mkdir -p $(dir $@)
71	$< > $@
72
73# Create the conscrypt library
74include $(CLEAR_VARS)
75LOCAL_SRC_FILES := $(call all-java-files-under,src/main/java)
76LOCAL_SRC_FILES += $(call all-java-files-under,src/platform/java)
77LOCAL_GENERATED_SOURCES := $(conscrypt_gen_java_files)
78LOCAL_JAVA_LIBRARIES := core-oj core-libart
79LOCAL_NO_STANDARD_LIBRARIES := true
80LOCAL_JAVACFLAGS := $(local_javac_flags)
81LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
82LOCAL_MODULE_TAGS := optional
83LOCAL_MODULE := conscrypt
84LOCAL_REQUIRED_MODULES := libjavacrypto
85LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
86LOCAL_JAVA_LANGUAGE_VERSION := 1.7
87include $(BUILD_JAVA_LIBRARY)
88
89# Create the conscrypt library without jarjar for tests
90include $(CLEAR_VARS)
91LOCAL_SRC_FILES := $(call all-java-files-under,src/main/java)
92LOCAL_SRC_FILES += $(call all-java-files-under,src/platform/java)
93LOCAL_GENERATED_SOURCES := $(conscrypt_gen_java_files)
94LOCAL_JAVA_LIBRARIES := core-oj core-libart
95LOCAL_NO_STANDARD_LIBRARIES := true
96LOCAL_JAVACFLAGS := $(local_javac_flags)
97LOCAL_MODULE_TAGS := optional
98LOCAL_MODULE := conscrypt-nojarjar
99LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
100LOCAL_JAVA_LANGUAGE_VERSION := 1.7
101include $(BUILD_STATIC_JAVA_LIBRARY)
102
103ifeq ($(LIBCORE_SKIP_TESTS),)
104# Make the conscrypt-tests library.
105include $(CLEAR_VARS)
106LOCAL_SRC_FILES := $(call all-java-files-under,src/test/java)
107LOCAL_JAVA_RESOURCE_DIRS := src/test/resources
108LOCAL_NO_STANDARD_LIBRARIES := true
109LOCAL_JAVA_LIBRARIES := core-oj core-libart core-junit bouncycastle
110LOCAL_STATIC_JAVA_LIBRARIES := core-tests-support conscrypt-nojarjar
111LOCAL_JAVACFLAGS := $(local_javac_flags)
112LOCAL_MODULE_TAGS := optional
113LOCAL_MODULE := conscrypt-tests
114LOCAL_REQUIRED_MODULES := libjavacrypto
115LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
116LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
117LOCAL_JAVA_LANGUAGE_VERSION := 1.7
118include $(BUILD_STATIC_JAVA_LIBRARY)
119endif
120
121# Platform conscrypt crypto JNI library
122include $(CLEAR_VARS)
123ifneq (,$(wildcard $(TOP)/external/boringssl/flavor.mk))
124    include $(TOP)/external/boringssl/flavor.mk
125else
126    include $(TOP)/external/openssl/flavor.mk
127endif
128LOCAL_CFLAGS += $(core_cflags)
129LOCAL_CFLAGS += -DJNI_JARJAR_PREFIX="com/android/"
130LOCAL_CPPFLAGS += $(core_cppflags)
131LOCAL_SRC_FILES := \
132        src/main/native/org_conscrypt_NativeCrypto.cpp
133LOCAL_C_INCLUDES += \
134        external/openssl/include \
135        external/openssl \
136        libcore/include \
137        libcore/luni/src/main/native
138LOCAL_SHARED_LIBRARIES := libcrypto libjavacore liblog libnativehelper libssl libz
139ifeq ($(OPENSSL_FLAVOR),BoringSSL)
140  LOCAL_SHARED_LIBRARIES += libkeystore-engine
141endif
142LOCAL_MODULE_TAGS := optional
143LOCAL_MODULE := libjavacrypto
144LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
145include $(BUILD_SHARED_LIBRARY)
146
147# Unbundled Conscrypt jar
148include $(CLEAR_VARS)
149LOCAL_SRC_FILES := $(call all-java-files-under,src/main/java)
150LOCAL_SRC_FILES += $(call all-java-files-under,src/compat/java)
151LOCAL_GENERATED_SOURCES := $(conscrypt_gen_java_files)
152LOCAL_SDK_VERSION := 9
153LOCAL_JAVACFLAGS := $(local_javac_flags)
154LOCAL_MODULE_TAGS := optional
155LOCAL_MODULE := conscrypt_unbundled
156LOCAL_JAVA_LIBRARIES := conscrypt-stubs
157LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
158LOCAL_JACK_FLAGS := -D jack.classpath.default-libraries=false
159LOCAL_JAVA_LANGUAGE_VERSION := 1.7
160include $(BUILD_STATIC_JAVA_LIBRARY)
161
162# Stub library for unbundled builds
163include $(CLEAR_VARS)
164LOCAL_SRC_FILES := $(call all-java-files-under,src/stub/java)
165LOCAL_SDK_VERSION := 9
166LOCAL_JAVACFLAGS := $(local_javac_flags)
167LOCAL_MODULE := conscrypt-stubs
168LOCAL_JACK_FLAGS := -D jack.classpath.default-libraries=false
169LOCAL_JAVA_LANGUAGE_VERSION := 1.7
170include $(BUILD_STATIC_JAVA_LIBRARY)
171
172# Unbundled Conscrypt crypto JNI library
173include $(CLEAR_VARS)
174LOCAL_CFLAGS += $(core_cflags)
175LOCAL_CPPFLAGS += $(core_cppflags)
176LOCAL_SRC_FILES := \
177        src/main/native/org_conscrypt_NativeCrypto.cpp \
178        src/compat/native/JNIHelp.cpp
179LOCAL_C_INCLUDES += \
180        external/openssl/include \
181        external/openssl \
182        external/conscrypt/src/compat/native
183# NO_KEYSTORE_ENGINE instructs the BoringSSL build of Conscrypt not to support
184# the keystore ENGINE. It is not available in this build configuration.
185LOCAL_CFLAGS += -DNO_KEYSTORE_ENGINE
186LOCAL_LDFLAGS := -llog -lz -ldl
187LOCAL_STATIC_LIBRARIES := libssl_static libcrypto_static
188LOCAL_MODULE_TAGS := optional
189LOCAL_MODULE := libconscrypt_jni
190LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
191LOCAL_SDK_VERSION := 9
192LOCAL_JAVA_LANGUAGE_VERSION := 1.7
193include $(BUILD_SHARED_LIBRARY)
194
195# Static unbundled Conscrypt crypto JNI library
196include $(CLEAR_VARS)
197LOCAL_CFLAGS += $(core_cflags)
198LOCAL_CPPFLAGS += $(core_cppflags) \
199        -DJNI_JARJAR_PREFIX="com/google/android/gms/" \
200        -DCONSCRYPT_UNBUNDLED \
201        -DSTATIC_LIB \
202        -DNO_KEYSTORE_ENGINE
203LOCAL_SRC_FILES := \
204        src/main/native/org_conscrypt_NativeCrypto.cpp \
205        src/compat/native/JNIHelp.cpp
206LOCAL_C_INCLUDES += \
207        external/openssl/include \
208        external/openssl \
209        external/conscrypt/src/compat/native
210LOCAL_MODULE_TAGS := optional
211LOCAL_MODULE := libconscrypt_static
212LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
213LOCAL_STATIC_LIBRARIES := libssl_static libcrypto_static
214LOCAL_SDK_VERSION := 9
215LOCAL_JAVA_LANGUAGE_VERSION := 1.7
216include $(BUILD_STATIC_LIBRARY)
217
218#
219# Build for the host.
220#
221
222ifeq ($(HOST_OS),linux)
223
224# Make the conscrypt-hostdex library
225include $(CLEAR_VARS)
226LOCAL_SRC_FILES := $(call all-java-files-under,src/main/java)
227LOCAL_SRC_FILES += $(call all-java-files-under,src/platform/java)
228LOCAL_GENERATED_SOURCES := $(conscrypt_gen_java_files)
229LOCAL_JAVACFLAGS := $(local_javac_flags)
230LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
231LOCAL_MODULE_TAGS := optional
232LOCAL_MODULE := conscrypt-hostdex
233LOCAL_REQUIRED_MODULES := libjavacrypto
234LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
235LOCAL_JAVA_LANGUAGE_VERSION := 1.7
236include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
237
238# Make the conscrypt-hostdex-nojarjar for tests
239include $(CLEAR_VARS)
240LOCAL_SRC_FILES := $(call all-java-files-under,src/main/java)
241LOCAL_SRC_FILES += $(call all-java-files-under,src/platform/java)
242LOCAL_GENERATED_SOURCES := $(conscrypt_gen_java_files)
243LOCAL_JAVACFLAGS := $(local_javac_flags)
244LOCAL_BUILD_HOST_DEX := true
245LOCAL_MODULE_TAGS := optional
246LOCAL_MODULE := conscrypt-hostdex-nojarjar
247LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
248LOCAL_JAVA_LANGUAGE_VERSION := 1.7
249include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
250
251# Make the conscrypt-tests library.
252ifeq ($(LIBCORE_SKIP_TESTS),)
253    include $(CLEAR_VARS)
254    LOCAL_SRC_FILES := $(call all-java-files-under,src/test/java)
255    LOCAL_JAVA_RESOURCE_DIRS := src/test/resources
256    LOCAL_JAVA_LIBRARIES := bouncycastle-hostdex core-junit-hostdex core-tests-support-hostdex conscrypt-hostdex-nojarjar
257    LOCAL_JAVACFLAGS := $(local_javac_flags)
258    LOCAL_MODULE_TAGS := optional
259    LOCAL_MODULE := conscrypt-tests-hostdex
260    LOCAL_REQUIRED_MODULES := libjavacrypto
261    LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
262    LOCAL_JAVA_LANGUAGE_VERSION := 1.7
263    include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
264endif
265
266# Conscrypt native library for host
267include $(CLEAR_VARS)
268LOCAL_CLANG := true
269LOCAL_SRC_FILES += \
270        src/main/native/org_conscrypt_NativeCrypto.cpp
271LOCAL_C_INCLUDES += \
272        external/openssl/include \
273        external/openssl \
274        libcore/include \
275        libcore/luni/src/main/native
276LOCAL_CPPFLAGS += $(core_cppflags)
277LOCAL_LDLIBS += -lpthread
278LOCAL_MODULE_TAGS := optional
279LOCAL_MODULE := libjavacrypto
280LOCAL_CFLAGS += -DJNI_JARJAR_PREFIX="com/android/"
281# NO_KEYSTORE_ENGINE instructs the BoringSSL build of Conscrypt not to support
282# the keystore ENGINE. It is not available in this build configuration.
283LOCAL_CFLAGS += -DNO_KEYSTORE_ENGINE
284LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
285LOCAL_SHARED_LIBRARIES := libcrypto-host libjavacore liblog libnativehelper libssl-host
286LOCAL_MULTILIB := both
287LOCAL_CXX_STL := none
288include $(BUILD_HOST_SHARED_LIBRARY)
289
290# Conscrypt native library for nojarjar'd version
291# Don't build this for unbundled conscrypt build
292ifeq (,$(TARGET_BUILD_APPS))
293    include $(CLEAR_VARS)
294    LOCAL_CLANG := true
295    LOCAL_SRC_FILES += \
296            src/main/native/org_conscrypt_NativeCrypto.cpp
297    LOCAL_C_INCLUDES += \
298            external/openssl/include \
299            external/openssl \
300            libcore/include \
301            libcore/luni/src/main/native
302    LOCAL_CPPFLAGS += $(core_cppflags) -DCONSCRYPT_NOT_UNBUNDLED
303    LOCAL_LDLIBS += -lpthread
304    LOCAL_MODULE_TAGS := optional
305    LOCAL_MODULE := libconscrypt_jni
306    LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
307    # NO_KEYSTORE_ENGINE instructs the BoringSSL build of Conscrypt not to
308    # support the keystore ENGINE. It is not available in this build
309    # configuration.
310    LOCAL_CFLAGS += -DNO_KEYSTORE_ENGINE
311    LOCAL_SHARED_LIBRARIES := libcrypto-host libjavacore liblog libnativehelper libssl-host
312    LOCAL_MULTILIB := both
313    LOCAL_CXX_STL := none
314    include $(BUILD_HOST_SHARED_LIBRARY)
315endif
316
317endif # HOST_OS == linux
318
319# Conscrypt JNI library for host OpenJDK
320# To be self-contained, this shared library statically links in all of its
321# Android-specific dependencies.
322include $(CLEAR_VARS)
323LOCAL_CLANG := true
324LOCAL_SRC_FILES += \
325        src/main/native/org_conscrypt_NativeCrypto.cpp \
326        src/openjdk/native/JNIHelp.cpp
327LOCAL_C_INCLUDES += \
328        external/openssl/include \
329        external/openssl \
330        external/conscrypt/src/openjdk/native
331LOCAL_CPPFLAGS += $(core_cppflags)
332LOCAL_LDLIBS += -lpthread
333LOCAL_MODULE_TAGS := optional
334LOCAL_MODULE := libconscrypt_openjdk_jni
335LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
336# NO_KEYSTORE_ENGINE instructs the BoringSSL build of Conscrypt not to
337# support the keystore ENGINE. It is not available in this build
338# configuration.
339LOCAL_CFLAGS += -DNO_KEYSTORE_ENGINE
340LOCAL_CXX_STL := libc++_static
341LOCAL_WHOLE_STATIC_LIBRARIES := libcrypto_static libssl_static-host
342LOCAL_MULTILIB := both
343# TODO: b/26097626. ASAN breaks use of this library in JVM.
344# Re-enable sanitization when the issue with making clients of this library
345# preload ASAN runtime is resolved. Without that, clients are getting runtime
346# errors due to unresoled ASAN symbols, such as
347# __asan_option_detect_stack_use_after_return.
348LOCAL_SANITIZE := never
349include $(BUILD_HOST_SHARED_LIBRARY)
350
351# Conscrypt Java library for host OpenJDK
352include $(CLEAR_VARS)
353LOCAL_SRC_FILES := $(call all-java-files-under,src/main/java)
354LOCAL_SRC_FILES += $(call all-java-files-under,src/openjdk/java)
355LOCAL_SRC_FILES += $(call all-java-files-under,src/openjdk-host/java)
356LOCAL_GENERATED_SOURCES := $(conscrypt_gen_java_files)
357LOCAL_JAVACFLAGS := $(local_javac_flags)
358LOCAL_MODULE_TAGS := optional
359LOCAL_MODULE := conscrypt-host
360LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
361LOCAL_JAVA_LANGUAGE_VERSION := 1.7
362include $(BUILD_HOST_JAVA_LIBRARY)
363
364# clear out local variables
365core_cflags :=
366core_cppflags :=
367local_javac_flags :=
368