2018-09-20 09:43:24 +08:00
|
|
|
T := $(CURDIR)
|
|
|
|
OUT_DIR ?= $(shell mkdir -p $(T)/build;cd $(T)/build;pwd)
|
|
|
|
CC ?= gcc
|
2018-05-15 09:09:20 +08:00
|
|
|
|
2019-01-11 19:27:50 +08:00
|
|
|
TRACE_CFLAGS := -g -O0 -std=gnu11
|
|
|
|
TRACE_CFLAGS += -D_GNU_SOURCE
|
|
|
|
TRACE_CFLAGS += -DNO_OPENSSL
|
|
|
|
TRACE_CFLAGS += -m64
|
|
|
|
TRACE_CFLAGS += -Wall -ffunction-sections
|
|
|
|
TRACE_CFLAGS += -Werror
|
2018-10-23 15:02:24 +08:00
|
|
|
TRACE_CFLAGS += -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
|
2019-01-11 19:27:50 +08:00
|
|
|
TRACE_CFLAGS += -Wformat -Wformat-security -fno-strict-aliasing
|
|
|
|
TRACE_CFLAGS += -fpie -fpic
|
|
|
|
TRACE_CFLAGS += $(CFLAGS)
|
2018-09-20 09:43:24 +08:00
|
|
|
|
|
|
|
GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
|
|
|
|
GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)
|
|
|
|
|
|
|
|
#enable stack overflow check
|
|
|
|
STACK_PROTECTOR := 1
|
|
|
|
|
|
|
|
ifdef STACK_PROTECTOR
|
|
|
|
ifeq (true, $(shell [ $(GCC_MAJOR) -gt 4 ] && echo true))
|
2019-01-11 19:27:50 +08:00
|
|
|
TRACE_CFLAGS += -fstack-protector-strong
|
2018-09-20 09:43:24 +08:00
|
|
|
else
|
|
|
|
ifeq (true, $(shell [ $(GCC_MAJOR) -eq 4 ] && [ $(GCC_MINOR) -ge 9 ] && echo true))
|
2019-01-11 19:27:50 +08:00
|
|
|
TRACE_CFLAGS += -fstack-protector-strong
|
2018-09-20 09:43:24 +08:00
|
|
|
else
|
2019-01-11 19:27:50 +08:00
|
|
|
TRACE_CFLAGS += -fstack-protector
|
2018-09-20 09:43:24 +08:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2019-01-11 19:27:50 +08:00
|
|
|
TRACE_LDFLAGS := -Wl,-z,noexecstack
|
|
|
|
TRACE_LDFLAGS += -Wl,-z,relro,-z,now
|
|
|
|
TRACE_LDFLAGS += -pie
|
|
|
|
TRACE_LDFLAGS += $(LDFLAGS)
|
2018-05-15 09:09:20 +08:00
|
|
|
|
2018-03-29 13:46:06 +08:00
|
|
|
all:
|
2019-01-11 19:27:50 +08:00
|
|
|
$(CC) -o $(OUT_DIR)/acrntrace acrntrace.c sbuf.c -I. -lpthread -lrt $(TRACE_CFLAGS) $(TRACE_LDFLAGS)
|
2018-03-29 13:46:06 +08:00
|
|
|
|
|
|
|
clean:
|
2018-06-04 15:57:25 +08:00
|
|
|
rm -f $(OUT_DIR)/acrntrace
|
2018-09-20 09:43:24 +08:00
|
|
|
ifneq ($(OUT_DIR),.)
|
|
|
|
rm -rf $(OUT_DIR)
|
|
|
|
endif
|
2018-05-17 03:21:45 +08:00
|
|
|
|
|
|
|
install: $(OUT_DIR)/acrntrace
|
|
|
|
install -d $(DESTDIR)/usr/bin
|
|
|
|
install -t $(DESTDIR)/usr/bin $(OUT_DIR)/acrntrace
|