xref: /kvm-unit-tests/Makefile (revision a322d4c597bb7a4de7985e7b51b80504f7e4fdda)
1
2ifeq ($(wildcard config.mak),)
3$(error run ./configure first. See ./configure -h)
4endif
5
6include config.mak
7
8DESTDIR := $(PREFIX)/share/qemu/tests
9
10.PHONY: arch_clean clean distclean cscope
11
12#make sure env CFLAGS variable is not used
13CFLAGS =
14
15libgcc := $(shell $(CC) --print-libgcc-file-name)
16
17libcflat := lib/libcflat.a
18cflatobjs := \
19	lib/argv.o \
20	lib/printf.o \
21	lib/string.o \
22	lib/abort.o \
23	lib/report.o
24
25#include architecure specific make rules
26include config/config-$(ARCH).mak
27
28# cc-option
29# Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
30
31cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
32              > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
33
34CFLAGS += -g
35CFLAGS += $(autodepend-flags) -Wall
36CFLAGS += $(call cc-option, -fomit-frame-pointer, "")
37CFLAGS += $(call cc-option, -fno-stack-protector, "")
38CFLAGS += $(call cc-option, -fno-stack-protector-all, "")
39
40CXXFLAGS += $(CFLAGS)
41
42autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d
43
44LDFLAGS += $(CFLAGS)
45LDFLAGS += -pthread -lrt
46
47$(libcflat): $(cflatobjs)
48	$(AR) rcs $@ $^
49
50%.o: %.S
51	$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
52
53-include */.*.d */*/.*.d
54
55install:
56	mkdir -p $(DESTDIR)
57	install $(tests_and_config) $(DESTDIR)
58
59clean: arch_clean
60	$(RM) lib/.*.d $(libcflat) $(cflatobjs)
61
62distclean: clean
63	$(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.*
64
65cscope: common_dirs = lib
66cscope:
67	$(RM) ./cscope.*
68	find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \
69		-name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files
70	cscope -bk
71