1include ../../../paths.make 2 3T := $(CURDIR) 4OUT_DIR ?= $(shell mkdir -p $(T)/build;cd $(T)/build;pwd) 5CC ?= gcc 6 7ifndef RELEASE 8 override RELEASE := n 9else 10 # Backward-compatibility for RELEASE=(0|1) 11 ifeq ($(RELEASE),1) 12 override RELEASE := y 13 else 14 ifeq ($(RELEASE),0) 15 override RELEASE := n 16 endif 17 endif 18endif 19 20MANAGER_CFLAGS := -g -O0 -std=gnu11 21MANAGER_CFLAGS += -D_GNU_SOURCE 22MANAGER_CFLAGS += -DNO_OPENSSL 23MANAGER_CFLAGS += -m64 24MANAGER_CFLAGS += -Wall -ffunction-sections 25MANAGER_CFLAGS += -Werror 26MANAGER_CFLAGS += -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 27MANAGER_CFLAGS += -Wformat -Wformat-security -fno-strict-aliasing 28MANAGER_CFLAGS += -fno-delete-null-pointer-checks -fwrapv 29MANAGER_CFLAGS += -fpie -fpic 30#FIXME: remove me. work-around for system() calls, which will be removed 31MANAGER_CFLAGS += -Wno-format-truncation -Wno-unused-result 32MANAGER_CFLAGS += -Wno-stringop-truncation 33MANAGER_CFLAGS += $(CFLAGS) 34 35MANAGER_CFLAGS += -I../../../devicemodel/include 36MANAGER_CFLAGS += -I../../../devicemodel/include/public 37MANAGER_CFLAGS += -I../../../hypervisor/include 38 39MANAGER_HEADERS := ../../../devicemodel/include/dm.h 40MANAGER_HEADERS += ../../../devicemodel/include/types.h 41MANAGER_HEADERS += ../../../devicemodel/include/pm.h 42MANAGER_HEADERS += ../../../devicemodel/include/dm_string.h 43MANAGER_HEADERS += ../../../devicemodel/include/macros.h 44MANAGER_HEADERS += ../../../devicemodel/include/public/hsm_ioctl_defs.h 45MANAGER_HEADERS += ../../../devicemodel/include/public/acrn_common.h 46 47GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1) 48GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1) 49 50#enable stack overflow check 51STACK_PROTECTOR := 1 52 53ifdef STACK_PROTECTOR 54ifeq (true, $(shell [ $(GCC_MAJOR) -gt 4 ] && echo true)) 55MANAGER_CFLAGS += -fstack-protector-strong 56else 57ifeq (true, $(shell [ $(GCC_MAJOR) -eq 4 ] && [ $(GCC_MINOR) -ge 9 ] && echo true)) 58MANAGER_CFLAGS += -fstack-protector-strong 59else 60MANAGER_CFLAGS += -fstack-protector 61endif 62endif 63endif 64 65ifeq ($(RELEASE),n) 66MANAGER_CFLAGS += -g -DMNGR_DEBUG 67else 68MANAGER_LDFLAGS += -s 69endif 70 71MANAGER_LDFLAGS := -Wl,-z,noexecstack 72MANAGER_LDFLAGS += -Wl,-z,relro,-z,now 73MANAGER_LDFLAGS += -pie 74MANAGER_LDFLAGS += -L$(OUT_DIR) 75MANAGER_LDFLAGS += -lpthread 76MANAGER_LDFLAGS += -lacrn-mngr 77MANAGER_LDFLAGS += $(LDFLAGS) 78 79.PHONY: all 80all: $(OUT_DIR)/libacrn-mngr.a $(OUT_DIR)/acrn_mngr.h $(OUT_DIR)/acrnctl $(OUT_DIR)/acrnd 81 82$(OUT_DIR)/libacrn-mngr.a: acrn_mngr.c acrn_mngr.h $(MANAGER_HEADERS) 83 $(CC) $(MANAGER_CFLAGS) -c acrn_mngr.c -o $(OUT_DIR)/acrn_mngr.o 84 ar -cr $@ $(OUT_DIR)/acrn_mngr.o 85 86ifneq ($(OUT_DIR),.) 87$(OUT_DIR)/acrn_mngr.h: ./acrn_mngr.h $(MANAGER_HEADERS) 88 cp ./acrn_mngr.h $(OUT_DIR)/ 89endif 90 91$(OUT_DIR)/acrnctl: acrnctl.c acrn_mngr.h $(OUT_DIR)/libacrn-mngr.a 92 $(CC) -o $(OUT_DIR)/acrnctl acrnctl.c acrn_vm_ops.c $(MANAGER_CFLAGS) $(MANAGER_LDFLAGS) 93 94$(OUT_DIR)/acrnd: acrnd.c $(OUT_DIR)/libacrn-mngr.a 95 $(CC) -o $(OUT_DIR)/acrnd acrnd.c acrn_vm_ops.c $(MANAGER_CFLAGS) $(MANAGER_LDFLAGS) 96ifneq ($(OUT_DIR),.) 97 cp ./acrnd.service $(OUT_DIR)/acrnd.service 98endif 99 100.PHONY: clean 101clean: 102 rm -f $(OUT_DIR)/acrnctl 103 rm -f $(OUT_DIR)/acrn_mngr.o 104 rm -f $(OUT_DIR)/libacrn-mngr.a 105 rm -f $(OUT_DIR)/acrnd 106ifneq ($(OUT_DIR),.) 107 rm -f $(OUT_DIR)/acrn_mngr.h 108 rm -f $(OUT_DIR)/acrnd.service 109 rm -rf $(OUT_DIR) 110endif 111 112.PHONY: install 113install: 114 install -d $(DESTDIR)$(bindir) 115 install -d $(DESTDIR)$(systemd_unitdir)/system 116 install -d $(DESTDIR)$(libdir) 117 install -d $(DESTDIR)$(includedir)/acrn 118 install -t $(DESTDIR)$(bindir) $(OUT_DIR)/acrnctl 119 install -t $(DESTDIR)$(bindir) $(OUT_DIR)/acrnd 120 install -m 0644 -t $(DESTDIR)$(libdir) $(OUT_DIR)/libacrn-mngr.a 121 install -m 0644 -t $(DESTDIR)$(includedir)/acrn $(OUT_DIR)/acrn_mngr.h 122 install -m 0644 -t $(DESTDIR)$(includedir)/acrn $(MANAGER_HEADERS) 123 install -p -D -m 0644 $(OUT_DIR)/acrnd.service $(DESTDIR)$(systemd_unitdir)/system 124