forked from yugr/libdebugme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
75 lines (60 loc) · 2.02 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright 2016-2017 Yury Gribov
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE.txt file.
CC = gcc
CPPFLAGS = -Iinclude
CFLAGS = -fPIC -g -fvisibility=hidden -Wall -Wextra -Werror
LDFLAGS = -fPIC -shared -Wl,--no-allow-shlib-undefined
ifeq (,$(DEBUG))
CFLAGS += -O2
LDFLAGS += -Wl,-O2
else
CFLAGS += -O0
endif
ifneq (,$(ASAN))
CFLAGS += -fsanitize=address
LDFLAGS += -Wl,--allow-shlib-undefined -fsanitize=address
endif
ifneq (,$(UBSAN))
CFLAGS += -fsanitize=undefined
LDFLAGS += -fsanitize=undefined
endif
DESTDIR = /usr
OBJS = bin/gdb.o bin/debugme.o bin/init.o bin/common.o
$(shell mkdir -p bin)
all: bin/libdebugme.so
install:
install -D bin/libdebugme.so $(DESTDIR)/lib
DEBUGME_OPTIONS = handle_signals=1:quiet=1:altstack=1:debug_opts=-quiet -batch -ex backtrace
check:
$(CC) $(CPPFLAGS) test/segv.c -o bin/a.out
if DEBUGME_OPTIONS='$(DEBUGME_OPTIONS)' LD_PRELOAD=bin/libdebugme.so bin/a.out; then false; fi
$(CC) $(CPPFLAGS) test/segv.c -Wl,--no-as-needed bin/libdebugme.so -o bin/a.out
if DEBUGME_OPTIONS='$(DEBUGME_OPTIONS)' LD_LIBRARY_PATH=bin bin/a.out; then false; fi
bin/libdebugme.so: $(OBJS) bin/FLAGS Makefile
$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
bin/%.o: src/%.c Makefile bin/FLAGS
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
bin/FLAGS: FORCE
if test x"$(CFLAGS) $(LDFLAGS)" != x"$$(cat $@)"; then \
echo "$(CFLAGS) $(LDFLAGS)" > $@; \
fi
help:
@echo "Common targets:"
@echo " all Build all executables and scripts"
@echo " clean Clean all build files and temps."
@echo " help Print help on build options."
@echo ' install Install to $$DESTDIR (default is /usr).'
@echo ""
@echo "Less common:"
@echo " check Run regtests."
@echo ""
@echo "Build options:"
@echo " DESTDIR=path Specify installation root."
@echo " DEBUG=1 Build debug version of code."
@echo " ASAN=1 Build with ASan checks."
@echo " UBSAN=1 Build with UBSan checks."
clean:
rm -f bin/*
.PHONY: clean all install check FORCE help