1# 2# ACRN-DM 3# 4include ../paths.make 5 6BASEDIR := $(shell pwd) 7DM_OBJDIR ?= $(CURDIR)/build 8DM_BUILD_VERSION ?= 9DM_BUILD_TAG ?= 10 11CC ?= gcc 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 26CFLAGS := -g -O0 -std=gnu11 27CFLAGS += -D_GNU_SOURCE 28CFLAGS += -DNO_OPENSSL 29CFLAGS += -m64 30CFLAGS += -Wall -ffunction-sections 31CFLAGS += -Werror 32CFLAGS += -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 33CFLAGS += -Wformat -Wformat-security -fno-strict-aliasing 34CFLAGS += -fno-delete-null-pointer-checks -fwrapv 35CFLAGS += -fpie 36CFLAGS += -Wno-stringop-truncation -Wno-address-of-packed-member 37 38CFLAGS += -I$(BASEDIR)/include 39CFLAGS += -I$(BASEDIR)/include/public 40CFLAGS += -I$(DM_OBJDIR)/include 41CFLAGS += -I$(TOOLS_OUT)/services 42CFLAGS += -I$(SYSROOT)/usr/include/pixman-1 43CFLAGS += -I$(SYSROOT)/usr/include/glib-2.0 44CFLAGS += -I$(SYSROOT)/usr/include/SDL2 45CFLAGS += -I$(SYSROOT)/usr/include/EGL 46CFLAGS += -I$(SYSROOT)/usr/include/GLES2 47 48CFLAGS += -DIASL_MIN_VER=\"$(IASL_MIN_VER)\" 49 50GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1) 51GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1) 52 53#enable stack overflow check 54STACK_PROTECTOR := 1 55 56ifdef STACK_PROTECTOR 57ifeq (true, $(shell [ $(GCC_MAJOR) -gt 4 ] && echo true)) 58CFLAGS += -fstack-protector-strong 59else 60ifeq (true, $(shell [ $(GCC_MAJOR) -eq 4 ] && [ $(GCC_MINOR) -ge 9 ] && echo true)) 61CFLAGS += -fstack-protector-strong 62else 63CFLAGS += -fstack-protector 64endif 65endif 66endif 67 68ifeq ($(RELEASE),n) 69CFLAGS += -DDM_DEBUG 70else 71LDFLAGS += -s 72endif 73 74 75LDFLAGS += -Wl,-z,noexecstack 76LDFLAGS += -Wl,-z,relro,-z,now 77LDFLAGS += -pie 78LDFLAGS += -L$(TOOLS_OUT)/services 79 80LIBS = -lrt 81LIBS += -lpthread 82LIBS += -lcrypto 83LIBS += -luring 84LIBS += -lpciaccess 85LIBS += -lusb-1.0 86LIBS += -lacrn-mngr 87LIBS += -lcjson 88LIBS += -lpixman-1 89LIBS += -lSDL2 90LIBS += -lEGL 91LIBS += -lGLESv2 92 93 94# lib 95SRCS += lib/dm_string.c 96 97# hw 98SRCS += hw/block_if.c 99SRCS += hw/usb_core.c 100SRCS += hw/uart_core.c 101SRCS += hw/vdisplay_sdl.c 102SRCS += hw/vga.c 103SRCS += hw/gc.c 104SRCS += hw/pci/virtio/virtio.c 105SRCS += hw/pci/virtio/virtio_kernel.c 106SRCS += hw/pci/virtio/vhost.c 107SRCS += hw/platform/usb_mouse.c 108SRCS += hw/platform/usb_pmapper.c 109SRCS += hw/platform/atkbdc.c 110SRCS += hw/platform/ps2mouse.c 111SRCS += hw/platform/rtc.c 112SRCS += hw/platform/pit.c 113SRCS += hw/platform/hpet.c 114SRCS += hw/platform/ps2kbd.c 115SRCS += hw/platform/ioapic.c 116SRCS += hw/platform/cmos_io.c 117SRCS += hw/platform/ioc.c 118SRCS += hw/platform/ioc_cbc.c 119SRCS += hw/platform/pty_vuart.c 120SRCS += hw/platform/acpi/acpi.c 121SRCS += hw/platform/vssram/vssram.c 122SRCS += hw/platform/acpi/acpi_pm.c 123SRCS += hw/platform/acpi/acpi_parser.c 124SRCS += hw/platform/rpmb/rpmb_sim.c 125SRCS += hw/platform/rpmb/rpmb_backend.c 126SRCS += hw/platform/rpmb/att_keybox.c 127SRCS += hw/platform/tpm/tpm_emulator.c 128SRCS += hw/platform/tpm/tpm_crb.c 129SRCS += hw/platform/tpm/tpm.c 130SRCS += hw/platform/debugexit.c 131SRCS += hw/pci/wdt_i6300esb.c 132SRCS += hw/pci/lpc.c 133SRCS += hw/pci/xhci.c 134SRCS += hw/pci/core.c 135SRCS += hw/pci/virtio/virtio_console.c 136SRCS += hw/pci/virtio/virtio_block.c 137SRCS += hw/pci/virtio/virtio_input.c 138SRCS += hw/pci/virtio/virtio_i2c.c 139SRCS += hw/pci/ahci.c 140SRCS += hw/pci/hostbridge.c 141SRCS += hw/pci/platform_gsi_info.c 142SRCS += hw/pci/gsi_sharing.c 143SRCS += hw/pci/passthrough.c 144SRCS += hw/pci/pci_util.c 145SRCS += hw/pci/ptm.c 146SRCS += hw/pci/virtio/virtio_audio.c 147SRCS += hw/pci/virtio/virtio_net.c 148SRCS += hw/pci/virtio/virtio_rnd.c 149SRCS += hw/pci/virtio/virtio_ipu.c 150SRCS += hw/pci/virtio/virtio_hyper_dmabuf.c 151SRCS += hw/pci/virtio/virtio_mei.c 152SRCS += hw/pci/virtio/virtio_coreu.c 153SRCS += hw/pci/virtio/virtio_hdcp.c 154SRCS += hw/pci/virtio/virtio_rpmb.c 155SRCS += hw/pci/virtio/virtio_gpio.c 156SRCS += hw/pci/virtio/virtio_gpu.c 157SRCS += hw/pci/virtio/vhost_vsock.c 158SRCS += hw/pci/irq.c 159SRCS += hw/pci/uart.c 160SRCS += hw/pci/gvt.c 161SRCS += hw/pci/npk.c 162SRCS += hw/pci/ivshmem.c 163SRCS += hw/mmio/core.c 164 165# core 166#SRCS += core/bootrom.c 167SRCS += core/monitor.c 168SRCS += core/sw_load_common.c 169SRCS += core/sw_load_bzimage.c 170SRCS += core/sw_load_vsbl.c 171SRCS += core/sw_load_ovmf.c 172SRCS += core/sw_load_elf.c 173SRCS += core/mevent.c 174SRCS += core/iothread.c 175SRCS += core/pm.c 176SRCS += core/pm_vuart.c 177SRCS += core/console.c 178SRCS += core/inout.c 179SRCS += core/mem.c 180SRCS += core/post.c 181SRCS += core/vmmapi.c 182SRCS += core/mptbl.c 183SRCS += core/main.c 184SRCS += core/hugetlb.c 185SRCS += core/vrpmb.c 186SRCS += core/timer.c 187SRCS += core/cmd_monitor/socket.c 188SRCS += core/cmd_monitor/command.c 189SRCS += core/cmd_monitor/command_handler.c 190SRCS += core/cmd_monitor/cmd_monitor.c 191SRCS += core/sbuf.c 192SRCS += core/vm_event.c 193 194# arch 195SRCS += arch/x86/pm.c 196SRCS += arch/x86/power_button.c 197 198# log 199SRCS += log/log.c 200SRCS += log/kmsg_logger.c 201SRCS += log/disk_logger.c 202 203OBJS := $(patsubst %.c,$(DM_OBJDIR)/%.o,$(SRCS)) 204 205VERSION_H := $(DM_OBJDIR)/include/version.h 206 207HEADERS := $(shell find $(BASEDIR) -name '*.h') 208HEADERS += $(VERSION_H) 209 210DISTCLEAN_OBJS := $(shell find $(BASEDIR) -name '*.o') 211 212PROGRAM := acrn-dm 213 214BIOS_BIN := $(wildcard bios/*) 215 216all: $(DM_OBJDIR)/$(PROGRAM) 217 @echo -n "" 218 219$(DM_OBJDIR)/$(PROGRAM): $(OBJS) 220 $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $^ $(LIBS) 221 222clean: 223 rm -rf $(DM_OBJDIR) 224 225distclean: 226 rm -f $(DISTCLEAN_OBJS) 227 rm -rf $(DM_OBJDIR) 228 rm -f tags TAGS cscope.files cscope.in.out cscope.out cscope.po.out GTAGS GPATH GRTAGS GSYMS 229 230$(VERSION_H): 231 mkdir -p $(DM_OBJDIR)/include 232 touch $(VERSION_H) 233 if [ "$(DM_BUILD_VERSION)"x = x ];then\ 234 COMMIT=`git rev-parse --verify --short HEAD 2>/dev/null`;\ 235 DIRTY=`git diff-index --name-only HEAD`;\ 236 if [ -n "$$DIRTY" ];then PATCH="$$COMMIT-dirty";else PATCH="$$COMMIT";fi;\ 237 else\ 238 PATCH="$(DM_BUILD_VERSION)";\ 239 fi;\ 240 COMMIT_TAGS=$$(git tag --points-at HEAD|tr -s "\n" " "); \ 241 COMMIT_TAGS=$$(eval echo $$COMMIT_TAGS);\ 242 COMMIT_TIME=$$(git log -1 --date=format:"%Y-%m-%d-%T" --format=%cd); \ 243 TIME=$$(date -u -d "@$${SOURCE_DATE_EPOCH:-$$(date +%s)}" "+%Y-%m-%d %H:%M:%S"); \ 244 USER="$${USER:-$$(id -u -n)}"; \ 245 echo "/*" > $(VERSION_H); \ 246 sed 's/^/ * /' ../LICENSE >> $(VERSION_H);\ 247 echo " */" >> $(VERSION_H);\ 248 echo "" >> $(VERSION_H);\ 249 echo "#define DM_BRANCH_VERSION "\"$(BRANCH_VERSION)\""" >> $(VERSION_H);\ 250 echo "#define DM_COMMIT_DIRTY "\""$$PATCH"\""" >> $(VERSION_H);\ 251 echo "#define DM_COMMIT_TAGS "\"$$COMMIT_TAGS\""" >> $(VERSION_H);\ 252 echo "#define DM_COMMIT_TIME "\"$$COMMIT_TIME\""" >> $(VERSION_H);\ 253 echo "#define DM_BUILD_TIME "\""$$TIME"\""" >> $(VERSION_H);\ 254 echo "#define DM_BUILD_USER "\""$$USER"\""" >> $(VERSION_H) 255 256-include $(OBJS:.o=.d) 257 258$(DM_OBJDIR)/%.o: %.c $(HEADERS) 259 [ ! -e $@ ] && mkdir -p $(dir $@); \ 260 $(CC) $(CFLAGS) -c $< -o $@ -MMD -MT $@ 261 262install: $(DM_OBJDIR)/$(PROGRAM) install-bios 263 install -D --mode=0755 $(DM_OBJDIR)/$(PROGRAM) $(DESTDIR)$(bindir)/$(PROGRAM) 264 265 266install-bios: $(BIOS_BIN) 267 install -d $(DESTDIR)$(datadir)/acrn/bios 268 install -D --mode=0664 -t $(DESTDIR)$(datadir)/acrn/bios $^ 269