blob: 1e5f05d4fa78d9984b09a4173f2e786f3b7b2129 [file] [log] [blame]
robert.swiecki3bb518c2010-10-14 00:48:24 +00001# honggfuzz - Makefile
2# -----------------------------------------
3#
4# Author: Robert Swiecki <swiecki@google.com>
5#
robert.swiecki@gmail.comba85c3e2015-02-02 14:55:16 +00006# Copyright 2010-2015 by Google Inc. All Rights Reserved.
robert.swiecki3bb518c2010-10-14 00:48:24 +00007#
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.
19
20
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030021# Common for all architectures
Robert Swieckia9db9dd2016-03-09 16:29:37 +010022CC ?= gcc
23LD = $(CC)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030024BIN := honggfuzz
Robert Swieckifc35c5e2016-03-09 17:18:48 +010025COMMON_CFLAGS := -D_GNU_SOURCE -Wall -Werror -Wframe-larger-than=131072
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030026COMMON_LDFLAGS := -lm
Robert Swiecki0e673882016-03-31 18:50:29 +020027COMMON_SRCS := honggfuzz.c cmdline.c display.c files.c fuzz.c log.c mangle.c report.c sancov.c subproc.c util.c
Jaggera443b692016-08-29 23:01:15 +020028CFLAGS ?= -O3
29LDFLAGS ?=
groebert@google.com1bd4c212013-06-19 11:13:56 +000030
robert.swiecki@gmail.com448d2812015-02-02 20:57:13 +000031OS ?= $(shell uname -s)
robert.swiecki@gmail.com15eca6f2015-03-04 03:31:36 +000032MARCH ?= $(shell uname -m)
groebert@google.com1bd4c212013-06-19 11:13:56 +000033
robert.swiecki3bb518c2010-10-14 00:48:24 +000034ifeq ($(OS),Linux)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030035 ARCH := LINUX
Robert Swieckiac310a82016-02-22 18:58:36 +010036
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030037 ARCH_CFLAGS := -std=c11 -I. -I/usr/local/include -I/usr/include \
38 -Wextra -Wno-initializer-overrides -Wno-override-init \
Robert Swiecki0a7ce042016-08-25 15:31:31 +020039 -Wno-unknown-warning-option -funroll-loops \
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030040 -D_FILE_OFFSET_BITS=64
Jagger2e06f562016-02-11 09:32:39 +010041 ARCH_LDFLAGS := -L/usr/local/include -L/usr/include \
Jagger2e06f562016-02-11 09:32:39 +010042 -lpthread -lunwind-ptrace -lunwind-generic -lbfd -lopcodes -lrt
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030043 ARCH_SRCS := $(wildcard linux/*.c)
robert.swiecki@gmail.com3ad0bb32015-03-04 17:19:13 +000044
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030045 ifeq ("$(wildcard /usr/include/bfd.h)","")
46 WARN_LIBRARY += binutils-devel
47 endif
48 ifeq ("$(wildcard /usr/include/libunwind-ptrace.h)","")
49 WARN_LIBRARY += libunwind-devel/libunwind8-devel
50 endif
Jagger9797ac52016-02-04 23:57:29 +010051 ifeq ("$(wildcard /usr/local/include/intel-pt.h)","/usr/local/include/intel-pt.h")
52 ARCH_CFLAGS += -D_HF_LINUX_INTEL_PT_LIB
53 ARCH_CFLAGS += -I/usr/local/include
Jagger070b2c62016-02-05 06:01:15 +010054 ARCH_LDFLAGS += -L/usr/local/lib -lipt -Wl,--rpath=/usr/local/lib
Jagger9797ac52016-02-04 23:57:29 +010055 endif
56 ifeq ("$(wildcard /usr/include/intel-pt.h)","/usr/include/intel-pt.h")
57 ARCH_CFLAGS += -D_HF_LINUX_INTEL_PT_LIB
Jagger3594cda2016-02-08 00:05:47 +010058 ARCH_LDFLAGS += -lipt
Jagger9797ac52016-02-04 23:57:29 +010059 endif
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030060 ifdef WARN_LIBRARY
61 $(info ***************************************************************)
62 $(info Development libraries which are most likely missing on your OS:)
63 $(info $(WARN_LIBRARY))
64 $(info ***************************************************************)
65 endif
robert.swiecki@gmail.com15eca6f2015-03-04 03:31:36 +000066
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030067 ifeq ($(MARCH),$(filter $(MARCH),x86_64 i386))
68 # Support for popcnt (used in linux/perf.c)
69 ARCH_CFLAGS += -msse4.2
70 endif # MARCH
71 # OS Linux
72else ifeq ($(OS),Darwin)
73 ARCH := DARWIN
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070074 CRASHWRANGLER := third_party/mac
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030075 OS_VERSION := $(shell sw_vers -productVersion)
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070076 ifneq (,$(findstring 10.11,$(OS_VERSION)))
Robert Swiecki1cd09ae2016-02-10 15:56:48 +010077 # El Capitan didn't break compatibility
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070078 SDK_NAME := "macosx10.11"
79 CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Yosemite.o
80 else ifneq (,$(findstring 10.10,$(OS_VERSION)))
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030081 SDK_NAME := "macosx10.10"
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070082 CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Yosemite.o
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030083 else ifneq (,$(findstring 10.9,$(OS_VERSION)))
84 SDK_NAME := "macosx10.9"
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070085 CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Mavericks.o
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030086 else ifneq (,$(findstring 10.8,$(OS_VERSION)))
87 SDK_NAME := "macosx10.8"
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070088 CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Mountain_Lion.o
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030089 else
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070090 $(error Unsupported MAC OS X version)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030091 endif
92 SDK := $(shell xcrun --sdk $(SDK_NAME) --show-sdk-path 2>/dev/null)
93 ifeq (,$(findstring MacOSX.platform,$(SDK)))
94 XC_PATH := $(shell xcode-select -p)
95 $(error $(SDK_NAME) not found in $(XC_PATH))
96 endif
97 CC := $(shell xcrun --sdk $(SDK_NAME) --find cc)
98 LD := $(shell xcrun --sdk $(SDK_NAME) --find cc)
Robert Swiecki0a7ce042016-08-25 15:31:31 +020099 ARCH_CFLAGS := -arch x86_64 -std=c99 -isysroot $(SDK) -I. \
Robert Swieckia9db9dd2016-03-09 16:29:37 +0100100 -x objective-c -pedantic -fblocks \
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300101 -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized \
102 -Wreturn-type -Wpointer-arith -Wno-gnu-case-range -Wno-gnu-designator \
103 -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-attributes
104 ARCH_LDFLAGS := -F/System/Library/PrivateFrameworks -framework CoreSymbolication -framework IOKit \
105 -F$(SDK)/System/Library/Frameworks -F$(SDK)/System/Library/PrivateFrameworks \
106 -framework Foundation -framework ApplicationServices -framework Symbolication \
107 -framework CoreServices -framework CrashReporterSupport -framework CoreFoundation \
108 -framework CommerceKit $(CRASH_REPORT)
109 MIG_RET := $(shell mig -header mac/mach_exc.h -user mac/mach_excUser.c -sheader mac/mach_excServer.h \
110 -server mac/mach_excServer.c $(SDK)/usr/include/mach/mach_exc.defs &>/dev/null; echo $$?)
111 ifeq ($(MIG_RET),1)
112 $(error mig failed to generate RPC code)
113 endif
114 ARCH_SRCS := $(wildcard mac/*.c)
115 # OS Darwin
tlogic@gmail.com479f0f92015-04-15 18:03:16 +0000116else
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300117 ARCH := POSIX
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300118 ARCH_SRCS := $(wildcard posix/*.c)
Jagger2381ef42016-03-20 23:32:05 +0100119 ARCH_CFLAGS := -std=c11 -I. -I/usr/local/include -I/usr/include \
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300120 -Wextra -Wno-initializer-overrides -Wno-override-init \
Robert Swieckiac310a82016-02-22 18:58:36 +0100121 -Wno-unknown-warning-option -Wno-unknown-pragmas \
Robert Swiecki0a7ce042016-08-25 15:31:31 +0200122 -U__STRICT_ANSI__ -funroll-loops
Jaggerf159a152016-09-02 02:22:09 +0200123 ARCH_LDFLAGS := -lpthread -L/usr/local/include -L/usr/include -lrt
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300124 # OS Posix
tlogic@gmail.com479f0f92015-04-15 18:03:16 +0000125endif
robert.swiecki@gmail.comb0cac5b2015-02-17 00:19:59 +0000126
Jagger98561502016-03-10 00:01:08 +0100127COMPILER = $(shell $(CC) -v 2>&1 | grep -E '(gcc|clang) version' | grep -oE '(clang|gcc)')
128ifeq ($(COMPILER),clang)
129 ARCH_CFLAGS += -fblocks
130 ARCH_LDFLAGS += -lBlocksRuntime
131endif
132
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300133SRCS := $(COMMON_SRCS) $(ARCH_SRCS)
134OBJS := $(SRCS:.c=.o)
Jaggera72ac9d2016-04-01 23:48:12 +0200135
Jaggerefeb4be2016-09-06 02:41:51 +0200136LIBS_SRCS := $(wildcard libhfuzz/*.c)
Jaggera72ac9d2016-04-01 23:48:12 +0200137LIBS_OBJS := $(LIBS_SRCS:.c=.o)
Jaggerefeb4be2016-09-06 02:41:51 +0200138HFUZZ_ARCH := libhfuzz/libhfuzz.a
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300139
140# Respect external user defines
141CFLAGS += $(COMMON_CFLAGS) $(ARCH_CFLAGS) -D_HF_ARCH_${ARCH}
142LDFLAGS += $(COMMON_LDFLAGS) $(ARCH_LDFLAGS)
robert.swiecki3bb518c2010-10-14 00:48:24 +0000143
Anestis Bechtsoudis3485c732015-09-10 17:40:04 +0300144ifeq ($(DEBUG),true)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300145 CFLAGS += -g -ggdb
Robert Swieckicaf9d762016-03-10 16:13:18 +0100146 LDFLAGS += -g -ggdb
Anestis Bechtsoudis3485c732015-09-10 17:40:04 +0300147endif
148
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300149# Control Android builds
150ANDROID_DEBUG_ENABLED ?= false
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300151ANDROID_CLANG ?= false
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300152ANDROID_APP_ABI ?= armeabi-v7a
153NDK_BUILD_ARGS :=
154ifeq ($(ANDROID_DEBUG_ENABLED),true)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300155 NDK_BUILD_ARGS += V=1 NDK_DEBUG=1 APP_OPTIM=debug
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300156endif
157
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300158ifeq ($(ANDROID_CLANG),true)
159 # clang works only for APIs >= 23, so default to it if not set
Jaggerd18ba372016-09-04 19:03:46 +0200160 ANDROID_API ?= android-24
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300161 ifeq ($(ANDROID_APP_ABI),armeabi-v7a)
Jaggerd18ba372016-09-04 19:03:46 +0200162 ANDROID_NDK_TOOLCHAIN ?= arm-linux-androideabi-4.9
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300163 else ifeq ($(ANDROID_APP_ABI),x86)
Jaggerd18ba372016-09-04 19:03:46 +0200164 ANDROID_NDK_TOOLCHAIN ?= x86-clang
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300165 else ifeq ($(ANDROID_APP_ABI),arm64-v8a)
Jaggerd18ba372016-09-04 19:03:46 +0200166 ANDROID_NDK_TOOLCHAIN ?= aarch64-linux-android-clang
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300167 else ifeq ($(ANDROID_APP_ABI),x86_64)
Jaggerd18ba372016-09-04 19:03:46 +0200168 ANDROID_NDK_TOOLCHAIN ?= x86_64-clang
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300169 else
170 $(error Unsuported / Unknown APP_API '$(ANDROID_APP_ABI)')
171 endif
172else
Jaggerd18ba372016-09-04 19:03:46 +0200173 ANDROID_API ?= android-24
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300174 ANDROID_NDK_TOOLCHAIN ?=
175endif
176
Jagger22f23952016-09-04 17:43:47 +0200177SUBDIR_ROOTS := linux mac posix lib
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300178DIRS := . $(shell find $(SUBDIR_ROOTS) -type d)
179CLEAN_PATTERNS := *.o *~ core *.a *.dSYM *.la *.so *.dylib
180SUBDIR_GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(CLEAN_PATTERNS)))
181MAC_GARGBAGE := $(wildcard mac/mach_exc*)
182ANDROID_GARBAGE := obj libs
183
Jagger9a135bb2016-08-21 21:37:06 +0200184all: $(BIN) $(HFUZZ_ARCH)
robert.swiecki@gmail.comf7610522015-02-16 10:52:02 +0000185
robert.swiecki661d83a2015-03-12 14:27:51 +0000186%.o: %.c
robert.swiecki@gmail.com2a32b512015-03-10 16:06:43 +0000187 $(CC) -c $(CFLAGS) -o $@ $<
robert.swiecki@gmail.comf7610522015-02-16 10:52:02 +0000188
robert.swiecki661d83a2015-03-12 14:27:51 +0000189%.so: %.c
190 $(CC) -fPIC -shared $(CFLAGS) -o $@ $<
191
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300192%.dylib: %.c
193 $(CC) -fPIC -shared $(CFLAGS) -o $@ $<
robert.swiecki@gmail.comc5f5be62015-02-15 17:17:21 +0000194
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300195$(BIN): $(OBJS)
196 $(LD) -o $(BIN) $(OBJS) $(LDFLAGS)
groebert@google.com1bd4c212013-06-19 11:13:56 +0000197
Jagger9a135bb2016-08-21 21:37:06 +0200198$(HFUZZ_ARCH): $(LIBS_OBJS)
199 $(AR) rcs $(HFUZZ_ARCH) $(LIBS_OBJS)
200
Robert Swiecki1cd09ae2016-02-10 15:56:48 +0100201.PHONY: clean
robert.swiecki3bb518c2010-10-14 00:48:24 +0000202clean:
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300203 $(RM) -r core $(OBJS) $(BIN) $(MAC_GARGBAGE) $(ANDROID_GARBAGE) $(SUBDIR_GARBAGE)
robert.swiecki3bb518c2010-10-14 00:48:24 +0000204
Robert Swiecki1cd09ae2016-02-10 15:56:48 +0100205.PHONY: indent
robert.swiecki3bb518c2010-10-14 00:48:24 +0000206indent:
Jagger400fd8f2015-08-16 10:50:55 +0200207 indent -linux -l100 -lc100 -nut -i4 *.c *.h */*.c */*.h; rm -f *~ */*~
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000208
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300209.PHONY: depend
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000210depend:
robert.swiecki@gmail.com42f2a3e2015-02-17 00:20:49 +0000211 makedepend -Y. -Y* -- $(SRCS)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300212
213.PHONY: android
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300214android:
Anestis Bechtsoudis3b5bd872015-09-13 10:58:30 +0300215 ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./android/Android.mk \
Anestis Bechtsoudis539dbc52015-12-26 20:11:46 +0200216 APP_PLATFORM=$(ANDROID_API) APP_ABI=$(ANDROID_APP_ABI) \
217 NDK_TOOLCHAIN=$(ANDROID_NDK_TOOLCHAIN) $(NDK_BUILD_ARGS)
Anestis Bechtsoudisb42f3e02015-08-17 08:57:42 +0300218
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000219
robert.swiecki3bb518c2010-10-14 00:48:24 +0000220# DO NOT DELETE
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000221
Jagger08816fd2016-03-11 01:32:38 +0100222honggfuzz.o: common.h cmdline.h display.h log.h files.h fuzz.h util.h
Robert Swiecki8b769342016-01-21 16:35:48 +0100223cmdline.o: cmdline.h common.h log.h files.h util.h
Robert Swiecki81c6a0d2015-09-08 15:43:20 +0200224display.o: common.h display.h log.h util.h
Robert Swiecki8ca28222016-03-15 20:35:44 +0100225files.o: common.h files.h log.h util.h
Jagger08816fd2016-03-11 01:32:38 +0100226fuzz.o: common.h fuzz.h arch.h files.h log.h mangle.h report.h sancov.h
Jaggerc8b6eda2016-09-01 03:52:35 +0200227fuzz.o: subproc.h util.h
228log.o: common.h log.h util.h
Jagger400fd8f2015-08-16 10:50:55 +0200229mangle.o: common.h mangle.h log.h util.h
Jagger3db1d952016-03-10 02:02:46 +0100230report.o: common.h report.h log.h util.h
Jagger733849b2016-03-10 03:19:04 +0100231sancov.o: common.h sancov.h files.h log.h util.h
Jagger2ed5b732016-09-04 17:45:59 +0200232subproc.o: common.h subproc.h arch.h files.h log.h sancov.h util.h
Jaggerc8b6eda2016-09-01 03:52:35 +0200233util.o: common.h util.h files.h log.h
Robert Swiecki2cb3de02016-03-24 14:43:56 +0100234linux/ptrace_utils.o: common.h linux/ptrace_utils.h files.h linux/bfd.h
Jaggerc8b6eda2016-09-01 03:52:35 +0200235linux/ptrace_utils.o: linux/unwind.h linux/unwind.h log.h sancov.h subproc.h
236linux/ptrace_utils.o: util.h
Jagger3e4abcc2016-07-18 20:41:00 +0200237linux/perf.o: common.h linux/perf.h files.h linux/pt.h log.h util.h
238linux/bfd.o: common.h linux/bfd.h linux/unwind.h files.h log.h util.h
Jaggerc8b6eda2016-09-01 03:52:35 +0200239linux/pt.o: common.h linux/pt.h log.h util.h
Robert Swiecki2cb3de02016-03-24 14:43:56 +0100240linux/unwind.o: common.h linux/unwind.h log.h
Jagger3e4abcc2016-07-18 20:41:00 +0200241linux/arch.o: common.h arch.h files.h linux/perf.h linux/ptrace_utils.h log.h
242linux/arch.o: sancov.h subproc.h util.h