blob: 492d295a00d394cd4f23ca78c4e2947665a5d9d4 [file] [log] [blame]
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +03001# 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
16LOCAL_PATH := $(abspath $(call my-dir)/..)
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030017
Anestis Bechtsoudis3195a992016-10-28 11:32:19 +030018# Force a clean if target API has changed and a previous build exists
19ifneq ("$(wildcard $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/android_api.txt)","")
20 CACHED_API := $(shell cat "$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/android_api.txt")
21 ifneq ($(ANDROID_API),$(CACHED_API))
22 $(info [!] Previous build was targeting different API level - cleaning)
23 DUMMY_CLEAN := $(shell make clean)
24 endif
25endif
26
27# Force a clean if selected toolchain has changed and a previous build exists
28ifneq ("$(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
34endif
35
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +030036# Enable Linux ptrace() instead of POSIX signal interface by default
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030037ANDROID_WITH_PTRACE ?= true
38
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030039ifeq ($(ANDROID_WITH_PTRACE),true)
Anestis Bechtsoudisf1812722015-08-19 10:12:19 +030040 ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi armeabi-v7a))
41 ARCH_ABI := arm
Anestis Bechtsoudisf1812722015-08-19 10:12:19 +030042 else ifeq ($(APP_ABI),$(filter $(APP_ABI),x86))
43 ARCH_ABI := x86
Anestis Bechtsoudisf1812722015-08-19 10:12:19 +030044 else ifeq ($(APP_ABI),$(filter $(APP_ABI),arm64-v8a))
45 ARCH_ABI := arm64
Anestis Bechtsoudisf1812722015-08-19 10:12:19 +030046 else ifeq ($(APP_ABI),$(filter $(APP_ABI),x86_64))
47 ARCH_ABI := x86_64
Anestis Bechtsoudisf1812722015-08-19 10:12:19 +030048 else
49 $(error Unsuported / Unknown APP_API '$(APP_ABI)')
50 endif
51
Anestis Bechtsoudisbe7fa272015-09-10 17:27:44 +030052 # 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 Bechtsoudis66cbb082015-09-11 20:15:15 +030055 else ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi-v7a))
Anestis Bechtsoudisbe7fa272015-09-10 17:27:44 +030056 OPENSSL_ARMCAP_ABI := "7"
57 endif
58
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030059 # Upstream libunwind compiled from sources with Android NDK toolchain
Anestis Bechtsoudis48b280a2016-10-28 10:05:10 +030060 LIBUNWIND_A := third_party/android/libunwind/$(ARCH_ABI)/libunwind-$(ARCH_ABI).a
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030061 ifeq ("$(wildcard $(LIBUNWIND_A))","")
Anestis Bechtsoudis48b280a2016-10-28 10:05:10 +030062 $(error libunwind-$(ARCH_ABI) is missing - to build execute \
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030063 '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 Bechtsoudis48b280a2016-10-28 10:05:10 +030074 LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-$(ARCH_ABI).a
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030075 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 Bechtsoudis96ff5902016-10-17 10:52:24 +030092 $(error libcapstone is missing - to build execute \
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030093 '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)
100endif
101
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300102ifneq (,$(findstring clang,$(NDK_TOOLCHAIN)))
103 LIBBRT_A := third_party/android/libBlocksRuntime/$(ARCH_ABI)/libblocksruntime.a
104 ifeq ("$(wildcard $(LIBBRT_A))","")
Anestis Bechtsoudis96ff5902016-10-17 10:52:24 +0300105 $(error libBlocksRuntime is missing - to build execute \
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300106 '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)
112endif
113
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300114ifeq ($(ANDROID_WITH_PTRACE),true)
Jagger3db1d952016-03-10 02:02:46 +0100115 ARCH_SRCS := linux/arch.c linux/ptrace_utils.c linux/perf.c linux/unwind.c linux/pt.c
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300116 ARCH := LINUX
117 $(info $(shell (echo "********************************************************************")))
118 $(info $(shell (echo "Android PTRACE build: Will prevent debuggerd from processing crashes")))
119 $(info $(shell (echo "********************************************************************")))
120else
121 ARCH_SRCS := posix/arch.c
122 ARCH := POSIX
123 $(info $(shell (echo "********************************************************************")))
Anestis Bechtsoudis61a8f4f2015-08-20 08:39:26 +0300124 $(info $(shell (echo "Android POSIX build: Will allow debuggerd to also process crashes")))
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300125 $(info $(shell (echo "********************************************************************")))
126endif
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300127
Anestis Bechtsoudis795853e2016-10-18 10:32:09 +0300128COMMON_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
135include $(CLEAR_VARS)
136LOCAL_MODULE := hfuzz
137LOCAL_SRC_FILES := $(wildcard libhfuzz/*.c)
138LOCAL_CFLAGS := -D_HF_ARCH_${ARCH} $(COMMON_CFLAGS) \
139 -fPIC -fno-builtin -fno-stack-protector
140
141ifneq (,$(findstring clang,$(NDK_TOOLCHAIN)))
142 LOCAL_CFLAGS += -fblocks
143 LOCAL_STATIC_LIBRARIES += libblocksruntime
144endif
145
146include $(BUILD_STATIC_LIBRARY)
147
148# Main honggfuzz module
149include $(CLEAR_VARS)
150
151LOCAL_MODULE := honggfuzz
152LOCAL_SRC_FILES := $(wildcard *.c)
153LOCAL_CFLAGS := $(COMMON_CFLAGS)
154LOCAL_LDFLAGS := -lm -latomic
155LOCAL_STATIC_LIBRARIES := libhfuzz
156
157ifeq ($(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
169endif
170
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300171LOCAL_SRC_FILES += $(ARCH_SRCS)
Anestis Bechtsoudis66cbb082015-09-11 20:15:15 +0300172LOCAL_CFLAGS += -D_HF_ARCH_${ARCH}
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300173
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300174ifneq (,$(findstring clang,$(NDK_TOOLCHAIN)))
175 LOCAL_CFLAGS += -fblocks
176 LOCAL_STATIC_LIBRARIES += libblocksruntime
177endif
178
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300179include $(BUILD_EXECUTABLE)
Anestis Bechtsoudis795853e2016-10-18 10:32:09 +0300180
181# The NDK build system does not copy static libraries into project/packages
Anestis Bechtsoudis3195a992016-10-28 11:32:19 +0300182# 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 Bechtsoudis795853e2016-10-18 10:32:09 +0300185all:POST_BUILD_EVENT
186POST_BUILD_EVENT:
Anestis Bechtsoudis3195a992016-10-28 11:32:19 +0300187 @echo $(ANDROID_API) > $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/android_api.txt
188 @echo $(NDK_TOOLCHAIN) > $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/ndk_toolchain.txt
Anestis Bechtsoudis795853e2016-10-18 10:32:09 +0300189 @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