blob: ed99525707948fe4e8d7198998aa934045cc8c41 [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
robert.swiecki@gmail.com8118eb62015-02-20 12:01:41 +000021CC ?= gcc
robert.swiecki@gmail.com2a32b512015-03-10 16:06:43 +000022CFLAGS += -std=c11 -I. -I/usr/local/include -I/usr/include \
robert.swiecki3bb518c2010-10-14 00:48:24 +000023 -D_GNU_SOURCE \
robert.swiecki@gmail.com15eca6f2015-03-04 03:31:36 +000024 -Wall -Wextra -Wno-initializer-overrides -Wno-override-init -Wno-unknown-warning-option -Werror \
25 -funroll-loops -O2
robert.swiecki3bb518c2010-10-14 00:48:24 +000026
robert.swiecki@gmail.com8118eb62015-02-20 12:01:41 +000027LD = $(CC)
robert.swiecki@gmail.com882900b2015-02-11 13:56:22 +000028LDFLAGS += -lm -lpthread -L/usr/local/include -L/usr/include
robert.swiecki3bb518c2010-10-14 00:48:24 +000029
Jagger0764ad72015-09-06 01:11:08 +020030SRCS = honggfuzz.c display.c log.c files.c fuzz.c report.c mangle.c util.c
robert.swiecki3bb518c2010-10-14 00:48:24 +000031
groebert@google.com1bd4c212013-06-19 11:13:56 +000032OBJS = $(SRCS:.c=.o)
33BIN = honggfuzz
34
robert.swiecki@gmail.com448d2812015-02-02 20:57:13 +000035OS ?= $(shell uname -s)
robert.swiecki@gmail.com15eca6f2015-03-04 03:31:36 +000036MARCH ?= $(shell uname -m)
groebert@google.com1bd4c212013-06-19 11:13:56 +000037
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +000038ARCH_SRCS := $(wildcard posix/*.c)
robert.swiecki@gmail.comb0cac5b2015-02-17 00:19:59 +000039ARCH = POSIX
Tommy Murphyfe390bd2015-06-11 22:44:26 -040040SDK =
groebert@google.com1bd4c212013-06-19 11:13:56 +000041
robert.swiecki3bb518c2010-10-14 00:48:24 +000042ifeq ($(OS),Linux)
robert.swiecki@gmail.com3ad0bb32015-03-04 17:19:13 +000043 ARCH = LINUX
44 CFLAGS += -D_FILE_OFFSET_BITS=64
robert.swiecki@gmail.com1111d132015-03-12 01:32:26 +000045 LDFLAGS += -lunwind-ptrace -lunwind-generic -lbfd -lopcodes -lrt
robert.swiecki@gmail.com3ad0bb32015-03-04 17:19:13 +000046 ARCH_SRCS := $(wildcard linux/*.c)
47
robert.swiecki@gmail.comc5f5be62015-02-15 17:17:21 +000048 ifeq ("$(wildcard /usr/include/bfd.h)","")
robert.swiecki62a5e922015-03-11 17:13:07 +000049 WARN_LIBRARY += "binutils-devel "
robert.swiecki@gmail.comc5f5be62015-02-15 17:17:21 +000050 endif
51 ifeq ("$(wildcard /usr/include/libunwind-ptrace.h)","")
robert.swiecki62a5e922015-03-11 17:13:07 +000052 WARN_LIBRARY += "libunwind-devel/libunwind8-devel "
robert.swiecki@gmail.comf8440e02015-02-03 14:44:35 +000053 endif
robert.swiecki@gmail.com15eca6f2015-03-04 03:31:36 +000054
robert.swiecki@gmail.com3ad0bb32015-03-04 17:19:13 +000055 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 Bechtsoudisc1f6faa2015-07-31 05:32:19 +030063endif # OS Linux
robert.swiecki@gmail.com15eca6f2015-03-04 03:31:36 +000064
robert.swiecki3bb518c2010-10-14 00:48:24 +000065ifeq ($(OS),Darwin)
tlogic@gmail.com479f0f92015-04-15 18:03:16 +000066 OS_VERSION = $(shell sw_vers -productVersion)
67ifneq (,$(findstring 10.10,$(OS_VERSION)))
68 SDK_NAME = "macosx10.10"
69 CRASH_REPORT = third_party/CrashReport_Yosemite.o
70else ifneq (,$(findstring 10.9,$(OS_VERSION)))
71 SDK_NAME = "macosx10.9"
72 CRASH_REPORT = third_party/CrashReport_Mavericks.o
73else ifneq (,$(findstring 10.8,$(OS_VERSION)))
74 SDK_NAME = "macosx10.8"
75 CRASH_REPORT = third_party/CrashReport_Mountain_Lion.o
76else
77 SDK_NAME = "macosx"
Tommy Murphyfe390bd2015-06-11 22:44:26 -040078 CRASH_REPORT =
tlogic@gmail.com479f0f92015-04-15 18:03:16 +000079endif
80 CC = $(shell xcrun --sdk $(SDK_NAME) --find cc)
81 SDK = $(shell xcrun --sdk $(SDK_NAME) --show-sdk-path)
Tommy Murphyfe390bd2015-06-11 22:44:26 -040082 CFLAGS = -arch x86_64 -O3 -g -ggdb -std=c99 -isysroot $(SDK) -I. \
groebert@google.com1bd4c212013-06-19 11:13:56 +000083 -x objective-c \
84 -D_GNU_SOURCE \
85 -pedantic \
tlogic@gmail.com479f0f92015-04-15 18:03:16 +000086 -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.com65fa9112015-02-02 20:55:36 +000090 LDFLAGS = -F/System/Library/PrivateFrameworks -framework CoreSymbolication -framework IOKit \
tlogic@gmail.com479f0f92015-04-15 18:03:16 +000091 -F$(SDK)/System/Library/Frameworks -F$(SDK)/System/Library/PrivateFrameworks \
groebert@google.com1bd4c212013-06-19 11:13:56 +000092 -framework Foundation -framework ApplicationServices -framework Symbolication \
93 -framework CoreServices -framework CrashReporterSupport -framework CoreFoundation \
Tommy Murphyfe390bd2015-06-11 22:44:26 -040094 -framework CommerceKit -lm
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +000095 ARCH_SRCS = $(wildcard mac/*.c)
groebert@google.com1bd4c212013-06-19 11:13:56 +000096 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.comb0cac5b2015-02-17 00:19:59 +000098 ARCH = DARWIN
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +030099endif # OS Darwin
robert.swiecki@gmail.comb0cac5b2015-02-17 00:19:59 +0000100
robert.swiecki3bb518c2010-10-14 00:48:24 +0000101SRCS += $(ARCH_SRCS)
robert.swiecki5fa9d902015-02-25 15:31:56 +0000102CFLAGS += -D_HF_ARCH_${ARCH}
robert.swiecki661d83a2015-03-12 14:27:51 +0000103INTERCEPTOR_SRCS = $(wildcard interceptor/*.c)
104INTERCEPTOR_LIBS = $(INTERCEPTOR_SRCS:.c=.so)
robert.swiecki3bb518c2010-10-14 00:48:24 +0000105
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300106# Control Android builds
107ANDROID_DEBUG_ENABLED ?= false
108ANDROID_APP_ABI ?= armeabi-v7a
Anestis Bechtsoudis61a8f4f2015-08-20 08:39:26 +0300109ANDROID_API ?= android-21
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300110NDK_BUILD_ARGS :=
111ifeq ($(ANDROID_DEBUG_ENABLED),true)
112 NDK_BUILD_ARGS += V=1 NDK_DEBUG=1 APP_OPTIM=debug
113endif
114
robert.swiecki661d83a2015-03-12 14:27:51 +0000115all: warn_libs $(BIN) $(INTERCEPTOR_LIBS)
robert.swiecki@gmail.comf7610522015-02-16 10:52:02 +0000116
robert.swiecki661d83a2015-03-12 14:27:51 +0000117%.o: %.c
robert.swiecki@gmail.com2a32b512015-03-10 16:06:43 +0000118 $(CC) -c $(CFLAGS) -o $@ $<
robert.swiecki@gmail.comf7610522015-02-16 10:52:02 +0000119
robert.swiecki661d83a2015-03-12 14:27:51 +0000120%.so: %.c
121 $(CC) -fPIC -shared $(CFLAGS) -o $@ $<
122
robert.swiecki@gmail.comc5f5be62015-02-15 17:17:21 +0000123warn_libs:
124ifdef WARN_LIBRARY
robert.swiecki@gmail.com66ee2752015-02-16 20:49:44 +0000125 @/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.comc5f5be62015-02-15 17:17:21 +0000129else
robert.swiecki@gmail.comc5f5be62015-02-15 17:17:21 +0000130endif
131
groebert@google.com1bd4c212013-06-19 11:13:56 +0000132$(BIN): $(MIG_OBJECTS) $(OBJS)
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000133 $(LD) -o $(BIN) $(OBJS) $(MIG_OBJECTS) $(CRASH_REPORT) $(LDFLAGS)
groebert@google.com1bd4c212013-06-19 11:13:56 +0000134
tlogic@gmail.com479f0f92015-04-15 18:03:16 +0000135$(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.com1bd4c212013-06-19 11:13:56 +0000137
138$(MIG_OBJECTS): $(MIG_OUTPUT)
robert.swiecki@gmail.com2a32b512015-03-10 16:06:43 +0000139 $(CC) -c $(CFLAGS) mach_excUser.c
140 $(CC) -c $(CFLAGS) mach_excServer.c
robert.swiecki3bb518c2010-10-14 00:48:24 +0000141
142clean:
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300143 $(RM) -r core $(OBJS) $(BIN) $(MIG_OUTPUT) $(MIG_OBJECTS) $(INTERCEPTOR_LIBS) obj libs
robert.swiecki3bb518c2010-10-14 00:48:24 +0000144
145indent:
Jagger400fd8f2015-08-16 10:50:55 +0200146 indent -linux -l100 -lc100 -nut -i4 *.c *.h */*.c */*.h; rm -f *~ */*~
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000147
148depend:
robert.swiecki@gmail.com42f2a3e2015-02-17 00:20:49 +0000149 makedepend -Y. -Y* -- $(SRCS)
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300150
151.PHONY:android
152android:
Anestis Bechtsoudisb42f3e02015-08-17 08:57:42 +0300153 ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./android/Android.mk \
Anestis Bechtsoudis61a8f4f2015-08-20 08:39:26 +0300154 APP_PLATFORM=$(ANDROID_API) APP_ABI=$(ANDROID_APP_ABI) $(NDK_BUILD_ARGS)
Anestis Bechtsoudisb42f3e02015-08-17 08:57:42 +0300155
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000156
robert.swiecki3bb518c2010-10-14 00:48:24 +0000157# DO NOT DELETE
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000158
159honggfuzz.o: common.h log.h files.h fuzz.h util.h
Robert Swiecki81c6a0d2015-09-08 15:43:20 +0200160display.o: common.h display.h log.h util.h
Jagger400fd8f2015-08-16 10:50:55 +0200161log.o: common.h log.h util.h
robert.swiecki@gmail.comcc050fd2015-02-02 20:00:42 +0000162files.o: common.h files.h log.h
Jagger92316ea2015-09-06 01:11:57 +0200163fuzz.o: common.h fuzz.h arch.h display.h files.h log.h mangle.h report.h
164fuzz.o: util.h
robert.swiecki@gmail.com42f2a3e2015-02-17 00:20:49 +0000165report.o: common.h report.h log.h util.h
Jagger400fd8f2015-08-16 10:50:55 +0200166mangle.o: common.h mangle.h log.h util.h
167util.o: common.h files.h log.h
Jagger3a78aca2015-08-23 12:59:53 +0200168linux/ptrace_utils.o: common.h linux/ptrace_utils.h files.h linux/bfd.h
169linux/ptrace_utils.o: linux/unwind.h log.h util.h
Jaggere0296ec2015-09-09 23:36:27 +0200170linux/perf.o: common.h linux/perf.h log.h util.h
171linux/bfd.o: common.h linux/bfd.h files.h log.h util.h
robert.swiecki@gmail.com42f2a3e2015-02-17 00:20:49 +0000172linux/unwind.o: common.h linux/unwind.h log.h
Jaggere0296ec2015-09-09 23:36:27 +0200173linux/arch.o: common.h arch.h linux/perf.h linux/ptrace_utils.h log.h util.h