Anestis Bechtsoudis | c1f6faa | 2015-07-31 05:32:19 +0300 | [diff] [blame] | 1 | # honggfuzz - Android makefile |
| 2 | # ----------------------------------------- |
| 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 | LOCAL_PATH := $(abspath $(call my-dir)/..) |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 17 | |
Anestis Bechtsoudis | 3195a99 | 2016-10-28 11:32:19 +0300 | [diff] [blame] | 18 | # Force a clean if target API has changed and a previous build exists |
| 19 | ifneq ("$(wildcard $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/android_api.txt)","") |
| 20 | CACHED_API := $(shell cat "$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/android_api.txt") |
Anestis Bechtsoudis | 95cc309 | 2016-10-30 12:22:34 +0200 | [diff] [blame^] | 21 | ifneq ($(APP_PLATFORM),$(CACHED_API)) |
Anestis Bechtsoudis | 3195a99 | 2016-10-28 11:32:19 +0300 | [diff] [blame] | 22 | $(info [!] Previous build was targeting different API level - cleaning) |
| 23 | DUMMY_CLEAN := $(shell make clean) |
| 24 | endif |
| 25 | endif |
| 26 | |
| 27 | # Force a clean if selected toolchain has changed and a previous build exists |
| 28 | ifneq ("$(wildcard $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/ndk_toolchain.txt)","") |
| 29 | CACHED_TOOLCHAIN := $(shell cat "$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/ndk_toolchain.txt") |
| 30 | ifneq ($(NDK_TOOLCHAIN),$(CACHED_TOOLCHAIN)) |
| 31 | $(info [!] Previous build was using different toolchain - cleaning) |
| 32 | DUMMY_CLEAN := $(shell make clean) |
| 33 | endif |
| 34 | endif |
| 35 | |
Anestis Bechtsoudis | d1fccd5 | 2016-05-06 13:11:27 +0300 | [diff] [blame] | 36 | # Enable Linux ptrace() instead of POSIX signal interface by default |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 37 | ANDROID_WITH_PTRACE ?= true |
| 38 | |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 39 | ifeq ($(ANDROID_WITH_PTRACE),true) |
Anestis Bechtsoudis | f181272 | 2015-08-19 10:12:19 +0300 | [diff] [blame] | 40 | ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi armeabi-v7a)) |
| 41 | ARCH_ABI := arm |
Anestis Bechtsoudis | f181272 | 2015-08-19 10:12:19 +0300 | [diff] [blame] | 42 | else ifeq ($(APP_ABI),$(filter $(APP_ABI),x86)) |
| 43 | ARCH_ABI := x86 |
Anestis Bechtsoudis | f181272 | 2015-08-19 10:12:19 +0300 | [diff] [blame] | 44 | else ifeq ($(APP_ABI),$(filter $(APP_ABI),arm64-v8a)) |
| 45 | ARCH_ABI := arm64 |
Anestis Bechtsoudis | f181272 | 2015-08-19 10:12:19 +0300 | [diff] [blame] | 46 | else ifeq ($(APP_ABI),$(filter $(APP_ABI),x86_64)) |
| 47 | ARCH_ABI := x86_64 |
Anestis Bechtsoudis | f181272 | 2015-08-19 10:12:19 +0300 | [diff] [blame] | 48 | else |
| 49 | $(error Unsuported / Unknown APP_API '$(APP_ABI)') |
| 50 | endif |
| 51 | |
Anestis Bechtsoudis | be7fa27 | 2015-09-10 17:27:44 +0300 | [diff] [blame] | 52 | # Additional libcrypto OpenSSL flags required to mitigate bug (ARM systems with API <= 21) |
| 53 | ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi)) |
| 54 | OPENSSL_ARMCAP_ABI := "5" |
Anestis Bechtsoudis | 66cbb08 | 2015-09-11 20:15:15 +0300 | [diff] [blame] | 55 | else ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi-v7a)) |
Anestis Bechtsoudis | be7fa27 | 2015-09-10 17:27:44 +0300 | [diff] [blame] | 56 | OPENSSL_ARMCAP_ABI := "7" |
| 57 | endif |
| 58 | |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 59 | # Upstream libunwind compiled from sources with Android NDK toolchain |
Anestis Bechtsoudis | 48b280a | 2016-10-28 10:05:10 +0300 | [diff] [blame] | 60 | LIBUNWIND_A := third_party/android/libunwind/$(ARCH_ABI)/libunwind-$(ARCH_ABI).a |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 61 | ifeq ("$(wildcard $(LIBUNWIND_A))","") |
Anestis Bechtsoudis | 48b280a | 2016-10-28 10:05:10 +0300 | [diff] [blame] | 62 | $(error libunwind-$(ARCH_ABI) is missing - to build execute \ |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 63 | 'third_party/android/scripts/compile-libunwind.sh third_party/android/libunwind $(ARCH_ABI)') |
| 64 | endif |
| 65 | |
| 66 | include $(CLEAR_VARS) |
| 67 | LOCAL_MODULE := libunwind |
| 68 | LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind.a |
| 69 | LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include |
| 70 | include $(PREBUILT_STATIC_LIBRARY) |
| 71 | |
| 72 | include $(CLEAR_VARS) |
| 73 | LOCAL_MODULE := libunwind-arch |
Anestis Bechtsoudis | 48b280a | 2016-10-28 10:05:10 +0300 | [diff] [blame] | 74 | LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-$(ARCH_ABI).a |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 75 | LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include |
| 76 | include $(PREBUILT_STATIC_LIBRARY) |
| 77 | |
| 78 | include $(CLEAR_VARS) |
| 79 | LOCAL_MODULE := libunwind-ptrace |
| 80 | LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-ptrace.a |
| 81 | LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include |
| 82 | include $(PREBUILT_STATIC_LIBRARY) |
| 83 | |
| 84 | LOCAL_MODULE := libunwind-dwarf-generic |
| 85 | LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-dwarf-generic.a |
| 86 | LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include |
| 87 | include $(PREBUILT_STATIC_LIBRARY) |
| 88 | |
| 89 | # Upstream capstone compiled from sources with Android NDK toolchain |
| 90 | LIBCAPSTONE_A := third_party/android/capstone/$(ARCH_ABI)/libcapstone.a |
| 91 | ifeq ("$(wildcard $(LIBCAPSTONE_A))","") |
Anestis Bechtsoudis | 96ff590 | 2016-10-17 10:52:24 +0300 | [diff] [blame] | 92 | $(error libcapstone is missing - to build execute \ |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 93 | 'third_party/android/scripts/compile-capstone.sh third_party/android/capstone $(ARCH_ABI)') |
| 94 | endif |
| 95 | include $(CLEAR_VARS) |
| 96 | LOCAL_MODULE := libcapstone |
| 97 | LOCAL_SRC_FILES := $(LIBCAPSTONE_A) |
| 98 | LOCAL_EXPORT_C_INCLUDES := third_party/android/capstone/include |
| 99 | include $(PREBUILT_STATIC_LIBRARY) |
| 100 | endif |
| 101 | |
Anestis Bechtsoudis | d1fccd5 | 2016-05-06 13:11:27 +0300 | [diff] [blame] | 102 | ifneq (,$(findstring clang,$(NDK_TOOLCHAIN))) |
| 103 | LIBBRT_A := third_party/android/libBlocksRuntime/$(ARCH_ABI)/libblocksruntime.a |
| 104 | ifeq ("$(wildcard $(LIBBRT_A))","") |
Anestis Bechtsoudis | 96ff590 | 2016-10-17 10:52:24 +0300 | [diff] [blame] | 105 | $(error libBlocksRuntime is missing - to build execute \ |
Anestis Bechtsoudis | d1fccd5 | 2016-05-06 13:11:27 +0300 | [diff] [blame] | 106 | 'third_party/android/scripts/compile-libBlocksRuntime.sh third_party/android/libBlocksRuntime $(ARCH_ABI)') |
| 107 | endif |
| 108 | include $(CLEAR_VARS) |
| 109 | LOCAL_MODULE := libblocksruntime |
| 110 | LOCAL_SRC_FILES := $(LIBBRT_A) |
| 111 | include $(PREBUILT_STATIC_LIBRARY) |
| 112 | endif |
| 113 | |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 114 | ifeq ($(ANDROID_WITH_PTRACE),true) |
Jagger | 3db1d95 | 2016-03-10 02:02:46 +0100 | [diff] [blame] | 115 | ARCH_SRCS := linux/arch.c linux/ptrace_utils.c linux/perf.c linux/unwind.c linux/pt.c |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 116 | ARCH := LINUX |
| 117 | $(info $(shell (echo "********************************************************************"))) |
| 118 | $(info $(shell (echo "Android PTRACE build: Will prevent debuggerd from processing crashes"))) |
| 119 | $(info $(shell (echo "********************************************************************"))) |
| 120 | else |
| 121 | ARCH_SRCS := posix/arch.c |
| 122 | ARCH := POSIX |
| 123 | $(info $(shell (echo "********************************************************************"))) |
Anestis Bechtsoudis | 61a8f4f | 2015-08-20 08:39:26 +0300 | [diff] [blame] | 124 | $(info $(shell (echo "Android POSIX build: Will allow debuggerd to also process crashes"))) |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 125 | $(info $(shell (echo "********************************************************************"))) |
| 126 | endif |
Anestis Bechtsoudis | c1f6faa | 2015-07-31 05:32:19 +0300 | [diff] [blame] | 127 | |
Anestis Bechtsoudis | 795853e | 2016-10-18 10:32:09 +0300 | [diff] [blame] | 128 | COMMON_CFLAGS := -std=c11 -I. \ |
| 129 | -D_GNU_SOURCE \ |
| 130 | -Wall -Wextra -Wno-initializer-overrides -Wno-override-init \ |
| 131 | -Wno-unknown-warning-option -Werror -funroll-loops -O2 \ |
| 132 | -Wframe-larger-than=51200 |
| 133 | |
| 134 | # libhfuzz module |
| 135 | include $(CLEAR_VARS) |
| 136 | LOCAL_MODULE := hfuzz |
| 137 | LOCAL_SRC_FILES := $(wildcard libhfuzz/*.c) |
| 138 | LOCAL_CFLAGS := -D_HF_ARCH_${ARCH} $(COMMON_CFLAGS) \ |
| 139 | -fPIC -fno-builtin -fno-stack-protector |
| 140 | |
| 141 | ifneq (,$(findstring clang,$(NDK_TOOLCHAIN))) |
| 142 | LOCAL_CFLAGS += -fblocks |
| 143 | LOCAL_STATIC_LIBRARIES += libblocksruntime |
| 144 | endif |
| 145 | |
| 146 | include $(BUILD_STATIC_LIBRARY) |
| 147 | |
| 148 | # Main honggfuzz module |
| 149 | include $(CLEAR_VARS) |
| 150 | |
| 151 | LOCAL_MODULE := honggfuzz |
| 152 | LOCAL_SRC_FILES := $(wildcard *.c) |
| 153 | LOCAL_CFLAGS := $(COMMON_CFLAGS) |
| 154 | LOCAL_LDFLAGS := -lm -latomic |
| 155 | LOCAL_STATIC_LIBRARIES := libhfuzz |
| 156 | |
| 157 | ifeq ($(ANDROID_WITH_PTRACE),true) |
| 158 | LOCAL_C_INCLUDES := third_party/android/libunwind/include \ |
| 159 | third_party/android/capstone/include |
| 160 | LOCAL_STATIC_LIBRARIES += libunwind-arch \ |
| 161 | libunwind \ |
| 162 | libunwind-ptrace \ |
| 163 | libunwind-dwarf-generic \ |
| 164 | libcapstone |
| 165 | LOCAL_CFLAGS += -D__HF_USE_CAPSTONE__ |
| 166 | ifeq ($(ARCH_ABI),arm) |
| 167 | LOCAL_CFLAGS += -DOPENSSL_ARMCAP_ABI='$(OPENSSL_ARMCAP_ABI)' |
| 168 | endif |
| 169 | endif |
| 170 | |
Anestis Bechtsoudis | c1f6faa | 2015-07-31 05:32:19 +0300 | [diff] [blame] | 171 | LOCAL_SRC_FILES += $(ARCH_SRCS) |
Anestis Bechtsoudis | 66cbb08 | 2015-09-11 20:15:15 +0300 | [diff] [blame] | 172 | LOCAL_CFLAGS += -D_HF_ARCH_${ARCH} |
Anestis Bechtsoudis | c1f6faa | 2015-07-31 05:32:19 +0300 | [diff] [blame] | 173 | |
Anestis Bechtsoudis | d1fccd5 | 2016-05-06 13:11:27 +0300 | [diff] [blame] | 174 | ifneq (,$(findstring clang,$(NDK_TOOLCHAIN))) |
| 175 | LOCAL_CFLAGS += -fblocks |
| 176 | LOCAL_STATIC_LIBRARIES += libblocksruntime |
| 177 | endif |
| 178 | |
Anestis Bechtsoudis | c1f6faa | 2015-07-31 05:32:19 +0300 | [diff] [blame] | 179 | include $(BUILD_EXECUTABLE) |
Anestis Bechtsoudis | 795853e | 2016-10-18 10:32:09 +0300 | [diff] [blame] | 180 | |
| 181 | # The NDK build system does not copy static libraries into project/packages |
Anestis Bechtsoudis | 3195a99 | 2016-10-28 11:32:19 +0300 | [diff] [blame] | 182 | # so it has to be done manually in order to have all output under a single path. |
| 183 | # Also save some build attribute cache files so that cleans can be enforced when |
| 184 | # required. |
Anestis Bechtsoudis | 795853e | 2016-10-18 10:32:09 +0300 | [diff] [blame] | 185 | all:POST_BUILD_EVENT |
| 186 | POST_BUILD_EVENT: |
Anestis Bechtsoudis | 95cc309 | 2016-10-30 12:22:34 +0200 | [diff] [blame^] | 187 | @echo $(APP_PLATFORM) > $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/android_api.txt |
Anestis Bechtsoudis | 3195a99 | 2016-10-28 11:32:19 +0300 | [diff] [blame] | 188 | @echo $(NDK_TOOLCHAIN) > $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/ndk_toolchain.txt |
Anestis Bechtsoudis | 795853e | 2016-10-18 10:32:09 +0300 | [diff] [blame] | 189 | @test -f $(LOCAL_PATH)/obj/local/$(TARGET_ARCH_ABI)/libhfuzz.a && \ |
| 190 | cp $(LOCAL_PATH)/obj/local/$(TARGET_ARCH_ABI)/libhfuzz.a \ |
| 191 | $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libhfuzz.a || true |