Android.mk revision 53bfdae4ffdbd43d0c019d1a35af1f8477a272c9
1# 2# Copyright (C) 2012 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 17ifneq ($(BUILD_TINY_ANDROID), true) 18 19LOCAL_PATH := $(call my-dir) 20 21# ----------------------------------------------------------------------------- 22# Benchmarks. 23# ----------------------------------------------------------------------------- 24 25benchmark_c_flags = \ 26 -O2 \ 27 -Wall -Wextra \ 28 -Werror \ 29 -fno-builtin \ 30 31benchmark_src_files = \ 32 benchmark_main.cpp \ 33 math_benchmark.cpp \ 34 property_benchmark.cpp \ 35 string_benchmark.cpp \ 36 time_benchmark.cpp \ 37 38# Build benchmarks for the device (with bionic's .so). Run with: 39# adb shell bionic-benchmarks 40include $(CLEAR_VARS) 41LOCAL_MODULE := bionic-benchmarks 42LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 43LOCAL_CFLAGS += $(benchmark_c_flags) 44LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include 45LOCAL_SHARED_LIBRARIES += libstlport 46LOCAL_SRC_FILES := $(benchmark_src_files) 47include $(BUILD_EXECUTABLE) 48 49# ----------------------------------------------------------------------------- 50# Unit tests. 51# ----------------------------------------------------------------------------- 52 53test_c_flags = \ 54 -fstack-protector-all \ 55 -g \ 56 -Wall -Wextra \ 57 -Werror \ 58 -fno-builtin \ 59 60test_src_files = \ 61 dirent_test.cpp \ 62 eventfd_test.cpp \ 63 fenv_test.cpp \ 64 getauxval_test.cpp \ 65 getcwd_test.cpp \ 66 inttypes_test.cpp \ 67 libc_logging_test.cpp \ 68 libgen_test.cpp \ 69 malloc_test.cpp \ 70 math_test.cpp \ 71 netdb_test.cpp \ 72 pthread_test.cpp \ 73 regex_test.cpp \ 74 sched_test.cpp \ 75 signal_test.cpp \ 76 stack_protector_test.cpp \ 77 stack_unwinding_test.cpp \ 78 statvfs_test.cpp \ 79 stdio_test.cpp \ 80 stdlib_test.cpp \ 81 string_test.cpp \ 82 strings_test.cpp \ 83 stubs_test.cpp \ 84 sys_select_test.cpp \ 85 sys_sendfile_test.cpp \ 86 sys_stat_test.cpp \ 87 system_properties_test.cpp \ 88 time_test.cpp \ 89 unistd_test.cpp \ 90 91test_dynamic_ldflags = -Wl,--export-dynamic -Wl,-u,DlSymTestFunction 92test_dynamic_src_files = \ 93 dlfcn_test.cpp \ 94 95test_fortify_static_libraries = \ 96 fortify1-tests-gcc fortify2-tests-gcc fortify1-tests-clang fortify2-tests-clang 97 98include $(CLEAR_VARS) 99LOCAL_MODULE := bionic-unit-tests-unwind-test-impl 100LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions 101LOCAL_SRC_FILES := stack_unwinding_test_impl.c 102include $(BUILD_STATIC_LIBRARY) 103 104include $(CLEAR_VARS) 105LOCAL_MODULE := bionic-unit-tests-unwind-test-impl-host 106LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions 107LOCAL_SRC_FILES := stack_unwinding_test_impl.c 108include $(BUILD_HOST_STATIC_LIBRARY) 109 110# Build tests for the device (with bionic's .so). Run with: 111# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests 112include $(CLEAR_VARS) 113LOCAL_MODULE := bionic-unit-tests 114LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 115LOCAL_CFLAGS += $(test_c_flags) 116LOCAL_LDFLAGS += $(test_dynamic_ldflags) 117LOCAL_SHARED_LIBRARIES += libdl 118LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files) 119LOCAL_WHOLE_STATIC_LIBRARIES := $(test_fortify_static_libraries) 120LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl 121include $(BUILD_NATIVE_TEST) 122 123# Build tests for the device (with bionic's .a). Run with: 124# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static 125include $(CLEAR_VARS) 126LOCAL_MODULE := bionic-unit-tests-static 127LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 128LOCAL_FORCE_STATIC_EXECUTABLE := true 129LOCAL_WHOLE_STATIC_LIBRARIES += libBionicTests 130LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc 131include $(BUILD_NATIVE_TEST) 132 133# ----------------------------------------------------------------------------- 134# We build the static unit tests as a library so they can be used both for 135# bionic-unit-tests-static and also as part of CTS. 136# ----------------------------------------------------------------------------- 137 138include $(CLEAR_VARS) 139LOCAL_MODULE := libBionicTests 140LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 141LOCAL_CFLAGS += $(test_c_flags) 142LOCAL_SRC_FILES := $(test_src_files) 143LOCAL_CFLAGS += \ 144 -DGTEST_OS_LINUX_ANDROID \ 145 -DGTEST_HAS_STD_STRING \ 146 147LOCAL_C_INCLUDES += \ 148 bionic bionic/libstdc++/include \ 149 external/gtest/include \ 150 external/stlport/stlport \ 151 152LOCAL_WHOLE_STATIC_LIBRARIES := \ 153 $(test_fortify_static_libraries) \ 154 bionic-unit-tests-unwind-test-impl \ 155 156include $(BUILD_STATIC_LIBRARY) 157 158# ----------------------------------------------------------------------------- 159# Test library for the unit tests. 160# ----------------------------------------------------------------------------- 161 162# Build no-elf-hash-table-library.so to test dlopen(3) on a library that 163# only has a GNU-style hash table. MIPS doesn't support GNU hash style. 164ifneq ($(TARGET_ARCH),mips) 165include $(CLEAR_VARS) 166LOCAL_MODULE := no-elf-hash-table-library 167LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 168LOCAL_SRC_FILES := empty.cpp 169LOCAL_LDFLAGS := -Wl,--hash-style=gnu 170include $(BUILD_SHARED_LIBRARY) 171endif 172 173# ----------------------------------------------------------------------------- 174# Unit tests built against glibc. 175# ----------------------------------------------------------------------------- 176 177# Build tests for the host (with glibc). 178# Note that this will build against glibc, so it's not useful for testing 179# bionic's implementation, but it does let you use glibc as a reference 180# implementation for testing the tests themselves. 181ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) 182include $(CLEAR_VARS) 183LOCAL_MODULE := bionic-unit-tests-glibc 184LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 185LOCAL_CFLAGS += $(test_c_flags) 186LOCAL_LDFLAGS += -lpthread -ldl -lrt 187LOCAL_LDFLAGS += $(test_dynamic_ldflags) 188LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files) 189LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host 190include $(BUILD_HOST_NATIVE_TEST) 191endif 192 193# ----------------------------------------------------------------------------- 194# Run the unit tests built against x86 bionic on an x86 host. 195# ----------------------------------------------------------------------------- 196 197ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) 198ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) 199ifeq ($(TARGET_ARCH),x86) 200LINKER = linker 201else 202LINKER = linker64 203endif 204# gtest needs EXTERNAL_STORAGE for death test output. 205# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT. 206# We create /data/local/tmp to be as much like the regular target environment 207# as possible. 208bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh 209 mkdir -p $(TARGET_OUT_DATA)/local/tmp 210 cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin 211 cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin 212 ANDROID_DATA=$(TARGET_OUT_DATA) \ 213 ANDROID_ROOT=$(TARGET_OUT) \ 214 EXTERNAL_STORAGE=$(TARGET_OUT_DATA)/local/tmp \ 215 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \ 216 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests 217endif 218endif 219 220# ----------------------------------------------------------------------------- 221# FORTIFY_SOURCE tests 222# ----------------------------------------------------------------------------- 223 224fortify_c_includes = \ 225 bionic \ 226 bionic/libstdc++/include \ 227 external/stlport/stlport \ 228 external/gtest/include 229fortify_test_files = fortify_test.cpp 230 231# -Wno-error=unused-parameter needed as 232# external/stlport/stlport/stl/_threads.c (included from 233# external/gtest/include/gtest/gtest.h) does not compile cleanly under 234# clang. TODO: fix this. 235fortify_c_flags = $(test_c_flags) -Wno-error=unused-parameter 236 237include $(CLEAR_VARS) 238LOCAL_SRC_FILES := $(fortify_test_files) 239LOCAL_MODULE := fortify1-tests-gcc 240LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Gcc 241LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 242LOCAL_C_INCLUDES += $(fortify_c_includes) 243include $(BUILD_STATIC_LIBRARY) 244 245include $(CLEAR_VARS) 246LOCAL_SRC_FILES := $(fortify_test_files) 247LOCAL_MODULE := fortify2-tests-gcc 248LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Gcc 249LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 250LOCAL_C_INCLUDES += $(fortify_c_includes) 251include $(BUILD_STATIC_LIBRARY) 252 253include $(CLEAR_VARS) 254LOCAL_SRC_FILES := $(fortify_test_files) 255LOCAL_MODULE := fortify1-tests-clang 256LOCAL_CLANG := true 257LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Clang 258LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 259LOCAL_C_INCLUDES += $(fortify_c_includes) 260include $(BUILD_STATIC_LIBRARY) 261 262include $(CLEAR_VARS) 263LOCAL_SRC_FILES := $(fortify_test_files) 264LOCAL_MODULE := fortify2-tests-clang 265LOCAL_CLANG := true 266LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Clang 267LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 268LOCAL_C_INCLUDES += $(fortify_c_includes) 269include $(BUILD_STATIC_LIBRARY) 270 271endif # !BUILD_TINY_ANDROID 272