1# 2# ACRN-Crashlog Makefile 3# 4 5include ../../../paths.make 6 7BASEDIR := $(shell pwd) 8OUT_DIR ?= $(BASEDIR) 9BUILDDIR := $(OUT_DIR)/acrn-crashlog 10CC ?= gcc 11RM = rm 12 13ifndef RELEASE 14 override RELEASE := n 15else 16 # Backward-compatibility for RELEASE=(0|1) 17 ifeq ($(RELEASE),1) 18 override RELEASE := y 19 else 20 ifeq ($(RELEASE),0) 21 override RELEASE := n 22 endif 23 endif 24endif 25 26ifeq ($(RELEASE),n) 27CFLAGS += -DDEBUG_ACRN_CRASHLOG 28endif 29 30CFLAGS := -g -O0 -std=gnu11 31CFLAGS += -D_GNU_SOURCE 32CFLAGS += -m64 33CFLAGS += -Wall -ffunction-sections 34CFLAGS += -Werror 35CFLAGS += -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 36CFLAGS += -Wformat -Wformat-security -fno-strict-aliasing 37CFLAGS += -fpie 38CFLAGS += -Wall -Wextra -pedantic 39 40CFLAGS += -I$(BASEDIR)/include 41CFLAGS += -I$(BASEDIR)/include/public 42 43GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1) 44GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1) 45 46#enable stack overflow check 47STACK_PROTECTOR := 1 48 49ifdef STACK_PROTECTOR 50ifeq (true, $(shell [ $(GCC_MAJOR) -gt 4 ] && echo true)) 51CFLAGS += -fstack-protector-strong 52else 53ifeq (true, $(shell [ $(GCC_MAJOR) -eq 4 ] && [ $(GCC_MINOR) -ge 9 ] && echo true)) 54CFLAGS += -fstack-protector-strong 55else 56CFLAGS += -fstack-protector 57endif 58endif 59endif 60 61LDFLAGS += -Wl,-z,noexecstack 62LDFLAGS += -Wl,-z,relro,-z,now 63LDFLAGS += -pie 64INCLUDE := -I $(BASEDIR)/common/include 65 66export INCLUDE 67export BUILDDIR 68export CC 69export RM 70 71PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(SYSROOT)/usr/lib/pkgconfig 72PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(SYSROOT)/usr/share/pkgconfig 73PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(SYSROOT)/usr/local/lib/pkgconfig 74PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(SYSROOT)/usr/local/share/pkgconfig 75PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(SYSROOT)/usr/lib32/pkgconfig 76PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(SYSROOT)/usr/lib64/pkgconfig 77 78EXTRA_LIBS = -lsystemd-journal 79PKG_CONFIG := $(shell export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH); \ 80 pkg-config --libs libsystemd) 81LIB_EXIST := $(findstring lsystemd, $(PKG_CONFIG)) 82ifeq ($(strip $(LIB_EXIST)),lsystemd) 83 EXTRA_LIBS := -lsystemd 84endif 85 86export CFLAGS 87export LDFLAGS 88export EXTRA_LIBS 89 90.PHONY:all 91all: 92 $(MAKE) -C common 93 $(MAKE) -C acrnprobe 94 $(MAKE) -C usercrash 95 96.PHONY:clean 97clean: 98 $(MAKE) -C common clean 99 $(MAKE) -C acrnprobe clean 100 $(MAKE) -C usercrash clean 101 @if [ -d "$(BUILDDIR)" ]; then \ 102 $(RM) -rf $(BUILDDIR); \ 103 fi 104 105.PHONY:install 106install: 107 @install -d $(DESTDIR)$(bindir)/ 108 @install -p -D -m 0755 $(BUILDDIR)/acrnprobe/bin/acrnprobe $(DESTDIR)$(bindir)/ 109 @install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/debugger $(DESTDIR)$(bindir)/ 110 @install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/usercrash_c $(DESTDIR)$(bindir)/ 111 @install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/usercrash_s $(DESTDIR)$(bindir)/ 112 @install -p -D -m 0755 data/crashlogctl $(DESTDIR)$(bindir)/ 113 @install -p -D -m 0755 data/usercrash-wrapper $(DESTDIR)$(bindir)/ 114 @install -d $(DESTDIR)$(datadir)/acrn/crashlog 115 @install -p -D -m 0644 data/40-watchdog.conf $(DESTDIR)$(datadir)/acrn/crashlog 116 @install -p -D -m 0644 data/80-coredump.conf $(DESTDIR)$(datadir)/acrn/crashlog 117 @install -d $(DESTDIR)$(systemd_unitdir)/system/ 118 @install -p -D -m 0644 data/acrnprobe.service $(DESTDIR)$(systemd_unitdir)/system/ 119 @install -p -D -m 0644 data/usercrash.service $(DESTDIR)$(systemd_unitdir)/system/ 120 121.PHONY:uninstall 122uninstall: 123 @if [ -e "$(DESTDIR)$(bindir)/acrnprobe" ];then \ 124 $(RM) $(DESTDIR)$(bindir)/acrnprobe; \ 125 fi 126 @if [ -e "$(DESTDIR)$(bindir)/crashlogctl" ];then \ 127 $(DESTDIR)$(bindir)/crashlogctl disable && \ 128 $(RM) $(DESTDIR)$(bindir)/crashlogctl; \ 129 fi 130 @if [ -e "$(DESTDIR)$(bindir)/debugger" ];then \ 131 $(RM) $(DESTDIR)$(bindir)/debugger; \ 132 fi 133 @if [ -e "$(DESTDIR)$(bindir)/usercrash_c" ];then \ 134 $(RM) $(DESTDIR)$(bindir)/usercrash_c; \ 135 fi 136 @if [ -e "$(DESTDIR)$(bindir)/usercrash_s" ];then \ 137 $(RM) $(DESTDIR)$(bindir)/usercrash_s; \ 138 fi 139 @if [ -e "$(DESTDIR)$(bindir)/usercrash-wrapper" ];then \ 140 $(RM) $(DESTDIR)$(bindir)/usercrash-wrapper; \ 141 fi 142 @if [ -e "$(DESTDIR)$(datadir)/acrn/crashlog/40-watchdog.conf" ];then \ 143 $(RM) $(DESTDIR)$(datadir)/acrn/crashlog/40-watchdog.conf; \ 144 fi 145 @if [ -e "$(DESTDIR)$(datadir)/acrn/crashlog/80-coredump.conf" ];then \ 146 $(RM) $(DESTDIR)$(datadir)/acrn/crashlog/80-coredump.conf; \ 147 fi 148 @if [ -e "$(DESTDIR)$(systemd_unitdir)/system/acrnprobe.service" ];then \ 149 $(RM) $(DESTDIR)$(systemd_unitdir)/system/acrnprobe.service; \ 150 fi 151 @if [ -e "$(DESTDIR)$(systemd_unitdir)/system/usercrash.service" ];then \ 152 $(RM) $(DESTDIR)$(systemd_unitdir)/system/usercrash.service; \ 153 fi 154