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. |
| 19 | |
| 20 | |
robert.swiecki@gmail.com | 8118eb6 | 2015-02-20 12:01:41 +0000 | [diff] [blame] | 21 | CC ?= gcc |
robert.swiecki@gmail.com | 2a32b51 | 2015-03-10 16:06:43 +0000 | [diff] [blame] | 22 | CFLAGS += -std=c11 -I. -I/usr/local/include -I/usr/include \ |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 23 | -D_GNU_SOURCE \ |
robert.swiecki@gmail.com | 15eca6f | 2015-03-04 03:31:36 +0000 | [diff] [blame] | 24 | -Wall -Wextra -Wno-initializer-overrides -Wno-override-init -Wno-unknown-warning-option -Werror \ |
| 25 | -funroll-loops -O2 |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 26 | |
robert.swiecki@gmail.com | 8118eb6 | 2015-02-20 12:01:41 +0000 | [diff] [blame] | 27 | LD = $(CC) |
robert.swiecki@gmail.com | 882900b | 2015-02-11 13:56:22 +0000 | [diff] [blame] | 28 | LDFLAGS += -lm -lpthread -L/usr/local/include -L/usr/include |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 29 | |
Jagger | 0764ad7 | 2015-09-06 01:11:08 +0200 | [diff] [blame] | 30 | SRCS = honggfuzz.c display.c log.c files.c fuzz.c report.c mangle.c util.c |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 31 | |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 32 | OBJS = $(SRCS:.c=.o) |
| 33 | BIN = honggfuzz |
| 34 | |
robert.swiecki@gmail.com | 448d281 | 2015-02-02 20:57:13 +0000 | [diff] [blame] | 35 | OS ?= $(shell uname -s) |
robert.swiecki@gmail.com | 15eca6f | 2015-03-04 03:31:36 +0000 | [diff] [blame] | 36 | MARCH ?= $(shell uname -m) |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 37 | |
robert.swiecki@gmail.com | a0d8714 | 2015-02-14 13:11:18 +0000 | [diff] [blame] | 38 | ARCH_SRCS := $(wildcard posix/*.c) |
robert.swiecki@gmail.com | b0cac5b | 2015-02-17 00:19:59 +0000 | [diff] [blame] | 39 | ARCH = POSIX |
Tommy Murphy | fe390bd | 2015-06-11 22:44:26 -0400 | [diff] [blame] | 40 | SDK = |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 41 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 42 | ifeq ($(OS),Linux) |
robert.swiecki@gmail.com | 3ad0bb3 | 2015-03-04 17:19:13 +0000 | [diff] [blame] | 43 | ARCH = LINUX |
| 44 | CFLAGS += -D_FILE_OFFSET_BITS=64 |
robert.swiecki@gmail.com | 1111d13 | 2015-03-12 01:32:26 +0000 | [diff] [blame] | 45 | LDFLAGS += -lunwind-ptrace -lunwind-generic -lbfd -lopcodes -lrt |
robert.swiecki@gmail.com | 3ad0bb3 | 2015-03-04 17:19:13 +0000 | [diff] [blame] | 46 | ARCH_SRCS := $(wildcard linux/*.c) |
| 47 | |
robert.swiecki@gmail.com | c5f5be6 | 2015-02-15 17:17:21 +0000 | [diff] [blame] | 48 | ifeq ("$(wildcard /usr/include/bfd.h)","") |
robert.swiecki | 62a5e92 | 2015-03-11 17:13:07 +0000 | [diff] [blame] | 49 | WARN_LIBRARY += "binutils-devel " |
robert.swiecki@gmail.com | c5f5be6 | 2015-02-15 17:17:21 +0000 | [diff] [blame] | 50 | endif |
| 51 | ifeq ("$(wildcard /usr/include/libunwind-ptrace.h)","") |
robert.swiecki | 62a5e92 | 2015-03-11 17:13:07 +0000 | [diff] [blame] | 52 | WARN_LIBRARY += "libunwind-devel/libunwind8-devel " |
robert.swiecki@gmail.com | f8440e0 | 2015-02-03 14:44:35 +0000 | [diff] [blame] | 53 | endif |
robert.swiecki@gmail.com | 15eca6f | 2015-03-04 03:31:36 +0000 | [diff] [blame] | 54 | |
robert.swiecki@gmail.com | 3ad0bb3 | 2015-03-04 17:19:13 +0000 | [diff] [blame] | 55 | ifeq ($(MARCH),x86_64) |
| 56 | # Support for popcnt (used in linux/perf.c) |
| 57 | CFLAGS += -msse4.2 |
| 58 | endif # MARCH |
| 59 | ifeq ($(MARCH),i386) |
| 60 | # Support for popcnt (used in linux/perf.c) |
| 61 | CFLAGS += -msse4.2 |
| 62 | endif # MARCH |
Anestis Bechtsoudis | c1f6faa | 2015-07-31 05:32:19 +0300 | [diff] [blame] | 63 | endif # OS Linux |
robert.swiecki@gmail.com | 15eca6f | 2015-03-04 03:31:36 +0000 | [diff] [blame] | 64 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 65 | ifeq ($(OS),Darwin) |
tlogic@gmail.com | 479f0f9 | 2015-04-15 18:03:16 +0000 | [diff] [blame] | 66 | OS_VERSION = $(shell sw_vers -productVersion) |
| 67 | ifneq (,$(findstring 10.10,$(OS_VERSION))) |
| 68 | SDK_NAME = "macosx10.10" |
| 69 | CRASH_REPORT = third_party/CrashReport_Yosemite.o |
| 70 | else ifneq (,$(findstring 10.9,$(OS_VERSION))) |
| 71 | SDK_NAME = "macosx10.9" |
| 72 | CRASH_REPORT = third_party/CrashReport_Mavericks.o |
| 73 | else ifneq (,$(findstring 10.8,$(OS_VERSION))) |
| 74 | SDK_NAME = "macosx10.8" |
| 75 | CRASH_REPORT = third_party/CrashReport_Mountain_Lion.o |
| 76 | else |
| 77 | SDK_NAME = "macosx" |
Tommy Murphy | fe390bd | 2015-06-11 22:44:26 -0400 | [diff] [blame] | 78 | CRASH_REPORT = |
tlogic@gmail.com | 479f0f9 | 2015-04-15 18:03:16 +0000 | [diff] [blame] | 79 | endif |
| 80 | CC = $(shell xcrun --sdk $(SDK_NAME) --find cc) |
| 81 | SDK = $(shell xcrun --sdk $(SDK_NAME) --show-sdk-path) |
Tommy Murphy | fe390bd | 2015-06-11 22:44:26 -0400 | [diff] [blame] | 82 | CFLAGS = -arch x86_64 -O3 -g -ggdb -std=c99 -isysroot $(SDK) -I. \ |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 83 | -x objective-c \ |
| 84 | -D_GNU_SOURCE \ |
| 85 | -pedantic \ |
tlogic@gmail.com | 479f0f9 | 2015-04-15 18:03:16 +0000 | [diff] [blame] | 86 | -Wall -Werror -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized \ |
| 87 | -Wreturn-type -Wpointer-arith -Wno-gnu-case-range -Wno-gnu-designator \ |
| 88 | -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-attributes |
| 89 | LD = $(shell xcrun --sdk $(SDK_NAME) --find cc) |
robert.swiecki@gmail.com | 65fa911 | 2015-02-02 20:55:36 +0000 | [diff] [blame] | 90 | LDFLAGS = -F/System/Library/PrivateFrameworks -framework CoreSymbolication -framework IOKit \ |
tlogic@gmail.com | 479f0f9 | 2015-04-15 18:03:16 +0000 | [diff] [blame] | 91 | -F$(SDK)/System/Library/Frameworks -F$(SDK)/System/Library/PrivateFrameworks \ |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 92 | -framework Foundation -framework ApplicationServices -framework Symbolication \ |
| 93 | -framework CoreServices -framework CrashReporterSupport -framework CoreFoundation \ |
Tommy Murphy | fe390bd | 2015-06-11 22:44:26 -0400 | [diff] [blame] | 94 | -framework CommerceKit -lm |
robert.swiecki@gmail.com | a0d8714 | 2015-02-14 13:11:18 +0000 | [diff] [blame] | 95 | ARCH_SRCS = $(wildcard mac/*.c) |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 96 | MIG_OUTPUT = mach_exc.h mach_excUser.c mach_excServer.h mach_excServer.c |
| 97 | MIG_OBJECTS = mach_excUser.o mach_excServer.o |
robert.swiecki@gmail.com | b0cac5b | 2015-02-17 00:19:59 +0000 | [diff] [blame] | 98 | ARCH = DARWIN |
Anestis Bechtsoudis | c1f6faa | 2015-07-31 05:32:19 +0300 | [diff] [blame] | 99 | endif # OS Darwin |
robert.swiecki@gmail.com | b0cac5b | 2015-02-17 00:19:59 +0000 | [diff] [blame] | 100 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 101 | SRCS += $(ARCH_SRCS) |
robert.swiecki | 5fa9d90 | 2015-02-25 15:31:56 +0000 | [diff] [blame] | 102 | CFLAGS += -D_HF_ARCH_${ARCH} |
robert.swiecki | 661d83a | 2015-03-12 14:27:51 +0000 | [diff] [blame] | 103 | INTERCEPTOR_SRCS = $(wildcard interceptor/*.c) |
| 104 | INTERCEPTOR_LIBS = $(INTERCEPTOR_SRCS:.c=.so) |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 105 | |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 106 | # Control Android builds |
| 107 | ANDROID_DEBUG_ENABLED ?= false |
| 108 | ANDROID_APP_ABI ?= armeabi-v7a |
Anestis Bechtsoudis | 61a8f4f | 2015-08-20 08:39:26 +0300 | [diff] [blame] | 109 | ANDROID_API ?= android-21 |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 110 | NDK_BUILD_ARGS := |
| 111 | ifeq ($(ANDROID_DEBUG_ENABLED),true) |
| 112 | NDK_BUILD_ARGS += V=1 NDK_DEBUG=1 APP_OPTIM=debug |
| 113 | endif |
| 114 | |
robert.swiecki | 661d83a | 2015-03-12 14:27:51 +0000 | [diff] [blame] | 115 | all: warn_libs $(BIN) $(INTERCEPTOR_LIBS) |
robert.swiecki@gmail.com | f761052 | 2015-02-16 10:52:02 +0000 | [diff] [blame] | 116 | |
robert.swiecki | 661d83a | 2015-03-12 14:27:51 +0000 | [diff] [blame] | 117 | %.o: %.c |
robert.swiecki@gmail.com | 2a32b51 | 2015-03-10 16:06:43 +0000 | [diff] [blame] | 118 | $(CC) -c $(CFLAGS) -o $@ $< |
robert.swiecki@gmail.com | f761052 | 2015-02-16 10:52:02 +0000 | [diff] [blame] | 119 | |
robert.swiecki | 661d83a | 2015-03-12 14:27:51 +0000 | [diff] [blame] | 120 | %.so: %.c |
| 121 | $(CC) -fPIC -shared $(CFLAGS) -o $@ $< |
| 122 | |
robert.swiecki@gmail.com | c5f5be6 | 2015-02-15 17:17:21 +0000 | [diff] [blame] | 123 | warn_libs: |
| 124 | ifdef WARN_LIBRARY |
robert.swiecki@gmail.com | 66ee275 | 2015-02-16 20:49:44 +0000 | [diff] [blame] | 125 | @/bin/echo -e "*********************************************************" |
| 126 | @/bin/echo -e "Development libraries which are most likely missing on your OS:" |
| 127 | @/bin/echo "$(WARN_LIBRARY)" |
| 128 | @/bin/echo -e "*********************************************************" |
robert.swiecki@gmail.com | c5f5be6 | 2015-02-15 17:17:21 +0000 | [diff] [blame] | 129 | else |
robert.swiecki@gmail.com | c5f5be6 | 2015-02-15 17:17:21 +0000 | [diff] [blame] | 130 | endif |
| 131 | |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 132 | $(BIN): $(MIG_OBJECTS) $(OBJS) |
robert.swiecki@gmail.com | cc050fd | 2015-02-02 20:00:42 +0000 | [diff] [blame] | 133 | $(LD) -o $(BIN) $(OBJS) $(MIG_OBJECTS) $(CRASH_REPORT) $(LDFLAGS) |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 134 | |
tlogic@gmail.com | 479f0f9 | 2015-04-15 18:03:16 +0000 | [diff] [blame] | 135 | $(MIG_OUTPUT): $(SDK)/usr/include/mach/mach_exc.defs |
| 136 | mig -header mach_exc.h -user mach_excUser.c -sheader mach_excServer.h -server mach_excServer.c $(SDK)/usr/include/mach/mach_exc.defs |
groebert@google.com | 1bd4c21 | 2013-06-19 11:13:56 +0000 | [diff] [blame] | 137 | |
| 138 | $(MIG_OBJECTS): $(MIG_OUTPUT) |
robert.swiecki@gmail.com | 2a32b51 | 2015-03-10 16:06:43 +0000 | [diff] [blame] | 139 | $(CC) -c $(CFLAGS) mach_excUser.c |
| 140 | $(CC) -c $(CFLAGS) mach_excServer.c |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 141 | |
| 142 | clean: |
Anestis Bechtsoudis | c1f6faa | 2015-07-31 05:32:19 +0300 | [diff] [blame] | 143 | $(RM) -r core $(OBJS) $(BIN) $(MIG_OUTPUT) $(MIG_OBJECTS) $(INTERCEPTOR_LIBS) obj libs |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 144 | |
| 145 | indent: |
Jagger | 400fd8f | 2015-08-16 10:50:55 +0200 | [diff] [blame] | 146 | 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] | 147 | |
| 148 | depend: |
robert.swiecki@gmail.com | 42f2a3e | 2015-02-17 00:20:49 +0000 | [diff] [blame] | 149 | makedepend -Y. -Y* -- $(SRCS) |
Anestis Bechtsoudis | c1f6faa | 2015-07-31 05:32:19 +0300 | [diff] [blame] | 150 | |
| 151 | .PHONY:android |
| 152 | android: |
Anestis Bechtsoudis | b42f3e0 | 2015-08-17 08:57:42 +0300 | [diff] [blame] | 153 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./android/Android.mk \ |
Anestis Bechtsoudis | 61a8f4f | 2015-08-20 08:39:26 +0300 | [diff] [blame] | 154 | APP_PLATFORM=$(ANDROID_API) APP_ABI=$(ANDROID_APP_ABI) $(NDK_BUILD_ARGS) |
Anestis Bechtsoudis | b42f3e0 | 2015-08-17 08:57:42 +0300 | [diff] [blame] | 155 | |
robert.swiecki@gmail.com | cc050fd | 2015-02-02 20:00:42 +0000 | [diff] [blame] | 156 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 157 | # DO NOT DELETE |
robert.swiecki@gmail.com | cc050fd | 2015-02-02 20:00:42 +0000 | [diff] [blame] | 158 | |
| 159 | honggfuzz.o: common.h log.h files.h fuzz.h util.h |
Robert Swiecki | 81c6a0d | 2015-09-08 15:43:20 +0200 | [diff] [blame] | 160 | display.o: common.h display.h log.h util.h |
Jagger | 400fd8f | 2015-08-16 10:50:55 +0200 | [diff] [blame] | 161 | log.o: common.h log.h util.h |
robert.swiecki@gmail.com | cc050fd | 2015-02-02 20:00:42 +0000 | [diff] [blame] | 162 | files.o: common.h files.h log.h |
Jagger | 92316ea | 2015-09-06 01:11:57 +0200 | [diff] [blame] | 163 | fuzz.o: common.h fuzz.h arch.h display.h files.h log.h mangle.h report.h |
| 164 | fuzz.o: util.h |
robert.swiecki@gmail.com | 42f2a3e | 2015-02-17 00:20:49 +0000 | [diff] [blame] | 165 | report.o: common.h report.h log.h util.h |
Jagger | 400fd8f | 2015-08-16 10:50:55 +0200 | [diff] [blame] | 166 | mangle.o: common.h mangle.h log.h util.h |
| 167 | util.o: common.h files.h log.h |
Jagger | 3a78aca | 2015-08-23 12:59:53 +0200 | [diff] [blame] | 168 | linux/ptrace_utils.o: common.h linux/ptrace_utils.h files.h linux/bfd.h |
| 169 | linux/ptrace_utils.o: linux/unwind.h log.h util.h |
Jagger | e0296ec | 2015-09-09 23:36:27 +0200 | [diff] [blame] | 170 | linux/perf.o: common.h linux/perf.h log.h util.h |
| 171 | linux/bfd.o: common.h linux/bfd.h files.h log.h util.h |
robert.swiecki@gmail.com | 42f2a3e | 2015-02-17 00:20:49 +0000 | [diff] [blame] | 172 | linux/unwind.o: common.h linux/unwind.h log.h |
Jagger | e0296ec | 2015-09-09 23:36:27 +0200 | [diff] [blame] | 173 | linux/arch.o: common.h arch.h linux/perf.h linux/ptrace_utils.h log.h util.h |