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
31 KBUILD_CPPFLAGS += -DARCH_LINK
34 ifneq ($(wildcard $(obj)/include/jailhouse/config.h),)
35 KBUILD_CFLAGS += -include $(obj)/include/jailhouse/config.h
38 CORE_OBJECTS = setup.o printk.o paging.o control.o lib.o
40 define filechk_config_mk
42 echo "\$$(foreach config,\$$(filter CONFIG_%, \
43 \$$(.VARIABLES)), \$$(eval undefine \$$(config)))"; \
44 if [ -f $(src)/include/jailhouse/config.h ]; then \
45 sed -e "/^#define \([^[:space:]]*\)[[:space:]]*1/!d" \
46 -e "s/^#define \([^[:space:]]*\)[[:space:]]*1/\1=y/" \
47 $(src)/include/jailhouse/config.h; \
52 $(obj)/include/jailhouse/config.mk: Makefile FORCE
53 $(call filechk,config_mk)
55 define filechk_version
56 $(src)/../scripts/gen_version_h $(src)/..
59 clean-files := $(obj)/include/jailhouse/config.mk \
60 $(obj)/include/jailhouse/version.h
63 "/^=>/{s:=>#\(.*\):/* \1 */:; \
64 s:^=>\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
65 s:^=>\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
69 quiet_cmd_defines = GEN $@
72 echo "#ifndef _GENERATED_ASM_DEFINES_H"; \
73 echo "#define _GENERATED_ASM_DEFINES_H"; \
75 echo " * This file is autogenerated. If you need to change it,"; \
76 echo " * edit arch/$(SRCARCH)/asm-defines.c instead."; \
78 echo " * ALL MANUAL CHANGES TO THIS FILE WILL BE LOST!"; \
81 sed -ne $(sed-y) $<; \
86 defines-file := include/generated/asm-defines.h
88 targets := $(defines-file) arch/$(SRCARCH)/asm-defines.s
90 $(obj)/arch/$(SRCARCH)/asm-defines.s: $(src)/arch/$(SRCARCH)/asm-defines.c
91 $(call if_changed_dep,cc_s_c)
93 $(obj)/$(defines-file): $(obj)/arch/$(SRCARCH)/asm-defines.s
94 $(Q)mkdir -p $(dir $@)
97 $(obj)/include/jailhouse/version.h: $(src)/Makefile FORCE
98 $(call filechk,version)
100 $(foreach co,$(CORE_OBJECTS),\
101 $(eval $(obj)/$(co): $(obj)/$(defines-file)))
103 $(obj)/setup.o: $(obj)/include/jailhouse/version.h
105 arch-builtin: $(obj)/$(defines-file) $(obj)/include/jailhouse/config.mk FORCE
106 $(Q)$(MAKE) $(build)=$(obj)/arch/$(SRCARCH) \
107 CONFIG_MK=$(obj)/include/jailhouse/config.mk
111 define BUILD_JAILHOUSE_template
112 always += jailhouse$(1).bin
114 hypervisor$(1)-y := $$(CORE_OBJECTS) arch/$$(SRCARCH)/built-in$(1).o \
116 targets += $$(hypervisor$(1)-y)
118 # Need fake recipe here so make will consider this a volatile target
119 $$(obj)/arch/$$(SRCARCH)/built-in$(1).o: arch-builtin
122 HYPERVISOR$(1)_OBJS = $$(addprefix $$(obj)/,$$(hypervisor$(1)-y))
124 LDFLAGS_hypervisor$(1).o := -T
126 targets += hypervisor$(1).o
127 $$(obj)/hypervisor$(1).o: $$(src)/hypervisor.lds $$(HYPERVISOR$(1)_OBJS)
128 $$(call if_changed,ld)
130 OBJCOPYFLAGS_jailhouse$(1).bin := -O binary -R .eh_frame
132 targets += jailhouse$(1).bin
133 $$(obj)/jailhouse$(1).bin: $$(obj)/hypervisor$(1).o
134 $$(call if_changed,objcopy)
137 ifneq ($(BUILD_VARIANTS),)
138 $(foreach variant,$(BUILD_VARIANTS),\
139 $(eval $(call BUILD_JAILHOUSE_template,-$(variant))))
141 $(eval $(call BUILD_JAILHOUSE_template,))