]> git.karo-electronics.de Git - karo-tx-linux.git/blob - tools/kvm/Makefile
Merge remote-tracking branch 'signal/for-next'
[karo-tx-linux.git] / tools / kvm / Makefile
1 #
2 # Define WERROR=0 to disable -Werror.
3 #
4
5 ifeq ($(strip $(V)),)
6         E = @echo
7         Q = @
8 else
9         E = @\#
10         Q =
11 endif
12 ifneq ($(I), )
13         KINCL_PATH=$(I)
14 else
15         KINCL_PATH=../..
16 endif
17 export E Q KINCL_PATH
18
19 include config/utilities.mak
20 include config/feature-tests.mak
21
22 CC      := $(CROSS_COMPILE)$(CC)
23 LD      := $(CROSS_COMPILE)$(LD)
24
25 FIND    := find
26 CSCOPE  := cscope
27 TAGS    := ctags
28 INSTALL := install
29
30 prefix = $(HOME)
31 bindir_relative = bin
32 bindir = $(prefix)/$(bindir_relative)
33
34 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
35 bindir_SQ = $(subst ','\'',$(bindir))
36
37 PROGRAM := lkvm
38 PROGRAM_ALIAS := vm
39
40 GUEST_INIT := guest/init
41
42 OBJS    += builtin-balloon.o
43 OBJS    += builtin-debug.o
44 OBJS    += builtin-help.o
45 OBJS    += builtin-list.o
46 OBJS    += builtin-stat.o
47 OBJS    += builtin-pause.o
48 OBJS    += builtin-resume.o
49 OBJS    += builtin-run.o
50 OBJS    += builtin-setup.o
51 OBJS    += builtin-stop.o
52 OBJS    += builtin-version.o
53 OBJS    += disk/core.o
54 OBJS    += framebuffer.o
55 OBJS    += guest_compat.o
56 OBJS    += hw/rtc.o
57 OBJS    += hw/serial.o
58 OBJS    += ioport.o
59 OBJS    += kvm-cpu.o
60 OBJS    += kvm.o
61 OBJS    += main.o
62 OBJS    += mmio.o
63 OBJS    += pci.o
64 OBJS    += term.o
65 OBJS    += virtio/blk.o
66 OBJS    += virtio/scsi.o
67 OBJS    += virtio/console.o
68 OBJS    += virtio/core.o
69 OBJS    += virtio/net.o
70 OBJS    += virtio/rng.o
71 OBJS    += virtio/balloon.o
72 OBJS    += virtio/pci.o
73 OBJS    += disk/blk.o
74 OBJS    += disk/qcow.o
75 OBJS    += disk/raw.o
76 OBJS    += ioeventfd.o
77 OBJS    += net/uip/core.o
78 OBJS    += net/uip/arp.o
79 OBJS    += net/uip/icmp.o
80 OBJS    += net/uip/ipv4.o
81 OBJS    += net/uip/tcp.o
82 OBJS    += net/uip/udp.o
83 OBJS    += net/uip/buf.o
84 OBJS    += net/uip/csum.o
85 OBJS    += net/uip/dhcp.o
86 OBJS    += kvm-cmd.o
87 OBJS    += util/init.o
88 OBJS    += util/rbtree.o
89 OBJS    += util/threadpool.o
90 OBJS    += util/parse-options.o
91 OBJS    += util/rbtree-interval.o
92 OBJS    += util/strbuf.o
93 OBJS    += util/read-write.o
94 OBJS    += util/util.o
95 OBJS    += virtio/9p.o
96 OBJS    += virtio/9p-pdu.o
97 OBJS    += hw/vesa.o
98 OBJS    += hw/pci-shmem.o
99 OBJS    += kvm-ipc.o
100 OBJS    += builtin-sandbox.o
101 OBJS    += virtio/mmio.o
102
103 # Translate uname -m into ARCH string
104 ARCH ?= $(shell uname -m | sed -e s/i.86/i386/ -e s/ppc.*/powerpc/)
105
106 ifeq ($(ARCH),i386)
107         ARCH         := x86
108         DEFINES      += -DCONFIG_X86_32
109 endif
110 ifeq ($(ARCH),x86_64)
111         ARCH         := x86
112         DEFINES      += -DCONFIG_X86_64
113 endif
114
115 LIBFDT_SRC = fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o
116 LIBFDT_OBJS = $(patsubst %,../../scripts/dtc/libfdt/%,$(LIBFDT_SRC))
117
118 ### Arch-specific stuff
119
120 #x86
121 ifeq ($(ARCH),x86)
122         DEFINES += -DCONFIG_X86
123         OBJS    += x86/boot.o
124         OBJS    += x86/cpuid.o
125         OBJS    += x86/interrupt.o
126         OBJS    += x86/ioport.o
127         OBJS    += x86/irq.o
128         OBJS    += x86/kvm.o
129         OBJS    += x86/kvm-cpu.o
130         OBJS    += x86/mptable.o
131         OBJS    += hw/i8042.o
132 # Exclude BIOS object files from header dependencies.
133         OTHEROBJS       += x86/bios.o
134         OTHEROBJS       += x86/bios/bios-rom.o
135         ARCH_INCLUDE := x86/include
136 endif
137 # POWER/ppc:  Actually only support ppc64 currently.
138 ifeq ($(ARCH), powerpc)
139         DEFINES += -DCONFIG_PPC
140         OBJS    += powerpc/boot.o
141         OBJS    += powerpc/ioport.o
142         OBJS    += powerpc/irq.o
143         OBJS    += powerpc/kvm.o
144         OBJS    += powerpc/cpu_info.o
145         OBJS    += powerpc/kvm-cpu.o
146         OBJS    += powerpc/spapr_hcall.o
147         OBJS    += powerpc/spapr_rtas.o
148         OBJS    += powerpc/spapr_hvcons.o
149         OBJS    += powerpc/spapr_pci.o
150         OBJS    += powerpc/xics.o
151 # We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
152 # so just build it in:
153         CFLAGS  += -I../../scripts/dtc/libfdt
154         OTHEROBJS       += $(LIBFDT_OBJS)
155         ARCH_INCLUDE := powerpc/include
156         CFLAGS  += -m64
157 endif
158
159 ###
160
161 ifeq (,$(ARCH_INCLUDE))
162         UNSUPP_ERR = @echo "This architecture is not supported in kvmtool." && exit 1
163 else
164         UNSUPP_ERR =
165 endif
166
167 ###
168
169 # Detect optional features.
170 # On a given system, some libs may link statically, some may not; so, check
171 # both and only build those that link!
172
173 FLAGS_BFD := $(CFLAGS) -lbfd
174 ifeq ($(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD)),y)
175         CFLAGS_DYNOPT   += -DCONFIG_HAS_BFD
176         OBJS_DYNOPT     += symbol.o
177         LIBS_DYNOPT     += -lbfd
178 endif
179 ifeq ($(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD) -static),y)
180         CFLAGS_STATOPT  += -DCONFIG_HAS_BFD
181         OBJS_STATOPT    += symbol.o
182         LIBS_STATOPT    += -lbfd
183 endif
184
185 FLAGS_VNCSERVER := $(CFLAGS) -lvncserver
186 ifeq ($(call try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER)),y)
187         OBJS_DYNOPT     += ui/vnc.o
188         CFLAGS_DYNOPT   += -DCONFIG_HAS_VNCSERVER
189         LIBS_DYNOPT     += -lvncserver
190 endif
191 ifeq ($(call try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER) -static),y)
192         OBJS_STATOPT    += ui/vnc.o
193         CFLAGS_STATOPT  += -DCONFIG_HAS_VNCSERVER
194         LIBS_STATOPT    += -lvncserver
195 endif
196
197 FLAGS_SDL := $(CFLAGS) -lSDL
198 ifeq ($(call try-cc,$(SOURCE_SDL),$(FLAGS_SDL)),y)
199         OBJS_DYNOPT     += ui/sdl.o
200         CFLAGS_DYNOPT   += -DCONFIG_HAS_SDL
201         LIBS_DYNOPT     += -lSDL
202 endif
203 ifeq ($(call try-cc,$(SOURCE_SDL),$(FLAGS_SDL) -static), y)
204         OBJS_STATOPT    += ui/sdl.o
205         CFLAGS_STATOPT  += -DCONFIG_HAS_SDL
206         LIBS_STATOPT    += -lSDL
207 endif
208
209 FLAGS_ZLIB := $(CFLAGS) -lz
210 ifeq ($(call try-cc,$(SOURCE_ZLIB),$(FLAGS_ZLIB)),y)
211         CFLAGS_DYNOPT   += -DCONFIG_HAS_ZLIB
212         LIBS_DYNOPT     += -lz
213 endif
214 ifeq ($(call try-cc,$(SOURCE_ZLIB),$(FLAGS_ZLIB) -static),y)
215         CFLAGS_STATOPT  += -DCONFIG_HAS_ZLIB
216         LIBS_STATOPT    += -lz
217 endif
218
219 FLAGS_AIO := $(CFLAGS) -laio
220 ifeq ($(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO)),y)
221         CFLAGS_DYNOPT   += -DCONFIG_HAS_AIO
222         LIBS_DYNOPT     += -laio
223 endif
224 ifeq ($(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO) -static),y)
225         CFLAGS_STATOPT  += -DCONFIG_HAS_AIO
226         LIBS_STATOPT    += -laio
227 endif
228
229 ifneq ($(call try-build,$(SOURCE_STATIC),-static,),y)
230 $(error No static libc found. Please install glibc-static package.)
231 endif
232 ###
233
234 LIBS    += -lrt
235 LIBS    += -lpthread
236 LIBS    += -lutil
237
238
239 DEPS    := $(patsubst %.o,%.d,$(OBJS))
240
241 DEFINES += -D_FILE_OFFSET_BITS=64
242 DEFINES += -D_GNU_SOURCE
243 DEFINES += -DKVMTOOLS_VERSION='"$(KVMTOOLS_VERSION)"'
244 DEFINES += -DBUILD_ARCH='"$(ARCH)"'
245
246 KVM_INCLUDE := include
247 CFLAGS  += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) -I$(KINCL_PATH)/include/uapi -I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 -fno-strict-aliasing -g -flto
248
249 WARNINGS += -Wall
250 WARNINGS += -Wcast-align
251 WARNINGS += -Wformat=2
252 WARNINGS += -Winit-self
253 WARNINGS += -Wmissing-declarations
254 WARNINGS += -Wmissing-prototypes
255 WARNINGS += -Wnested-externs
256 WARNINGS += -Wno-system-headers
257 WARNINGS += -Wold-style-definition
258 WARNINGS += -Wredundant-decls
259 WARNINGS += -Wsign-compare
260 WARNINGS += -Wstrict-prototypes
261 WARNINGS += -Wundef
262 WARNINGS += -Wvolatile-register-var
263 WARNINGS += -Wwrite-strings
264
265 CFLAGS  += $(WARNINGS)
266
267 # Some targets may use 'external' sources that don't build totally cleanly.
268 CFLAGS_EASYGOING := $(CFLAGS)
269
270 ifneq ($(WERROR),0)
271         CFLAGS += -Werror
272 endif
273
274 all: arch_support_check $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT)
275
276 arch_support_check:
277         $(UNSUPP_ERR)
278
279 KVMTOOLS-VERSION-FILE:
280         @$(SHELL_PATH) util/KVMTOOLS-VERSION-GEN $(OUTPUT)
281 -include $(OUTPUT)KVMTOOLS-VERSION-FILE
282
283 # When building -static all objects are built with appropriate flags, which
284 # may differ between static & dynamic .o.  The objects are separated into
285 # .o and .static.o.  See the %.o: %.c rules below.
286 #
287 # $(OTHEROBJS) are things that do not get substituted like this.
288 #
289 STATIC_OBJS = $(patsubst %.o,%.static.o,$(OBJS) $(OBJS_STATOPT))
290 GUEST_OBJS = guest/guest_init.o
291
292 $(PROGRAM)-static:  $(DEPS) $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_INIT)
293         $(E) "  LINK    " $@
294         $(Q) $(CC) -static $(CFLAGS) $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_OBJS) $(LIBS) $(LIBS_STATOPT) -o $@
295
296 $(PROGRAM): $(DEPS) $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_INIT)
297         $(E) "  LINK    " $@
298         $(Q) $(CC) $(CFLAGS) $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_OBJS) $(LIBS) $(LIBS_DYNOPT) -o $@
299
300 $(PROGRAM_ALIAS): $(PROGRAM)
301         $(E) "  LN      " $@
302         $(Q) ln -f $(PROGRAM) $@
303
304 $(GUEST_INIT): guest/init.c
305         $(E) "  LINK    " $@
306         $(Q) $(CC) -static guest/init.c -o $@
307         $(Q) $(LD) -r -b binary -o guest/guest_init.o $(GUEST_INIT)
308
309 $(DEPS):
310
311 util/rbtree.d: ../../lib/rbtree.c
312         $(Q) $(CC) -M -MT util/rbtree.o $(CFLAGS) $< -o $@
313
314 %.d: %.c
315         $(Q) $(CC) -M -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@
316
317 %.s: %.c
318         $(Q) $(CC) -o $@ -S $(CFLAGS) -fverbose-asm $<
319
320 # The header file common-cmds.h is needed for compilation of builtin-help.c.
321 builtin-help.d: $(KVM_INCLUDE)/common-cmds.h
322
323 $(OBJS):
324
325 # This rule relaxes the -Werror on libfdt, since for now it still has
326 # a bunch of warnings. :(
327 ../../scripts/dtc/libfdt/%.o: ../../scripts/dtc/libfdt/%.c
328 ifeq ($(C),1)
329         $(E) "  CHECK   " $@
330         $(Q) $(CHECK) -c $(CFLAGS_EASYGOING) $< -o $@
331 endif
332         $(E) "  CC      " $@
333         $(Q) $(CC) -c $(CFLAGS_EASYGOING) $< -o $@
334
335 util/rbtree.static.o util/rbtree.o: ../../lib/rbtree.c
336 ifeq ($(C),1)
337         $(E) "  CHECK   " $@
338         $(Q) $(CHECK) -c $(CFLAGS) $< -o $@
339 endif
340         $(E) "  CC      " $@
341         $(Q) $(CC) -c $(CFLAGS) $< -o $@
342
343 %.static.o: %.c
344 ifeq ($(C),1)
345         $(E) "  CHECK   " $@
346         $(Q) $(CHECK) -c $(CFLAGS) $(CFLAGS_STATOPT) $< -o $@
347 endif
348         $(E) "  CC      " $@
349         $(Q) $(CC) -c $(CFLAGS) $(CFLAGS_STATOPT)  $< -o $@
350
351 %.o: %.c
352 ifeq ($(C),1)
353         $(E) "  CHECK   " $@
354         $(Q) $(CHECK) -c $(CFLAGS) $(CFLAGS_DYNOPT) $< -o $@
355 endif
356         $(E) "  CC      " $@
357         $(Q) $(CC) -c $(CFLAGS) $(CFLAGS_DYNOPT) $< -o $@
358
359
360 $(KVM_INCLUDE)/common-cmds.h: util/generate-cmdlist.sh command-list.txt
361
362 $(KVM_INCLUDE)/common-cmds.h: $(wildcard Documentation/kvm-*.txt)
363         $(E) "  GEN     " $@
364         $(Q) util/generate-cmdlist.sh > $@+ && mv $@+ $@
365
366 #
367 # BIOS assembly weirdness
368 #
369 BIOS_CFLAGS += -m32
370 BIOS_CFLAGS += -march=i386
371 BIOS_CFLAGS += -mregparm=3
372
373 BIOS_CFLAGS += -fno-stack-protector
374 BIOS_CFLAGS += -I../../arch/$(ARCH)
375
376 x86/bios.o: x86/bios/bios.bin x86/bios/bios-rom.h
377
378 x86/bios/bios.bin.elf: x86/bios/entry.S x86/bios/e820.c x86/bios/int10.c x86/bios/int15.c x86/bios/rom.ld.S
379         $(E) "  CC       x86/bios/memcpy.o"
380         $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s x86/bios/memcpy.c -o x86/bios/memcpy.o
381         $(E) "  CC       x86/bios/e820.o"
382         $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s x86/bios/e820.c -o x86/bios/e820.o
383         $(E) "  CC       x86/bios/int10.o"
384         $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s x86/bios/int10.c -o x86/bios/int10.o
385         $(E) "  CC       x86/bios/int15.o"
386         $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s x86/bios/int15.c -o x86/bios/int15.o
387         $(E) "  CC       x86/bios/entry.o"
388         $(Q) $(CC) $(CFLAGS) $(BIOS_CFLAGS) -c -s x86/bios/entry.S -o x86/bios/entry.o
389         $(E) "  LD      " $@
390         $(Q) $(LD) -T x86/bios/rom.ld.S -o x86/bios/bios.bin.elf x86/bios/memcpy.o x86/bios/entry.o x86/bios/e820.o x86/bios/int10.o x86/bios/int15.o
391
392 x86/bios/bios.bin: x86/bios/bios.bin.elf
393         $(E) "  OBJCOPY " $@
394         $(Q) objcopy -O binary -j .text x86/bios/bios.bin.elf x86/bios/bios.bin
395
396 x86/bios/bios-rom.o: x86/bios/bios-rom.S x86/bios/bios.bin x86/bios/bios-rom.h
397         $(E) "  CC      " $@
398         $(Q) $(CC) -c $(CFLAGS) x86/bios/bios-rom.S -o x86/bios/bios-rom.o
399
400 x86/bios/bios-rom.h: x86/bios/bios.bin.elf
401         $(E) "  NM      " $@
402         $(Q) cd x86/bios && sh gen-offsets.sh > bios-rom.h && cd ..
403
404 check: all
405         $(MAKE) -C tests
406         ./$(PROGRAM) run tests/pit/tick.bin
407         ./$(PROGRAM) run -d tests/boot/boot_test.iso -p "init=init"
408 .PHONY: check
409
410 install: all
411         $(E) "  INSTALL"
412         $(Q) $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)' 
413         $(Q) $(INSTALL) $(PROGRAM) '$(DESTDIR_SQ)$(bindir_SQ)' 
414 .PHONY: install
415
416 clean:
417         $(E) "  CLEAN"
418         $(Q) rm -f x86/bios/*.bin
419         $(Q) rm -f x86/bios/*.elf
420         $(Q) rm -f x86/bios/*.o
421         $(Q) rm -f x86/bios/bios-rom.h
422         $(Q) rm -f tests/boot/boot_test.iso
423         $(Q) rm -rf tests/boot/rootfs/
424         $(Q) rm -f $(DEPS) $(OBJS) $(OTHEROBJS) $(OBJS_DYNOPT) $(STATIC_OBJS) $(PROGRAM) $(PROGRAM_ALIAS) $(PROGRAM)-static $(GUEST_INIT) $(GUEST_OBJS)
425         $(Q) rm -f cscope.*
426         $(Q) rm -f tags
427         $(Q) rm -f TAGS
428         $(Q) rm -f $(KVM_INCLUDE)/common-cmds.h
429         $(Q) rm -f KVMTOOLS-VERSION-FILE
430 .PHONY: clean
431
432 KVM_DEV ?= /dev/kvm
433
434 $(KVM_DEV):
435         $(E) "  MKNOD " $@
436         $(Q) mknod $@ char 10 232
437
438 devices: $(KVM_DEV)
439 .PHONY: devices
440
441 TAGS:
442         $(E) "  GEN" $@
443         $(Q) $(RM) -f TAGS
444         $(Q) $(FIND) . -name '*.[hcS]' -print | xargs etags -a
445 .PHONY: TAGS
446
447 tags:
448         $(E) "  GEN" $@
449         $(Q) $(RM) -f tags
450         $(Q) $(FIND) . -name '*.[hcS]' -print | xargs ctags -a
451 .PHONY: tags
452
453 cscope:
454         $(E) "  GEN" $@
455         $(Q) $(FIND) . -name '*.[hcS]' -print > cscope.files
456         $(Q) $(CSCOPE) -bkqu
457 .PHONY: cscope
458
459 # Deps
460 -include $(DEPS)