]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/Makefile
hypervisor: Fix cleaning of generated files for latest kernels
[jailhouse.git] / hypervisor / Makefile
1 #
2 # Jailhouse, a Linux-based partitioning hypervisor
3 #
4 # Copyright (c) Siemens AG, 2013
5 # Copyright (c) Valentine Sinitsyn, 2014
6 #
7 # Authors:
8 #  Jan Kiszka <jan.kiszka@siemens.com>
9 #  Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
10 #
11 # This work is licensed under the terms of the GNU GPL, version 2.  See
12 # the COPYING file in the top-level directory.
13 #
14 # asm-defines.h generation code derived from Linux kernel.
15 #
16
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
22
23 ifeq ($(SRCARCH),x86)
24 KBUILD_CFLAGS += -mcmodel=kernel
25 KBUILD_CPPFLAGS += -m64
26 BUILD_VARIANTS := amd intel
27 endif
28
29 ifeq ($(SRCARCH),arm)
30 KBUILD_CFLAGS += -marm
31 endif
32
33 ifneq ($(wildcard $(obj)/include/jailhouse/config.h),)
34 KBUILD_CFLAGS += -include $(obj)/include/jailhouse/config.h
35 endif
36
37 CORE_OBJECTS = setup.o printk.o paging.o control.o lib.o
38
39 define filechk_config_mk
40 (                                                                       \
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;              \
47         fi                                                              \
48 )
49 endef
50
51 $(obj)/include/jailhouse/config.mk: Makefile FORCE
52         $(call filechk,config_mk)
53
54 define filechk_version
55         $(src)/../scripts/gen_version_h $(src)/..
56 endef
57
58 clean-files := include/jailhouse/config.mk \
59         include/jailhouse/version.h
60
61 define sed-y
62         "/^=>/{s:=>#\(.*\):/* \1 */:; \
63         s:^=>\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
64         s:^=>\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
65         s:=>::; p;}"
66 endef
67
68 quiet_cmd_defines = GEN     $@
69 define cmd_defines
70         (set -e; \
71          echo "#ifndef _GENERATED_ASM_DEFINES_H"; \
72          echo "#define _GENERATED_ASM_DEFINES_H"; \
73          echo "/*"; \
74          echo " * This file is autogenerated. If you need to change it,"; \
75          echo " * edit arch/$(SRCARCH)/asm-defines.c instead."; \
76          echo " *"; \
77          echo " * ALL MANUAL CHANGES TO THIS FILE WILL BE LOST!"; \
78          echo " */"; \
79          echo ""; \
80          sed -ne $(sed-y) $<; \
81          echo ""; \
82          echo "#endif" ) > $@
83 endef
84
85 defines-file := include/generated/asm-defines.h
86
87 targets := $(defines-file) arch/$(SRCARCH)/asm-defines.s
88
89 $(obj)/arch/$(SRCARCH)/asm-defines.s: $(src)/arch/$(SRCARCH)/asm-defines.c
90         $(call if_changed_dep,cc_s_c)
91
92 $(obj)/$(defines-file): $(obj)/arch/$(SRCARCH)/asm-defines.s
93         $(Q)mkdir -p $(dir $@)
94         $(call cmd,defines)
95
96 $(obj)/include/jailhouse/version.h: $(src)/Makefile FORCE
97         $(call filechk,version)
98
99 $(foreach co,$(CORE_OBJECTS),\
100         $(eval $(obj)/$(co): $(obj)/$(defines-file)))
101
102 $(obj)/setup.o: $(obj)/include/jailhouse/version.h
103
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
107
108 always :=
109
110 define BUILD_JAILHOUSE_template
111 always += jailhouse$(1).bin
112
113 hypervisor$(1)-y := $$(CORE_OBJECTS) arch/$$(SRCARCH)/built-in$(1).o \
114         hypervisor.lds
115 targets += $$(hypervisor$(1)-y)
116
117 # Need fake recipe here so make will consider this a volatile target
118 $$(obj)/arch/$$(SRCARCH)/built-in$(1).o: arch-builtin
119         @
120
121 HYPERVISOR$(1)_OBJS = $$(addprefix $$(obj)/,$$(hypervisor$(1)-y))
122
123 LDFLAGS_hypervisor$(1).o := -T
124
125 targets += hypervisor$(1).o
126 $$(obj)/hypervisor$(1).o: $$(src)/hypervisor.lds $$(HYPERVISOR$(1)_OBJS)
127         $$(call if_changed,ld)
128
129 OBJCOPYFLAGS_jailhouse$(1).bin := -O binary -R .eh_frame
130
131 targets += jailhouse$(1).bin
132 $$(obj)/jailhouse$(1).bin: $$(obj)/hypervisor$(1).o
133         $$(call if_changed,objcopy)
134 endef
135
136 ifneq ($(BUILD_VARIANTS),)
137 $(foreach variant,$(BUILD_VARIANTS),\
138         $(eval $(call BUILD_JAILHOUSE_template,-$(variant))))
139 else
140 $(eval $(call BUILD_JAILHOUSE_template,))
141 endif
142
143 .PHONY: arch-builtin