robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 1 | # honggfuzz - Makefile |
| 2 | # ----------------------------------------- |
| 3 | # |
| 4 | # Author: Robert Swiecki <swiecki@google.com> |
| 5 | # |
robert.swiecki@gmail.com | ba85c3e | 2015-02-02 14:55:16 +0000 | [diff] [blame] | 6 | # Copyright 2010-2015 by Google Inc. All Rights Reserved. |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
Aaron Carreras | 0903ae4 | 2016-10-14 13:25:55 -0400 | [diff] [blame] | 19 | # |
| 20 | # NOTE: xcrun is within xcode...xcode is required on OSX. |
| 21 | # |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 22 | |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 23 | # Common for all architectures |
Robert Swiecki | a9db9dd | 2016-03-09 16:29:37 +0100 | [diff] [blame] | 24 | CC ?= gcc |
| 25 | LD = $(CC) |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 26 | BIN := honggfuzz |
Robert Swiecki | fc35c5e | 2016-03-09 17:18:48 +0100 | [diff] [blame] | 27 | COMMON_CFLAGS := -D_GNU_SOURCE -Wall -Werror -Wframe-larger-than=131072 |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 28 | COMMON_LDFLAGS := -lm |
Robert Swiecki | 0e67388 | 2016-03-31 18:50:29 +0200 | [diff] [blame] | 29 | COMMON_SRCS := honggfuzz.c cmdline.c display.c files.c fuzz.c log.c mangle.c report.c sancov.c subproc.c util.c |
Jagger | a443b69 | 2016-08-29 23:01:15 +0200 | [diff] [blame] | 30 | CFLAGS ?= -O3 |
| 31 | LDFLAGS ?= |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 32 | |
robert.swiecki@gmail.com | 448d281 | 2015-02-02 20:57:13 +0000 | [diff] [blame] | 33 | OS ?= $(shell uname -s) |
robert.swiecki@gmail.com | 15eca6f | 2015-03-04 03:31:36 +0000 | [diff] [blame] | 34 | MARCH ?= $(shell uname -m) |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 35 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 36 | ifeq ($(OS),Linux) |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 37 | ARCH := LINUX |
Robert Swiecki | ac310a8 | 2016-02-22 18:58:36 +0100 | [diff] [blame] | 38 | |
Robert Swiecki | 94d54ff | 2016-09-06 14:38:21 +0200 | [diff] [blame] | 39 | ARCH_CFLAGS := -std=c11 -I/usr/local/include -I/usr/include \ |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 40 | -Wextra -Wno-initializer-overrides -Wno-override-init \ |
Robert Swiecki | 0a7ce04 | 2016-08-25 15:31:31 +0200 | [diff] [blame] | 41 | -Wno-unknown-warning-option -funroll-loops \ |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 42 | -D_FILE_OFFSET_BITS=64 |
Jagger | 2e06f56 | 2016-02-11 09:32:39 +0100 | [diff] [blame] | 43 | ARCH_LDFLAGS := -L/usr/local/include -L/usr/include \ |
Jagger | e4df070 | 2016-09-11 19:19:34 +0200 | [diff] [blame] | 44 | -lpthread -lunwind-ptrace -lunwind-generic -lbfd -lopcodes -lrt |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 45 | ARCH_SRCS := $(wildcard linux/*.c) |
robert.swiecki@gmail.com | 3ad0bb3 | 2015-03-04 17:19:13 +0000 | [diff] [blame] | 46 | |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 47 | ifeq ("$(wildcard /usr/include/bfd.h)","") |
| 48 | WARN_LIBRARY += binutils-devel |
| 49 | endif |
| 50 | ifeq ("$(wildcard /usr/include/libunwind-ptrace.h)","") |
| 51 | WARN_LIBRARY += libunwind-devel/libunwind8-devel |
| 52 | endif |
Jagger | 9797ac5 | 2016-02-04 23:57:29 +0100 | [diff] [blame] | 53 | ifeq ("$(wildcard /usr/local/include/intel-pt.h)","/usr/local/include/intel-pt.h") |
| 54 | ARCH_CFLAGS += -D_HF_LINUX_INTEL_PT_LIB |
| 55 | ARCH_CFLAGS += -I/usr/local/include |
Jagger | 070b2c6 | 2016-02-05 06:01:15 +0100 | [diff] [blame] | 56 | ARCH_LDFLAGS += -L/usr/local/lib -lipt -Wl,--rpath=/usr/local/lib |
Jagger | 9797ac5 | 2016-02-04 23:57:29 +0100 | [diff] [blame] | 57 | endif |
Jagger | 919cf2b | 2016-09-07 20:43:33 +0200 | [diff] [blame] | 58 | ifeq ($(MARCH),$(filter $(MARCH),x86_64 i386)) |
| 59 | # Support for popcnt (used in libhfuzz) |
| 60 | ARCH_CFLAGS += -msse4.2 |
| 61 | endif |
Jagger | 9797ac5 | 2016-02-04 23:57:29 +0100 | [diff] [blame] | 62 | ifeq ("$(wildcard /usr/include/intel-pt.h)","/usr/include/intel-pt.h") |
| 63 | ARCH_CFLAGS += -D_HF_LINUX_INTEL_PT_LIB |
Jagger | 3594cda | 2016-02-08 00:05:47 +0100 | [diff] [blame] | 64 | ARCH_LDFLAGS += -lipt |
Jagger | 9797ac5 | 2016-02-04 23:57:29 +0100 | [diff] [blame] | 65 | endif |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 66 | ifdef WARN_LIBRARY |
| 67 | $(info ***************************************************************) |
| 68 | $(info Development libraries which are most likely missing on your OS:) |
| 69 | $(info $(WARN_LIBRARY)) |
| 70 | $(info ***************************************************************) |
| 71 | endif |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 72 | # OS Linux |
| 73 | else ifeq ($(OS),Darwin) |
| 74 | ARCH := DARWIN |
Aaron Carreras | bfd365f | 2016-10-16 09:22:19 -0400 | [diff] [blame] | 75 | |
| 76 | # Figure out which crash reporter to use. |
Anestis Bechtsoudis | 0e5c2c5 | 2015-10-08 13:30:03 -0700 | [diff] [blame] | 77 | CRASHWRANGLER := third_party/mac |
Aaron Carreras | 623f4eb | 2016-10-15 07:52:13 -0400 | [diff] [blame] | 78 | OS_VERSION := $(shell sw_vers -productVersion) |
Anestis Bechtsoudis | e3df591 | 2016-10-28 10:02:29 +0300 | [diff] [blame] | 79 | ifneq (,$(findstring 10.12,$(OS_VERSION))) |
| 80 | CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Yosemite.o |
Aaron Carreras | 623f4eb | 2016-10-15 07:52:13 -0400 | [diff] [blame] | 81 | else ifneq (,$(findstring 10.11,$(OS_VERSION))) |
| 82 | # El Capitan didn't break compatibility |
| 83 | CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Yosemite.o |
| 84 | else ifneq (,$(findstring 10.10,$(OS_VERSION))) |
| 85 | CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Yosemite.o |
| 86 | else ifneq (,$(findstring 10.9,$(OS_VERSION))) |
| 87 | CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Mavericks.o |
| 88 | else ifneq (,$(findstring 10.8,$(OS_VERSION))) |
| 89 | CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Mountain_Lion.o |
| 90 | else |
| 91 | $(error Unsupported MAC OS X version) |
| 92 | endif |
| 93 | |
Aaron Carreras | bfd365f | 2016-10-16 09:22:19 -0400 | [diff] [blame] | 94 | # Figure out which XCode SDK to use. |
| 95 | OSX_SDK_VERSION := $(shell xcrun --show-sdk-version) |
Anestis Bechtsoudis | b442502 | 2016-10-17 12:58:01 +0300 | [diff] [blame] | 96 | SDK_NAME :=macosx$(OSX_SDK_VERSION) |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 97 | SDK := $(shell xcrun --sdk $(SDK_NAME) --show-sdk-path 2>/dev/null) |
| 98 | ifeq (,$(findstring MacOSX.platform,$(SDK))) |
| 99 | XC_PATH := $(shell xcode-select -p) |
| 100 | $(error $(SDK_NAME) not found in $(XC_PATH)) |
| 101 | endif |
Aaron Carreras | bfd365f | 2016-10-16 09:22:19 -0400 | [diff] [blame] | 102 | |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 103 | CC := $(shell xcrun --sdk $(SDK_NAME) --find cc) |
| 104 | LD := $(shell xcrun --sdk $(SDK_NAME) --find cc) |
Robert Swiecki | 0a7ce04 | 2016-08-25 15:31:31 +0200 | [diff] [blame] | 105 | ARCH_CFLAGS := -arch x86_64 -std=c99 -isysroot $(SDK) -I. \ |
Robert Swiecki | a9db9dd | 2016-03-09 16:29:37 +0100 | [diff] [blame] | 106 | -x objective-c -pedantic -fblocks \ |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 107 | -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized \ |
| 108 | -Wreturn-type -Wpointer-arith -Wno-gnu-case-range -Wno-gnu-designator \ |
| 109 | -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-attributes |
| 110 | ARCH_LDFLAGS := -F/System/Library/PrivateFrameworks -framework CoreSymbolication -framework IOKit \ |
| 111 | -F$(SDK)/System/Library/Frameworks -F$(SDK)/System/Library/PrivateFrameworks \ |
| 112 | -framework Foundation -framework ApplicationServices -framework Symbolication \ |
| 113 | -framework CoreServices -framework CrashReporterSupport -framework CoreFoundation \ |
| 114 | -framework CommerceKit $(CRASH_REPORT) |
| 115 | MIG_RET := $(shell mig -header mac/mach_exc.h -user mac/mach_excUser.c -sheader mac/mach_excServer.h \ |
| 116 | -server mac/mach_excServer.c $(SDK)/usr/include/mach/mach_exc.defs &>/dev/null; echo $$?) |
| 117 | ifeq ($(MIG_RET),1) |
| 118 | $(error mig failed to generate RPC code) |
| 119 | endif |
| 120 | ARCH_SRCS := $(wildcard mac/*.c) |
| 121 | # OS Darwin |
tlogic@gmail.com | 479f0f9 | 2015-04-15 18:03:16 +0000 | [diff] [blame] | 122 | else |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 123 | ARCH := POSIX |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 124 | ARCH_SRCS := $(wildcard posix/*.c) |
Robert Swiecki | 94d54ff | 2016-09-06 14:38:21 +0200 | [diff] [blame] | 125 | ARCH_CFLAGS := -std=c11 -I/usr/local/include -I/usr/include \ |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 126 | -Wextra -Wno-initializer-overrides -Wno-override-init \ |
Robert Swiecki | ac310a8 | 2016-02-22 18:58:36 +0100 | [diff] [blame] | 127 | -Wno-unknown-warning-option -Wno-unknown-pragmas \ |
Robert Swiecki | 0a7ce04 | 2016-08-25 15:31:31 +0200 | [diff] [blame] | 128 | -U__STRICT_ANSI__ -funroll-loops |
Jagger | f159a15 | 2016-09-02 02:22:09 +0200 | [diff] [blame] | 129 | ARCH_LDFLAGS := -lpthread -L/usr/local/include -L/usr/include -lrt |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 130 | # OS Posix |
tlogic@gmail.com | 479f0f9 | 2015-04-15 18:03:16 +0000 | [diff] [blame] | 131 | endif |
robert.swiecki@gmail.com | b0cac5b | 2015-02-17 00:19:59 +0000 | [diff] [blame] | 132 | |
Jagger | 9856150 | 2016-03-10 00:01:08 +0100 | [diff] [blame] | 133 | COMPILER = $(shell $(CC) -v 2>&1 | grep -E '(gcc|clang) version' | grep -oE '(clang|gcc)') |
| 134 | ifeq ($(COMPILER),clang) |
| 135 | ARCH_CFLAGS += -fblocks |
| 136 | ARCH_LDFLAGS += -lBlocksRuntime |
| 137 | endif |
| 138 | |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 139 | SRCS := $(COMMON_SRCS) $(ARCH_SRCS) |
| 140 | OBJS := $(SRCS:.c=.o) |
Jagger | a72ac9d | 2016-04-01 23:48:12 +0200 | [diff] [blame] | 141 | |
Jagger | efeb4be | 2016-09-06 02:41:51 +0200 | [diff] [blame] | 142 | LIBS_SRCS := $(wildcard libhfuzz/*.c) |
Jagger | a72ac9d | 2016-04-01 23:48:12 +0200 | [diff] [blame] | 143 | LIBS_OBJS := $(LIBS_SRCS:.c=.o) |
Jagger | efeb4be | 2016-09-06 02:41:51 +0200 | [diff] [blame] | 144 | HFUZZ_ARCH := libhfuzz/libhfuzz.a |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 145 | |
| 146 | # Respect external user defines |
| 147 | CFLAGS += $(COMMON_CFLAGS) $(ARCH_CFLAGS) -D_HF_ARCH_${ARCH} |
| 148 | LDFLAGS += $(COMMON_LDFLAGS) $(ARCH_LDFLAGS) |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 149 | |
Anestis Bechtsoudis | 3485c73 | 2015-09-10 17:40:04 +0300 | [diff] [blame] | 150 | ifeq ($(DEBUG),true) |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 151 | CFLAGS += -g -ggdb |
Robert Swiecki | caf9d76 | 2016-03-10 16:13:18 +0100 | [diff] [blame] | 152 | LDFLAGS += -g -ggdb |
Anestis Bechtsoudis | 3485c73 | 2015-09-10 17:40:04 +0300 | [diff] [blame] | 153 | endif |
| 154 | |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 155 | # Control Android builds |
Anestis Bechtsoudis | 6a938ed | 2016-10-12 12:04:34 +0300 | [diff] [blame] | 156 | ANDROID_API ?= android-24 |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 157 | ANDROID_DEBUG_ENABLED ?= false |
Anestis Bechtsoudis | d1fccd5 | 2016-05-06 13:11:27 +0300 | [diff] [blame] | 158 | ANDROID_CLANG ?= false |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 159 | ANDROID_APP_ABI ?= armeabi-v7a |
Anestis Bechtsoudis | f5ded93 | 2016-10-18 10:50:00 +0300 | [diff] [blame] | 160 | ANDROID_SKIP_CLEAN ?= false |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 161 | NDK_BUILD_ARGS := |
Anestis Bechtsoudis | f5ded93 | 2016-10-18 10:50:00 +0300 | [diff] [blame] | 162 | |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 163 | ifeq ($(ANDROID_DEBUG_ENABLED),true) |
Anestis Bechtsoudis | f5ded93 | 2016-10-18 10:50:00 +0300 | [diff] [blame] | 164 | NDK_BUILD_ARGS += V=1 NDK_DEBUG=1 APP_OPTIM=debug |
| 165 | endif |
| 166 | |
| 167 | # By default ndk-build cleans all project files to ensure that no semi-completed |
| 168 | # builds reach the app package. The following flag disables this check. It's mainly |
| 169 | # purposed to be used with android-all rule where we want recursive invocations |
| 170 | # to keep previous targets' binaries. |
| 171 | ifeq ($(ANDROID_SKIP_CLEAN),true) |
| 172 | NDK_BUILD_ARGS += NDK_APP.local.cleaned_binaries=true |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 173 | endif |
| 174 | |
Anestis Bechtsoudis | d1fccd5 | 2016-05-06 13:11:27 +0300 | [diff] [blame] | 175 | ifeq ($(ANDROID_CLANG),true) |
Anestis Bechtsoudis | 6a938ed | 2016-10-12 12:04:34 +0300 | [diff] [blame] | 176 | # clang works only against APIs >= 23 |
| 177 | ifeq ($(ANDROID_APP_ABI),$(filter $(ANDROID_APP_ABI),armeabi armeabi-v7a)) |
Anestis Bechtsoudis | f017925 | 2016-09-06 12:11:05 +0300 | [diff] [blame] | 178 | ANDROID_NDK_TOOLCHAIN ?= arm-linux-androideabi-clang |
Anestis Bechtsoudis | b4446a8 | 2016-10-28 11:30:10 +0300 | [diff] [blame] | 179 | ANDROID_ARCH_CPU := arm |
Anestis Bechtsoudis | 6a938ed | 2016-10-12 12:04:34 +0300 | [diff] [blame] | 180 | else ifeq ($(ANDROID_APP_ABI),$(filter $(ANDROID_APP_ABI),x86)) |
Jagger | d18ba37 | 2016-09-04 19:03:46 +0200 | [diff] [blame] | 181 | ANDROID_NDK_TOOLCHAIN ?= x86-clang |
Anestis Bechtsoudis | b4446a8 | 2016-10-28 11:30:10 +0300 | [diff] [blame] | 182 | ANDROID_ARCH_CPU := x86 |
Anestis Bechtsoudis | 6a938ed | 2016-10-12 12:04:34 +0300 | [diff] [blame] | 183 | else ifeq ($(ANDROID_APP_ABI),$(filter $(ANDROID_APP_ABI),arm64-v8a)) |
Jagger | d18ba37 | 2016-09-04 19:03:46 +0200 | [diff] [blame] | 184 | ANDROID_NDK_TOOLCHAIN ?= aarch64-linux-android-clang |
Anestis Bechtsoudis | b4446a8 | 2016-10-28 11:30:10 +0300 | [diff] [blame] | 185 | ANDROID_ARCH_CPU := arm64 |
Anestis Bechtsoudis | 6a938ed | 2016-10-12 12:04:34 +0300 | [diff] [blame] | 186 | else ifeq ($(ANDROID_APP_ABI),$(filter $(ANDROID_APP_ABI),x86_64)) |
Jagger | d18ba37 | 2016-09-04 19:03:46 +0200 | [diff] [blame] | 187 | ANDROID_NDK_TOOLCHAIN ?= x86_64-clang |
Anestis Bechtsoudis | b4446a8 | 2016-10-28 11:30:10 +0300 | [diff] [blame] | 188 | ANDROID_ARCH_CPU := x86_64 |
Anestis Bechtsoudis | d1fccd5 | 2016-05-06 13:11:27 +0300 | [diff] [blame] | 189 | else |
| 190 | $(error Unsuported / Unknown APP_API '$(ANDROID_APP_ABI)') |
| 191 | endif |
| 192 | else |
Anestis Bechtsoudis | 6a938ed | 2016-10-12 12:04:34 +0300 | [diff] [blame] | 193 | ifeq ($(ANDROID_APP_ABI),$(filter $(ANDROID_APP_ABI),armeabi armeabi-v7a)) |
| 194 | ANDROID_NDK_TOOLCHAIN ?= arm-linux-androideabi-4.9 |
Anestis Bechtsoudis | b4446a8 | 2016-10-28 11:30:10 +0300 | [diff] [blame] | 195 | ANDROID_ARCH_CPU := arm |
Anestis Bechtsoudis | 6a938ed | 2016-10-12 12:04:34 +0300 | [diff] [blame] | 196 | else ifeq ($(ANDROID_APP_ABI),$(filter $(ANDROID_APP_ABI),x86)) |
| 197 | ANDROID_NDK_TOOLCHAIN ?= x86-4.9 |
Anestis Bechtsoudis | b4446a8 | 2016-10-28 11:30:10 +0300 | [diff] [blame] | 198 | ANDROID_ARCH_CPU := x86 |
Anestis Bechtsoudis | 6a938ed | 2016-10-12 12:04:34 +0300 | [diff] [blame] | 199 | else ifeq ($(ANDROID_APP_ABI),$(filter $(ANDROID_APP_ABI),arm64-v8a)) |
| 200 | ANDROID_NDK_TOOLCHAIN ?= aarch64-linux-android-4.9 |
Anestis Bechtsoudis | b4446a8 | 2016-10-28 11:30:10 +0300 | [diff] [blame] | 201 | ANDROID_ARCH_CPU := arm64 |
Anestis Bechtsoudis | 6a938ed | 2016-10-12 12:04:34 +0300 | [diff] [blame] | 202 | else ifeq ($(ANDROID_APP_ABI),$(filter $(ANDROID_APP_ABI),x86_64)) |
| 203 | ANDROID_NDK_TOOLCHAIN ?= x86_64-4.9 |
Anestis Bechtsoudis | b4446a8 | 2016-10-28 11:30:10 +0300 | [diff] [blame] | 204 | ANDROID_ARCH_CPU := x86_64 |
Anestis Bechtsoudis | 6a938ed | 2016-10-12 12:04:34 +0300 | [diff] [blame] | 205 | else |
| 206 | $(error Unsuported / Unknown APP_API '$(ANDROID_APP_ABI)') |
| 207 | endif |
Anestis Bechtsoudis | d1fccd5 | 2016-05-06 13:11:27 +0300 | [diff] [blame] | 208 | endif |
| 209 | |
Jagger | 3cf9796 | 2016-09-06 03:17:59 +0200 | [diff] [blame] | 210 | SUBDIR_ROOTS := linux mac posix libhfuzz |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 211 | DIRS := . $(shell find $(SUBDIR_ROOTS) -type d) |
| 212 | CLEAN_PATTERNS := *.o *~ core *.a *.dSYM *.la *.so *.dylib |
| 213 | SUBDIR_GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(CLEAN_PATTERNS))) |
| 214 | MAC_GARGBAGE := $(wildcard mac/mach_exc*) |
| 215 | ANDROID_GARBAGE := obj libs |
| 216 | |
Jagger | 9a135bb | 2016-08-21 21:37:06 +0200 | [diff] [blame] | 217 | all: $(BIN) $(HFUZZ_ARCH) |
robert.swiecki@gmail.com | f761052 | 2015-02-16 10:52:02 +0000 | [diff] [blame] | 218 | |
robert.swiecki | 661d83a | 2015-03-12 14:27:51 +0000 | [diff] [blame] | 219 | %.o: %.c |
robert.swiecki@gmail.com | 2a32b51 | 2015-03-10 16:06:43 +0000 | [diff] [blame] | 220 | $(CC) -c $(CFLAGS) -o $@ $< |
robert.swiecki@gmail.com | f761052 | 2015-02-16 10:52:02 +0000 | [diff] [blame] | 221 | |
robert.swiecki | 661d83a | 2015-03-12 14:27:51 +0000 | [diff] [blame] | 222 | %.so: %.c |
| 223 | $(CC) -fPIC -shared $(CFLAGS) -o $@ $< |
| 224 | |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 225 | %.dylib: %.c |
| 226 | $(CC) -fPIC -shared $(CFLAGS) -o $@ $< |
robert.swiecki@gmail.com | c5f5be6 | 2015-02-15 17:17:21 +0000 | [diff] [blame] | 227 | |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 228 | $(BIN): $(OBJS) |
| 229 | $(LD) -o $(BIN) $(OBJS) $(LDFLAGS) |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 230 | |
Jagger | c0dce05 | 2016-09-11 15:46:39 +0200 | [diff] [blame] | 231 | $(LIBS_OBJS): $(LIBS_SRCS) |
Jagger | 418d350 | 2016-09-12 15:17:14 +0200 | [diff] [blame] | 232 | $(CC) -c -fPIC -fno-builtin $(CFLAGS) -fno-stack-protector -o $@ $(@:.o=.c) |
Jagger | c0dce05 | 2016-09-11 15:46:39 +0200 | [diff] [blame] | 233 | |
Jagger | 9a135bb | 2016-08-21 21:37:06 +0200 | [diff] [blame] | 234 | $(HFUZZ_ARCH): $(LIBS_OBJS) |
| 235 | $(AR) rcs $(HFUZZ_ARCH) $(LIBS_OBJS) |
| 236 | |
Robert Swiecki | 1cd09ae | 2016-02-10 15:56:48 +0100 | [diff] [blame] | 237 | .PHONY: clean |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 238 | clean: |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 239 | $(RM) -r core $(OBJS) $(BIN) $(MAC_GARGBAGE) $(ANDROID_GARBAGE) $(SUBDIR_GARBAGE) |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 240 | |
Robert Swiecki | 1cd09ae | 2016-02-10 15:56:48 +0100 | [diff] [blame] | 241 | .PHONY: indent |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 242 | indent: |
Jagger | 400fd8f | 2015-08-16 10:50:55 +0200 | [diff] [blame] | 243 | indent -linux -l100 -lc100 -nut -i4 *.c *.h */*.c */*.h; rm -f *~ */*~ |
robert.swiecki@gmail.com | cc050fd | 2015-02-02 20:00:42 +0000 | [diff] [blame] | 244 | |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 245 | .PHONY: depend |
robert.swiecki@gmail.com | cc050fd | 2015-02-02 20:00:42 +0000 | [diff] [blame] | 246 | depend: |
Jagger | 59c0d0e | 2016-09-11 15:56:47 +0200 | [diff] [blame] | 247 | makedepend -Y. -Y* -- *.c */*.c |
Anestis Bechtsoudis | 057c99f | 2015-09-24 14:39:57 +0300 | [diff] [blame] | 248 | |
| 249 | .PHONY: android |
Anestis Bechtsoudis | c1f6faa | 2015-07-31 05:32:19 +0300 | [diff] [blame] | 250 | android: |
Anestis Bechtsoudis | b4446a8 | 2016-10-28 11:30:10 +0300 | [diff] [blame] | 251 | @ANDROID_API=$(ANDROID_API) third_party/android/scripts/compile-libunwind.sh \ |
| 252 | third_party/android/libunwind $(ANDROID_ARCH_CPU) |
| 253 | |
| 254 | @ANDROID_API=$(ANDROID_API) third_party/android/scripts/compile-capstone.sh \ |
| 255 | third_party/android/capstone $(ANDROID_ARCH_CPU) |
| 256 | |
| 257 | ifeq ($(ANDROID_CLANG),true) |
| 258 | @ANDROID_API=$(ANDROID_API) third_party/android/scripts/compile-libBlocksRuntime.sh \ |
| 259 | third_party/android/libBlocksRuntime $(ANDROID_ARCH_CPU) |
| 260 | endif |
| 261 | |
Anestis Bechtsoudis | 3b5bd87 | 2015-09-13 10:58:30 +0300 | [diff] [blame] | 262 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./android/Android.mk \ |
Anestis Bechtsoudis | f5ded93 | 2016-10-18 10:50:00 +0300 | [diff] [blame] | 263 | APP_PLATFORM=$(ANDROID_API) APP_ABI=$(ANDROID_APP_ABI) \ |
| 264 | NDK_TOOLCHAIN=$(ANDROID_NDK_TOOLCHAIN) $(NDK_BUILD_ARGS) |
| 265 | |
| 266 | # Loop all ABIs and pass-through flags since visibility is lost due to sub-process |
| 267 | .PHONY: android-all |
| 268 | android-all: |
| 269 | @echo "Cleaning workspace:" |
| 270 | $(MAKE) clean |
| 271 | @echo "" |
| 272 | |
| 273 | @for abi in armeabi armeabi-v7a arm64-v8a x86 x86_64; do \ |
| 274 | ANDROID_APP_ABI=$$abi ANDROID_SKIP_CLEAN=true ANDROID_CLANG=$(ANDROID_CLANG) \ |
| 275 | ANDROID_API=$(ANDROID_API) ANDROID_DEBUG_ENABLED=$(ANDROID_DEBUG_ENABLED) \ |
| 276 | $(MAKE) android || { \ |
| 277 | echo "Recursive make failed"; exit 1; }; \ |
| 278 | echo ""; \ |
| 279 | done |
Anestis Bechtsoudis | b42f3e0 | 2015-08-17 08:57:42 +0300 | [diff] [blame] | 280 | |
Anestis Bechtsoudis | 6257b61 | 2016-10-28 11:30:43 +0300 | [diff] [blame] | 281 | .PHONY: android-clean-deps |
| 282 | android-clean-deps: |
| 283 | @for cpu in arm arm64 x86 x86_64; do \ |
| 284 | make -C "third_party/android/capstone" clean; \ |
| 285 | rm -rf "third_party/android/capstone/$$cpu"; \ |
| 286 | make -C "third_party/android/libunwind" clean; \ |
| 287 | rm -rf "third_party/android/libunwind/$$cpu"; \ |
| 288 | ndk-build -C "third_party/android/libBlocksRuntime" \ |
| 289 | NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk clean; \ |
| 290 | rm -rf "third_party/android/libBlocksRuntime/$$cpu"; \ |
| 291 | done |
| 292 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 293 | # DO NOT DELETE |
robert.swiecki@gmail.com | cc050fd | 2015-02-02 20:00:42 +0000 | [diff] [blame] | 294 | |
Robert Swiecki | 8b76934 | 2016-01-21 16:35:48 +0100 | [diff] [blame] | 295 | cmdline.o: cmdline.h common.h log.h files.h util.h |
Robert Swiecki | 81c6a0d | 2015-09-08 15:43:20 +0200 | [diff] [blame] | 296 | display.o: common.h display.h log.h util.h |
Robert Swiecki | 8ca2822 | 2016-03-15 20:35:44 +0100 | [diff] [blame] | 297 | files.o: common.h files.h log.h util.h |
Jagger | 08816fd | 2016-03-11 01:32:38 +0100 | [diff] [blame] | 298 | fuzz.o: common.h fuzz.h arch.h files.h log.h mangle.h report.h sancov.h |
Jagger | c8b6eda | 2016-09-01 03:52:35 +0200 | [diff] [blame] | 299 | fuzz.o: subproc.h util.h |
Jagger | 59c0d0e | 2016-09-11 15:56:47 +0200 | [diff] [blame] | 300 | honggfuzz.o: common.h cmdline.h display.h log.h files.h fuzz.h util.h |
Jagger | c8b6eda | 2016-09-01 03:52:35 +0200 | [diff] [blame] | 301 | log.o: common.h log.h util.h |
Jagger | 400fd8f | 2015-08-16 10:50:55 +0200 | [diff] [blame] | 302 | mangle.o: common.h mangle.h log.h util.h |
Jagger | 3db1d95 | 2016-03-10 02:02:46 +0100 | [diff] [blame] | 303 | report.o: common.h report.h log.h util.h |
Jagger | 733849b | 2016-03-10 03:19:04 +0100 | [diff] [blame] | 304 | sancov.o: common.h sancov.h files.h log.h util.h |
Jagger | 2ed5b73 | 2016-09-04 17:45:59 +0200 | [diff] [blame] | 305 | subproc.o: common.h subproc.h arch.h files.h log.h sancov.h util.h |
Jagger | c8b6eda | 2016-09-01 03:52:35 +0200 | [diff] [blame] | 306 | util.o: common.h util.h files.h log.h |
Jagger | 561b979 | 2016-09-12 15:14:37 +0200 | [diff] [blame] | 307 | libhfuzz/instrument.o: common.h util.h |
| 308 | libhfuzz/memorycmp.o: libhfuzz/instrument.h |
Jagger | 59c0d0e | 2016-09-11 15:56:47 +0200 | [diff] [blame] | 309 | libhfuzz/persistent.o: common.h |
Jagger | e631ee8 | 2016-09-11 15:55:34 +0200 | [diff] [blame] | 310 | linux/arch.o: common.h arch.h common.h files.h linux/perf.h |
| 311 | linux/arch.o: linux/ptrace_utils.h log.h sancov.h subproc.h util.h |
Robert Swiecki | e8f8e8d | 2016-10-03 23:51:32 +0200 | [diff] [blame] | 312 | linux/bfd.o: common.h linux/bfd.h linux/unwind.h files.h common.h log.h |
Jagger | 59c0d0e | 2016-09-11 15:56:47 +0200 | [diff] [blame] | 313 | linux/bfd.o: util.h |
Robert Swiecki | e8f8e8d | 2016-10-03 23:51:32 +0200 | [diff] [blame] | 314 | linux/perf.o: common.h linux/perf.h files.h common.h log.h util.h linux/pt.h |
Jagger | 59c0d0e | 2016-09-11 15:56:47 +0200 | [diff] [blame] | 315 | linux/pt.o: common.h linux/pt.h log.h common.h util.h |
Robert Swiecki | e8f8e8d | 2016-10-03 23:51:32 +0200 | [diff] [blame] | 316 | linux/ptrace_utils.o: common.h linux/ptrace_utils.h files.h common.h log.h |
Jagger | 59c0d0e | 2016-09-11 15:56:47 +0200 | [diff] [blame] | 317 | linux/ptrace_utils.o: sancov.h subproc.h util.h linux/bfd.h linux/unwind.h |
| 318 | linux/unwind.o: common.h linux/unwind.h log.h common.h |
| 319 | mac/arch.o: common.h arch.h files.h log.h sancov.h subproc.h util.h |
| 320 | posix/arch.o: common.h arch.h common.h files.h log.h sancov.h subproc.h |
| 321 | posix/arch.o: util.h |