blob: 4af53ddb01a53caf85ff975fa1307d1950eace48 [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
groebert@google.com1bd4c212013-06-19 11:13:56 +000028
robert.swiecki@gmail.com448d2812015-02-02 20:57:13 +000029OS ?= $(shell uname -s)
robert.swiecki@gmail.com15eca6f2015-03-04 03:31:36 +000030MARCH ?= $(shell uname -m)
groebert@google.com1bd4c212013-06-19 11:13:56 +000031
robert.swiecki3bb518c2010-10-14 00:48:24 +000032ifeq ($(OS),Linux)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030033 ARCH := LINUX
Robert Swieckiac310a82016-02-22 18:58:36 +010034
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030035 ARCH_CFLAGS := -std=c11 -I. -I/usr/local/include -I/usr/include \
36 -Wextra -Wno-initializer-overrides -Wno-override-init \
Robert Swieckia9db9dd2016-03-09 16:29:37 +010037 -Wno-unknown-warning-option -funroll-loops -O3 \
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030038 -D_FILE_OFFSET_BITS=64
Jagger2e06f562016-02-11 09:32:39 +010039 ARCH_LDFLAGS := -L/usr/local/include -L/usr/include \
Jagger2e06f562016-02-11 09:32:39 +010040 -lpthread -lunwind-ptrace -lunwind-generic -lbfd -lopcodes -lrt
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030041 ARCH_SRCS := $(wildcard linux/*.c)
robert.swiecki@gmail.com3ad0bb32015-03-04 17:19:13 +000042
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030043 ifeq ("$(wildcard /usr/include/bfd.h)","")
44 WARN_LIBRARY += binutils-devel
45 endif
46 ifeq ("$(wildcard /usr/include/libunwind-ptrace.h)","")
47 WARN_LIBRARY += libunwind-devel/libunwind8-devel
48 endif
Jagger9797ac52016-02-04 23:57:29 +010049 ifeq ("$(wildcard /usr/local/include/intel-pt.h)","/usr/local/include/intel-pt.h")
50 ARCH_CFLAGS += -D_HF_LINUX_INTEL_PT_LIB
51 ARCH_CFLAGS += -I/usr/local/include
Jagger070b2c62016-02-05 06:01:15 +010052 ARCH_LDFLAGS += -L/usr/local/lib -lipt -Wl,--rpath=/usr/local/lib
Jagger9797ac52016-02-04 23:57:29 +010053 endif
54 ifeq ("$(wildcard /usr/include/intel-pt.h)","/usr/include/intel-pt.h")
55 ARCH_CFLAGS += -D_HF_LINUX_INTEL_PT_LIB
Jagger3594cda2016-02-08 00:05:47 +010056 ARCH_LDFLAGS += -lipt
Jagger9797ac52016-02-04 23:57:29 +010057 endif
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030058 ifdef WARN_LIBRARY
59 $(info ***************************************************************)
60 $(info Development libraries which are most likely missing on your OS:)
61 $(info $(WARN_LIBRARY))
62 $(info ***************************************************************)
63 endif
robert.swiecki@gmail.com15eca6f2015-03-04 03:31:36 +000064
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030065 ifeq ($(MARCH),$(filter $(MARCH),x86_64 i386))
66 # Support for popcnt (used in linux/perf.c)
67 ARCH_CFLAGS += -msse4.2
68 endif # MARCH
69 # OS Linux
70else ifeq ($(OS),Darwin)
71 ARCH := DARWIN
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070072 CRASHWRANGLER := third_party/mac
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030073 OS_VERSION := $(shell sw_vers -productVersion)
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070074 ifneq (,$(findstring 10.11,$(OS_VERSION)))
Robert Swiecki1cd09ae2016-02-10 15:56:48 +010075 # El Capitan didn't break compatibility
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070076 SDK_NAME := "macosx10.11"
77 CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Yosemite.o
78 else ifneq (,$(findstring 10.10,$(OS_VERSION)))
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030079 SDK_NAME := "macosx10.10"
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070080 CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Yosemite.o
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030081 else ifneq (,$(findstring 10.9,$(OS_VERSION)))
82 SDK_NAME := "macosx10.9"
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070083 CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Mavericks.o
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030084 else ifneq (,$(findstring 10.8,$(OS_VERSION)))
85 SDK_NAME := "macosx10.8"
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070086 CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Mountain_Lion.o
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030087 else
Anestis Bechtsoudis0e5c2c52015-10-08 13:30:03 -070088 $(error Unsupported MAC OS X version)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030089 endif
90 SDK := $(shell xcrun --sdk $(SDK_NAME) --show-sdk-path 2>/dev/null)
91 ifeq (,$(findstring MacOSX.platform,$(SDK)))
92 XC_PATH := $(shell xcode-select -p)
93 $(error $(SDK_NAME) not found in $(XC_PATH))
94 endif
95 CC := $(shell xcrun --sdk $(SDK_NAME) --find cc)
96 LD := $(shell xcrun --sdk $(SDK_NAME) --find cc)
97 ARCH_CFLAGS := -arch x86_64 -O3 -std=c99 -isysroot $(SDK) -I. \
Robert Swieckia9db9dd2016-03-09 16:29:37 +010098 -x objective-c -pedantic -fblocks \
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +030099 -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized \
100 -Wreturn-type -Wpointer-arith -Wno-gnu-case-range -Wno-gnu-designator \
101 -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-attributes
102 ARCH_LDFLAGS := -F/System/Library/PrivateFrameworks -framework CoreSymbolication -framework IOKit \
103 -F$(SDK)/System/Library/Frameworks -F$(SDK)/System/Library/PrivateFrameworks \
104 -framework Foundation -framework ApplicationServices -framework Symbolication \
105 -framework CoreServices -framework CrashReporterSupport -framework CoreFoundation \
106 -framework CommerceKit $(CRASH_REPORT)
107 MIG_RET := $(shell mig -header mac/mach_exc.h -user mac/mach_excUser.c -sheader mac/mach_excServer.h \
108 -server mac/mach_excServer.c $(SDK)/usr/include/mach/mach_exc.defs &>/dev/null; echo $$?)
109 ifeq ($(MIG_RET),1)
110 $(error mig failed to generate RPC code)
111 endif
112 ARCH_SRCS := $(wildcard mac/*.c)
113 # OS Darwin
tlogic@gmail.com479f0f92015-04-15 18:03:16 +0000114else
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300115 ARCH := POSIX
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300116 ARCH_SRCS := $(wildcard posix/*.c)
Jagger2381ef42016-03-20 23:32:05 +0100117 ARCH_CFLAGS := -std=c11 -I. -I/usr/local/include -I/usr/include \
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300118 -Wextra -Wno-initializer-overrides -Wno-override-init \
Robert Swieckiac310a82016-02-22 18:58:36 +0100119 -Wno-unknown-warning-option -Wno-unknown-pragmas \
Jagger10a9ee22016-03-21 23:28:22 +0100120 -U__STRICT_ANSI__ -funroll-loops -O2
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300121 ARCH_LDFLAGS := -lpthread -L/usr/local/include -L/usr/include
122 # OS Posix
tlogic@gmail.com479f0f92015-04-15 18:03:16 +0000123endif
robert.swiecki@gmail.comb0cac5b2015-02-17 00:19:59 +0000124
Jagger98561502016-03-10 00:01:08 +0100125COMPILER = $(shell $(CC) -v 2>&1 | grep -E '(gcc|clang) version' | grep -oE '(clang|gcc)')
126ifeq ($(COMPILER),clang)
127 ARCH_CFLAGS += -fblocks
128 ARCH_LDFLAGS += -lBlocksRuntime
129endif
130
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300131SRCS := $(COMMON_SRCS) $(ARCH_SRCS)
132OBJS := $(SRCS:.c=.o)
Jaggera72ac9d2016-04-01 23:48:12 +0200133
Jagger065ff572016-04-01 23:49:33 +0200134LIBS_SRCS := $(wildcard libraries/*.c)
Jaggera72ac9d2016-04-01 23:48:12 +0200135LIBS_OBJS := $(LIBS_SRCS:.c=.o)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300136
137# Respect external user defines
138CFLAGS += $(COMMON_CFLAGS) $(ARCH_CFLAGS) -D_HF_ARCH_${ARCH}
139LDFLAGS += $(COMMON_LDFLAGS) $(ARCH_LDFLAGS)
robert.swiecki3bb518c2010-10-14 00:48:24 +0000140
Anestis Bechtsoudis3485c732015-09-10 17:40:04 +0300141ifeq ($(DEBUG),true)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300142 CFLAGS += -g -ggdb
Robert Swieckicaf9d762016-03-10 16:13:18 +0100143 LDFLAGS += -g -ggdb
Anestis Bechtsoudis3485c732015-09-10 17:40:04 +0300144endif
145
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300146# Control Android builds
147ANDROID_DEBUG_ENABLED ?= false
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300148ANDROID_CLANG ?= false
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300149ANDROID_APP_ABI ?= armeabi-v7a
150NDK_BUILD_ARGS :=
151ifeq ($(ANDROID_DEBUG_ENABLED),true)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300152 NDK_BUILD_ARGS += V=1 NDK_DEBUG=1 APP_OPTIM=debug
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300153endif
154
Anestis Bechtsoudisd1fccd52016-05-06 13:11:27 +0300155ifeq ($(ANDROID_CLANG),true)
156 # clang works only for APIs >= 23, so default to it if not set
157 ANDROID_API ?= android-23
158 ifeq ($(ANDROID_APP_ABI),armeabi-v7a)
159 ANDROID_NDK_TOOLCHAIN ?= arm-linux-androideabi-clang3.6
160 else ifeq ($(ANDROID_APP_ABI),x86)
161 ANDROID_NDK_TOOLCHAIN ?= x86-clang3.6
162 else ifeq ($(ANDROID_APP_ABI),arm64-v8a)
163 ANDROID_NDK_TOOLCHAIN ?= aarch64-linux-android-clang3.6
164 else ifeq ($(ANDROID_APP_ABI),x86_64)
165 ANDROID_NDK_TOOLCHAIN ?= x86_64-clang3.6
166 else
167 $(error Unsuported / Unknown APP_API '$(ANDROID_APP_ABI)')
168 endif
169else
170 ANDROID_API ?= android-21
171 ANDROID_NDK_TOOLCHAIN ?=
172endif
173
Jaggereafa0712016-04-02 00:01:06 +0200174SUBDIR_ROOTS := linux mac posix libraries
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300175DIRS := . $(shell find $(SUBDIR_ROOTS) -type d)
176CLEAN_PATTERNS := *.o *~ core *.a *.dSYM *.la *.so *.dylib
177SUBDIR_GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(CLEAN_PATTERNS)))
178MAC_GARGBAGE := $(wildcard mac/mach_exc*)
179ANDROID_GARBAGE := obj libs
180
Jaggera72ac9d2016-04-01 23:48:12 +0200181all: $(BIN) $(LIBS_OBJS)
robert.swiecki@gmail.comf7610522015-02-16 10:52:02 +0000182
robert.swiecki661d83a2015-03-12 14:27:51 +0000183%.o: %.c
robert.swiecki@gmail.com2a32b512015-03-10 16:06:43 +0000184 $(CC) -c $(CFLAGS) -o $@ $<
robert.swiecki@gmail.comf7610522015-02-16 10:52:02 +0000185
robert.swiecki661d83a2015-03-12 14:27:51 +0000186%.so: %.c
187 $(CC) -fPIC -shared $(CFLAGS) -o $@ $<
188
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300189%.dylib: %.c
190 $(CC) -fPIC -shared $(CFLAGS) -o $@ $<
robert.swiecki@gmail.comc5f5be62015-02-15 17:17:21 +0000191
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300192$(BIN): $(OBJS)
193 $(LD) -o $(BIN) $(OBJS) $(LDFLAGS)
groebert@google.com1bd4c212013-06-19 11:13:56 +0000194
Robert Swiecki1cd09ae2016-02-10 15:56:48 +0100195.PHONY: clean
robert.swiecki3bb518c2010-10-14 00:48:24 +0000196clean:
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300197 $(RM) -r core $(OBJS) $(BIN) $(MAC_GARGBAGE) $(ANDROID_GARBAGE) $(SUBDIR_GARBAGE)
robert.swiecki3bb518c2010-10-14 00:48:24 +0000198
Robert Swiecki1cd09ae2016-02-10 15:56:48 +0100199.PHONY: indent
robert.swiecki3bb518c2010-10-14 00:48:24 +0000200indent:
Jagger400fd8f2015-08-16 10:50:55 +0200201 indent -linux -l100 -lc100 -nut -i4 *.c *.h */*.c */*.h; rm -f *~ */*~
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000202
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300203.PHONY: depend
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000204depend:
robert.swiecki@gmail.com42f2a3e2015-02-17 00:20:49 +0000205 makedepend -Y. -Y* -- $(SRCS)
Anestis Bechtsoudis057c99f2015-09-24 14:39:57 +0300206
207.PHONY: android
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300208android:
Anestis Bechtsoudis3b5bd872015-09-13 10:58:30 +0300209 ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./android/Android.mk \
Anestis Bechtsoudis539dbc52015-12-26 20:11:46 +0200210 APP_PLATFORM=$(ANDROID_API) APP_ABI=$(ANDROID_APP_ABI) \
211 NDK_TOOLCHAIN=$(ANDROID_NDK_TOOLCHAIN) $(NDK_BUILD_ARGS)
Anestis Bechtsoudisb42f3e02015-08-17 08:57:42 +0300212
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000213
robert.swiecki3bb518c2010-10-14 00:48:24 +0000214# DO NOT DELETE
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000215
Jagger08816fd2016-03-11 01:32:38 +0100216honggfuzz.o: common.h cmdline.h display.h log.h files.h fuzz.h util.h
Robert Swiecki8b769342016-01-21 16:35:48 +0100217cmdline.o: cmdline.h common.h log.h files.h util.h
Robert Swiecki81c6a0d2015-09-08 15:43:20 +0200218display.o: common.h display.h log.h util.h
Robert Swiecki8ca28222016-03-15 20:35:44 +0100219files.o: common.h files.h log.h util.h
Jagger08816fd2016-03-11 01:32:38 +0100220fuzz.o: common.h fuzz.h arch.h files.h log.h mangle.h report.h sancov.h
221fuzz.o: util.h
Jagger03267342016-03-11 02:40:47 +0100222log.o: common.h log.h
Jagger400fd8f2015-08-16 10:50:55 +0200223mangle.o: common.h mangle.h log.h util.h
Jagger3db1d952016-03-10 02:02:46 +0100224report.o: common.h report.h log.h util.h
Jagger733849b2016-03-10 03:19:04 +0100225sancov.o: common.h sancov.h files.h log.h util.h
Jagger400fd8f2015-08-16 10:50:55 +0200226util.o: common.h files.h log.h
Jagger05cbaac2016-03-17 21:01:11 +0100227linux/arch.o: common.h arch.h linux/perf.h linux/ptrace_utils.h log.h
228linux/arch.o: sancov.h util.h files.h
Robert Swiecki2cb3de02016-03-24 14:43:56 +0100229linux/bfd.o: common.h linux/bfd.h linux/unwind.h files.h log.h util.h
230linux/perf.o: common.h linux/perf.h files.h linux/pt.h log.h util.h
231linux/pt.o: common.h linux/pt.h log.h
232linux/ptrace_utils.o: common.h linux/ptrace_utils.h files.h linux/bfd.h
233linux/ptrace_utils.o: linux/unwind.h linux/unwind.h log.h sancov.h util.h
234linux/unwind.o: common.h linux/unwind.h log.h