Skip to content

Commit

Permalink
hv: enhance Makefile to compile debug/release into 2 libraries
Browse files Browse the repository at this point in the history
enhance Makefile to compile debug/release into 2 libraries

v1 -> v2:
 * auto make all the libraries

Tracked-On: #861
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
  • Loading branch information
shiqingg authored and wenlingz committed Nov 23, 2018
1 parent 19b35f9 commit 81db242
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
38 changes: 31 additions & 7 deletions hypervisor/Makefile
Expand Up @@ -17,11 +17,16 @@ STACK_PROTECTOR := 1
BASEDIR := $(shell pwd)
HV_OBJDIR ?= $(CURDIR)/build
HV_FILE := acrn
SUB_MAKEFILES := $(wildcard */Makefile)

LIB_DEBUG = $(HV_OBJDIR)/debug/libdebug.a
LIB_RELEASE = $(HV_OBJDIR)/release/librelease.a

# initialize the flags we used
CFLAGS :=
ASFLAGS :=
LDFLAGS :=
ARFLAGS :=
ARCH_CFLAGS :=
ARCH_ASFLAGS :=
ARCH_ARFLAGS :=
Expand All @@ -37,6 +42,8 @@ include scripts/kconfig/kconfig.mk
LD_IN_TOOL = scripts/genld.sh
BASH = $(shell which bash)

ARFLAGS += crs

CFLAGS += -Wall -W
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -fshort-wchar -ffreestanding
Expand Down Expand Up @@ -110,8 +117,10 @@ AR ?= ar
LD ?= ld
OBJCOPY ?= objcopy

D_SRCS += $(wildcard debug/*.c)
R_SRCS += $(wildcard release/*.c)
export CC AS AR LD OBJCOPY
export CFLAGS ASFLAGS ARFLAGS LDFLAGS ARCH_CFLAGS ARCH_ASFLAGS ARCH_ARFLAGS ARCH_LDFLAGS
export HV_OBJDIR CONFIG_RELEASE INCLUDE_PATH
export LIB_DEBUG LIB_RELEASE

C_SRCS += boot/acpi.c
C_SRCS += boot/dmar_parse.c
Expand Down Expand Up @@ -222,10 +231,7 @@ endif

C_OBJS := $(patsubst %.c,$(HV_OBJDIR)/%.o,$(C_SRCS))
ifneq ($(CONFIG_RELEASE),y)
C_OBJS += $(patsubst %.c,$(HV_OBJDIR)/%.o,$(D_SRCS))
CFLAGS += -DHV_DEBUG -DPROFILING_ON
else
C_OBJS += $(patsubst %.c,$(HV_OBJDIR)/%.o,$(R_SRCS))
endif
S_OBJS := $(patsubst %.S,$(HV_OBJDIR)/%.o,$(S_SRCS))

Expand Down Expand Up @@ -261,7 +267,7 @@ else
endif

.PHONY: all
all: $(HV_OBJDIR)/$(HV_FILE).32.out $(HV_OBJDIR)/$(HV_FILE).bin
all: lib $(HV_OBJDIR)/$(HV_FILE).32.out $(HV_OBJDIR)/$(HV_FILE).bin

ifeq ($(CONFIG_PLATFORM), uefi)
all: efi
Expand All @@ -279,6 +285,24 @@ install: $(HV_OBJDIR)/$(HV_FILE).32.out
install -D $(HV_OBJDIR)/$(HV_FILE).32.out $(DESTDIR)/usr/lib/acrn/$(HV_FILE).sbl
endif

.PHONY: header
header: $(VERSION) $(HV_OBJDIR)/$(HV_CONFIG_H) $(TARGET_ACPI_INFO_HEADER)

.PHONY: lib
lib: $(SUB_MAKEFILES)

.PHONY: $(SUB_MAKEFILES)
$(SUB_MAKEFILES): header
for Makefile in $(SUB_MAKEFILES); do \
$(MAKE) -f $$Makefile MKFL_NAME=$$Makefile; \
done

ifneq ($(CONFIG_RELEASE),y)
LIB_FLAGS += $(LIB_DEBUG)
else
LIB_FLAGS += $(LIB_RELEASE)
endif

$(HV_OBJDIR)/$(HV_FILE).32.out: $(HV_OBJDIR)/$(HV_FILE).out
$(OBJCOPY) -S --section-alignment=0x1000 -O elf32-i386 $< $@

Expand All @@ -287,7 +311,7 @@ $(HV_OBJDIR)/$(HV_FILE).bin: $(HV_OBJDIR)/$(HV_FILE).out

$(HV_OBJDIR)/$(HV_FILE).out: $(C_OBJS) $(S_OBJS)
${BASH} ${LD_IN_TOOL} $(ARCH_LDSCRIPT_IN) $(ARCH_LDSCRIPT) ${HV_OBJDIR}/.config
$(CC) -Wl,-Map=$(HV_OBJDIR)/$(HV_FILE).map -o $@ $(LDFLAGS) $(ARCH_LDFLAGS) -T$(ARCH_LDSCRIPT) $^
$(CC) -Wl,-Map=$(HV_OBJDIR)/$(HV_FILE).map -o $@ $(LDFLAGS) $(ARCH_LDFLAGS) -T$(ARCH_LDSCRIPT) $^ $(LIB_FLAGS)

.PHONY: clean
clean:
Expand Down
25 changes: 25 additions & 0 deletions hypervisor/debug/Makefile
@@ -0,0 +1,25 @@
#
# ACRN Hypervisor Static Library for Debug Features
#

FILE_PATH := $(dir $(MKFL_NAME))
SRCS += $(wildcard $(FILE_PATH)/*.c)
OBJS += $(patsubst %.c,$(HV_OBJDIR)/%.o,$(SRCS))

.PHONY: default
default: lib

ifneq ($(CONFIG_RELEASE),y)
lib: $(OBJS)
$(AR) $(ARFLAGS) $(LIB_DEBUG) $(OBJS)
endif

.PHONY: clean
clean:
rm -f $(OBJS)

-include $(OBJS:.o=.d)

$(HV_OBJDIR)/%.o: %.c
[ ! -e $@ ] && mkdir -p $(dir $@); \
$(CC) $(patsubst %, -I%, $(INCLUDE_PATH)) -I. -c $(CFLAGS) $(ARCH_CFLAGS) $< -o $@ -MMD -MT $@
25 changes: 25 additions & 0 deletions hypervisor/release/Makefile
@@ -0,0 +1,25 @@
#
# ACRN Hypervisor Static Library for Release Version
#

FILE_PATH := $(dir $(MKFL_NAME))
SRCS += $(wildcard $(FILE_PATH)/*.c)
OBJS += $(patsubst %.c,$(HV_OBJDIR)/%.o,$(SRCS))

.PHONY: default
default: lib

ifeq ($(CONFIG_RELEASE),y)
lib: $(OBJS)
$(AR) $(ARFLAGS) $(LIB_RELEASE) $(OBJS)
endif

.PHONY: clean
clean:
rm -f $(OBJS)

-include $(OBJS:.o=.d)

$(HV_OBJDIR)/%.o: %.c
[ ! -e $@ ] && mkdir -p $(dir $@); \
$(CC) $(patsubst %, -I%, $(INCLUDE_PATH)) -I. -c $(CFLAGS) $(ARCH_CFLAGS) $< -o $@ -MMD -MT $@

0 comments on commit 81db242

Please sign in to comment.