1include ../../../paths.make 2 3T := $(CURDIR) 4OUT_DIR ?= $(shell mkdir -p $(T)/build;cd $(T)/build;pwd) 5CC ?= gcc 6 7LOG_CFLAGS := -g -O0 -std=gnu11 8LOG_CFLAGS += -D_GNU_SOURCE 9LOG_CFLAGS += -DNO_OPENSSL 10LOG_CFLAGS += -m64 11LOG_CFLAGS += -Wall -ffunction-sections 12LOG_CFLAGS += -Werror 13LOG_CFLAGS += -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 14LOG_CFLAGS += -Wformat -Wformat-security -fno-strict-aliasing 15LOG_CFLAGS += -fpie -fpic 16LOG_CFLAGS += $(CFLAGS) 17 18GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1) 19GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1) 20 21#enable stack overflow check 22STACK_PROTECTOR := 1 23 24ifdef STACK_PROTECTOR 25ifeq (true, $(shell [ $(GCC_MAJOR) -gt 4 ] && echo true)) 26LOG_CFLAGS += -fstack-protector-strong 27else 28ifeq (true, $(shell [ $(GCC_MAJOR) -eq 4 ] && [ $(GCC_MINOR) -ge 9 ] && echo true)) 29LOG_CFLAGS += -fstack-protector-strong 30else 31LOG_CFLAGS += -fstack-protector 32endif 33endif 34endif 35 36LOG_LDFLAGS := -Wl,-z,noexecstack 37LOG_LDFLAGS += -Wl,-z,relro,-z,now 38LOG_LDFLAGS += -pie 39LOG_LDFLAGS += $(LDFLAGS) 40 41all: 42 $(CC) -g acrnlog.c -o $(OUT_DIR)/acrnlog -lpthread $(LOG_CFLAGS) $(LOG_LDFLAGS) 43 cp acrnlog.service $(OUT_DIR)/acrnlog.service 44 45clean: 46 rm -f $(OUT_DIR)/acrnlog 47ifneq ($(OUT_DIR),.) 48 rm -f $(OUT_DIR)/acrnlog.service 49 rm -rf $(OUT_DIR) 50endif 51 52install: $(OUT_DIR)/acrnlog 53 install -d $(DESTDIR)$(bindir) 54 install -t $(DESTDIR)$(bindir) $(OUT_DIR)/acrnlog 55 install -d $(DESTDIR)$(systemd_unitdir)/system 56 install -p -D -m 0644 $(OUT_DIR)/acrnlog.service $(DESTDIR)$(systemd_unitdir)/system 57