xref: /kvm-unit-tests/x86/Makefile.common (revision 8b13a5b5cfdb26920c8f631a1e56e7a5eac917fe)
1#This is a make file with common rules for both x86 & x86-64
2
3all: directories test_cases
4
5cflatobjs += lib/pci.o
6cflatobjs += lib/pci-edu.o
7cflatobjs += lib/x86/setup.o
8cflatobjs += lib/x86/io.o
9cflatobjs += lib/x86/smp.o
10cflatobjs += lib/x86/vm.o
11cflatobjs += lib/x86/fwcfg.o
12cflatobjs += lib/x86/apic.o
13cflatobjs += lib/x86/atomic.o
14cflatobjs += lib/x86/desc.o
15cflatobjs += lib/x86/isr.o
16cflatobjs += lib/x86/acpi.o
17cflatobjs += lib/x86/stack.o
18
19OBJDIRS += lib/x86
20
21$(libcflat): LDFLAGS += -nostdlib
22$(libcflat): CFLAGS += -ffreestanding -I $(SRCDIR)/lib -I lib
23
24CFLAGS += -m$(bits)
25CFLAGS += -O1
26
27# stack.o relies on frame pointers.
28KEEP_FRAME_POINTER := y
29
30libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
31
32# We want to keep intermediate file: %.elf and %.o
33.PRECIOUS: %.elf %.o
34
35FLATLIBS = lib/libcflat.a $(libgcc)
36%.elf: %.o $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o)
37	$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,$(SRCDIR)/x86/flat.lds \
38		$(filter %.o, $^) $(FLATLIBS)
39
40%.flat: %.elf
41	$(OBJCOPY) -O elf32-i386 $^ $@
42
43tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
44               $(TEST_DIR)/smptest.flat  $(TEST_DIR)/port80.flat \
45               $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \
46               $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \
47               $(TEST_DIR)/kvmclock_test.flat  $(TEST_DIR)/eventinj.flat \
48               $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat $(TEST_DIR)/setjmp.flat \
49               $(TEST_DIR)/tsc_adjust.flat $(TEST_DIR)/asyncpf.flat \
50               $(TEST_DIR)/init.flat $(TEST_DIR)/smap.flat \
51               $(TEST_DIR)/hyperv_synic.flat $(TEST_DIR)/hyperv_stimer.flat \
52               $(TEST_DIR)/hyperv_connections.flat \
53
54ifdef API
55tests-api = api/api-sample api/dirty-log api/dirty-log-perf
56
57OBJDIRS += api
58endif
59
60test_cases: $(tests-common) $(tests) $(tests-api)
61
62$(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I $(SRCDIR)/lib -I $(SRCDIR)/lib/x86 -I lib
63
64$(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o
65	$(CC) -m32 -nostdlib -o $@ -Wl,-T,$(SRCDIR)/$(TEST_DIR)/realmode.lds $^
66
67$(TEST_DIR)/realmode.o: bits = 32
68
69$(TEST_DIR)/kvmclock_test.elf: $(TEST_DIR)/kvmclock.o
70
71$(TEST_DIR)/hyperv_synic.elf: $(TEST_DIR)/hyperv.o
72
73$(TEST_DIR)/hyperv_stimer.elf: $(TEST_DIR)/hyperv.o
74
75$(TEST_DIR)/hyperv_connections.elf: $(TEST_DIR)/hyperv.o
76
77arch_clean:
78	$(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \
79	$(TEST_DIR)/.*.d lib/x86/.*.d \
80	$(tests-api) api/*.o api/*.a api/.*.d
81
82api/%.o: CXXFLAGS += -m32 -std=gnu++11
83
84api/%: LDLIBS += -lstdc++ -lpthread -lrt
85api/%: LDFLAGS += -m32
86
87api/libapi.a: api/kvmxx.o api/identity.o api/exception.o api/memmap.o
88	$(AR) rcs $@ $^
89
90$(tests-api) : % : %.o api/libapi.a
91