2 # Jailhouse, a Linux-based partitioning hypervisor
4 # Copyright (c) Siemens AG, 2013
5 # Copyright (c) Valentine Sinitsyn, 2014
8 # Jan Kiszka <jan.kiszka@siemens.com>
9 # Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
11 # This work is licensed under the terms of the GNU GPL, version 2. See
12 # the COPYING file in the top-level directory.
14 # asm-defines.h generation code derived from Linux kernel.
17 LINUXINCLUDE := -I$(src)/arch/$(SRCARCH)/include -I$(src)/include
18 KBUILD_CFLAGS := -g -Os -Wall -Wstrict-prototypes -Wtype-limits \
19 -Wmissing-declarations -Wmissing-prototypes \
20 -fno-strict-aliasing -fno-pic -fno-common \
21 -fno-stack-protector -fno-builtin-ffsl
24 KBUILD_CFLAGS += -mcmodel=kernel
25 KBUILD_CPPFLAGS += -m64
26 BUILD_VARIANTS := amd intel
30 KBUILD_CFLAGS += -marm
33 ifneq ($(wildcard $(obj)/include/jailhouse/config.h),)
34 KBUILD_CFLAGS += -include $(obj)/include/jailhouse/config.h
37 CORE_OBJECTS = setup.o printk.o paging.o control.o lib.o
39 define filechk_config_mk
41 echo "\$$(foreach config,\$$(filter CONFIG_%, \
42 \$$(.VARIABLES)), \$$(eval undefine \$$(config)))"; \
43 if [ -f $(src)/include/jailhouse/config.h ]; then \
44 sed -e "/^#define \([^[:space:]]*\)[[:space:]]*1/!d" \
45 -e "s/^#define \([^[:space:]]*\)[[:space:]]*1/\1=y/" \
46 $(src)/include/jailhouse/config.h; \
51 $(obj)/include/jailhouse/config.mk: Makefile FORCE
52 $(call filechk,config_mk)
54 define filechk_version
55 $(src)/../scripts/gen_version_h $(src)/..
58 clean-files := include/jailhouse/config.mk \
59 include/jailhouse/version.h
62 "/^=>/{s:=>#\(.*\):/* \1 */:; \
63 s:^=>\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
64 s:^=>\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
68 quiet_cmd_defines = GEN $@
71 echo "#ifndef _GENERATED_ASM_DEFINES_H"; \
72 echo "#define _GENERATED_ASM_DEFINES_H"; \
74 echo " * This file is autogenerated. If you need to change it,"; \
75 echo " * edit arch/$(SRCARCH)/asm-defines.c instead."; \
77 echo " * ALL MANUAL CHANGES TO THIS FILE WILL BE LOST!"; \
80 sed -ne $(sed-y) $<; \
85 defines-file := include/generated/asm-defines.h
87 targets := $(defines-file) arch/$(SRCARCH)/asm-defines.s
89 $(obj)/arch/$(SRCARCH)/asm-defines.s: $(src)/arch/$(SRCARCH)/asm-defines.c
90 $(call if_changed_dep,cc_s_c)
92 $(obj)/$(defines-file): $(obj)/arch/$(SRCARCH)/asm-defines.s
93 $(Q)mkdir -p $(dir $@)
96 $(obj)/include/jailhouse/version.h: $(src)/Makefile FORCE
97 $(call filechk,version)
99 $(foreach co,$(CORE_OBJECTS),\
100 $(eval $(obj)/$(co): $(obj)/$(defines-file)))
102 $(obj)/setup.o: $(obj)/include/jailhouse/version.h
104 arch-builtin: $(obj)/$(defines-file) $(obj)/include/jailhouse/config.mk FORCE
105 $(Q)$(MAKE) $(build)=$(obj)/arch/$(SRCARCH) \
106 CONFIG_MK=$(obj)/include/jailhouse/config.mk
110 define BUILD_JAILHOUSE_template
111 always += jailhouse$(1).bin
113 hypervisor$(1)-y := $$(CORE_OBJECTS) arch/$$(SRCARCH)/built-in$(1).o \
115 targets += $$(hypervisor$(1)-y)
117 # Need fake recipe here so make will consider this a volatile target
118 $$(obj)/arch/$$(SRCARCH)/built-in$(1).o: arch-builtin
121 HYPERVISOR$(1)_OBJS = $$(addprefix $$(obj)/,$$(hypervisor$(1)-y))
123 LDFLAGS_hypervisor$(1).o := -T
125 targets += hypervisor$(1).o
126 $$(obj)/hypervisor$(1).o: $$(src)/hypervisor.lds $$(HYPERVISOR$(1)_OBJS)
127 $$(call if_changed,ld)
129 OBJCOPYFLAGS_jailhouse$(1).bin := -O binary -R .eh_frame
131 targets += jailhouse$(1).bin
132 $$(obj)/jailhouse$(1).bin: $$(obj)/hypervisor$(1).o
133 $$(call if_changed,objcopy)
136 ifneq ($(BUILD_VARIANTS),)
137 $(foreach variant,$(BUILD_VARIANTS),\
138 $(eval $(call BUILD_JAILHOUSE_template,-$(variant))))
140 $(eval $(call BUILD_JAILHOUSE_template,))