Sergey Bronnikov | 1b7dd7d | 2017-03-15 14:12:33 +0300 | [diff] [blame] | 1 | SHELL := /usr/bin/env bash |
Andrew Jones | 48fadf8 | 2015-11-05 18:24:26 -0600 | [diff] [blame] | 2 | |
Andrew Jones | 8922306 | 2014-06-11 16:01:19 +0200 | [diff] [blame] | 3 | ifeq ($(wildcard config.mak),) |
| 4 | $(error run ./configure first. See ./configure -h) |
| 5 | endif |
| 6 | |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 7 | include config.mak |
| 8 | |
Alex Bennée | 5ba83e7 | 2017-05-12 17:39:55 +0100 | [diff] [blame] | 9 | # Set search path for all sources |
| 10 | VPATH = $(SRCDIR) |
| 11 | |
Andrew Jones | b39ad08 | 2016-06-04 20:20:50 +0200 | [diff] [blame] | 12 | libdirs-get = $(shell [ -d "lib/$(1)" ] && echo "lib/$(1) lib/$(1)/asm") |
Andrew Jones | c3758c0 | 2023-09-25 15:32:52 +0200 | [diff] [blame] | 13 | ARCH_LIBDIRS := $(call libdirs-get,$(ARCH_LIBDIR)) $(call libdirs-get,$(TEST_DIR)) |
Alex Bennée | c7eb0b7 | 2017-05-12 17:39:57 +0100 | [diff] [blame] | 14 | OBJDIRS := $(ARCH_LIBDIRS) |
Andrew Jones | b39ad08 | 2016-06-04 20:20:50 +0200 | [diff] [blame] | 15 | |
Andrew Jones | 93e7b44 | 2015-07-13 19:03:02 +0200 | [diff] [blame] | 16 | DESTDIR := $(PREFIX)/share/kvm-unit-tests/ |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 17 | |
Andrew Jones | 34cc65d | 2014-06-11 16:01:20 +0200 | [diff] [blame] | 18 | .PHONY: arch_clean clean distclean cscope |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 19 | |
Andrew Jones | 4e40b02 | 2020-07-28 14:17:51 +0200 | [diff] [blame] | 20 | # cc-option |
| 21 | # Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0) |
| 22 | cc-option = $(shell if $(CC) -Werror $(1) -S -o /dev/null -xc /dev/null \ |
| 23 | > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) |
| 24 | |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 25 | libcflat := lib/libcflat.a |
| 26 | cflatobjs := \ |
Andrew Jones | 1b468b3 | 2014-06-11 16:01:17 +0200 | [diff] [blame] | 27 | lib/argv.o \ |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 28 | lib/printf.o \ |
Jan Kiszka | f3cdd15 | 2014-01-04 18:59:16 +0100 | [diff] [blame] | 29 | lib/string.o \ |
Andrew Jones | ce42dc8 | 2014-07-11 10:19:34 +0200 | [diff] [blame] | 30 | lib/abort.o \ |
Peter Feiner | 5226679 | 2016-03-22 16:35:02 -0700 | [diff] [blame] | 31 | lib/report.o \ |
| 32 | lib/stack.o |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 33 | |
Andrew Jones | f7f76b8 | 2014-04-03 14:00:34 +0200 | [diff] [blame] | 34 | # libfdt paths |
| 35 | LIBFDT_objdir = lib/libfdt |
Alex Bennée | 6d90fad | 2017-05-12 17:39:56 +0100 | [diff] [blame] | 36 | LIBFDT_srcdir = $(SRCDIR)/lib/libfdt |
Andrew Jones | f7f76b8 | 2014-04-03 14:00:34 +0200 | [diff] [blame] | 37 | LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a |
Andrew Jones | f7f76b8 | 2014-04-03 14:00:34 +0200 | [diff] [blame] | 38 | |
Alex Bennée | c7eb0b7 | 2017-05-12 17:39:57 +0100 | [diff] [blame] | 39 | OBJDIRS += $(LIBFDT_objdir) |
| 40 | |
Zixuan Wang | ad5fb88 | 2021-10-04 13:49:19 -0700 | [diff] [blame] | 41 | # EFI App |
Alexandru Elisei | c98ce6e | 2022-02-23 12:55:37 +0000 | [diff] [blame] | 42 | ifeq ($(CONFIG_EFI),y) |
Nadav Amit | 35c167a | 2023-06-28 00:13:51 +0000 | [diff] [blame] | 43 | EFI_CFLAGS := -DCONFIG_EFI -DCONFIG_RELOC |
Zixuan Wang | ad5fb88 | 2021-10-04 13:49:19 -0700 | [diff] [blame] | 44 | # The following CFLAGS and LDFLAGS come from: |
| 45 | # - GNU-EFI/Makefile.defaults |
| 46 | # - GNU-EFI/apps/Makefile |
Zixuan Wang | ad5fb88 | 2021-10-04 13:49:19 -0700 | [diff] [blame] | 47 | # GCC defines wchar to be 32 bits, but EFI expects 16 bits |
| 48 | EFI_CFLAGS += -fshort-wchar |
| 49 | # EFI applications use PIC as they are loaded to dynamic addresses, not a fixed |
| 50 | # starting address |
| 51 | EFI_CFLAGS += -fPIC |
| 52 | # Create shared library |
| 53 | EFI_LDFLAGS := -Bsymbolic -shared -nostdlib |
| 54 | endif |
| 55 | |
Alex Bennée | 6d90fad | 2017-05-12 17:39:56 +0100 | [diff] [blame] | 56 | #include architecture specific make rules |
| 57 | include $(SRCDIR)/$(TEST_DIR)/Makefile |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 58 | |
Thomas Huth | ac9e075 | 2020-05-12 11:50:48 +0200 | [diff] [blame] | 59 | COMMON_CFLAGS += -g $(autodepend-flags) -fno-strict-aliasing -fno-common |
Bill Wendling | c62b1fd | 2019-11-06 17:08:43 -0800 | [diff] [blame] | 60 | COMMON_CFLAGS += -Wall -Wwrite-strings -Wempty-body -Wuninitialized |
Thomas Huth | 01c070a | 2022-03-22 18:15:04 +0100 | [diff] [blame] | 61 | COMMON_CFLAGS += -Wignored-qualifiers -Wno-missing-braces $(CONFIG_WERROR) |
Bill Wendling | c62b1fd | 2019-11-06 17:08:43 -0800 | [diff] [blame] | 62 | |
Peter Feiner | 5226679 | 2016-03-22 16:35:02 -0700 | [diff] [blame] | 63 | frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer |
| 64 | fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "") |
Alexandru Elisei | 2087da5 | 2020-01-31 16:37:19 +0000 | [diff] [blame] | 65 | fno_stack_protector := $(call cc-option, -fno-stack-protector, "") |
| 66 | fno_stack_protector_all := $(call cc-option, -fno-stack-protector-all, "") |
Paolo Bonzini | 29ff488 | 2016-10-25 15:26:43 +0200 | [diff] [blame] | 67 | wno_frame_address := $(call cc-option, -Wno-frame-address, "") |
Gavin Guo | cdb91f6 | 2017-01-16 14:38:24 +0100 | [diff] [blame] | 68 | fno_pic := $(call cc-option, -fno-pic, "") |
| 69 | no_pie := $(call cc-option, -no-pie, "") |
Bill Wendling | c62b1fd | 2019-11-06 17:08:43 -0800 | [diff] [blame] | 70 | wclobbered := $(call cc-option, -Wclobbered, "") |
| 71 | wunused_but_set_parameter := $(call cc-option, -Wunused-but-set-parameter, "") |
| 72 | wmissing_parameter_type := $(call cc-option, -Wmissing-parameter-type, "") |
| 73 | wold_style_declaration := $(call cc-option, -Wold-style-declaration, "") |
| 74 | |
Thomas Huth | 7cd9735 | 2017-06-29 20:42:51 +0200 | [diff] [blame] | 75 | COMMON_CFLAGS += $(fomit_frame_pointer) |
| 76 | COMMON_CFLAGS += $(fno_stack_protector) |
| 77 | COMMON_CFLAGS += $(fno_stack_protector_all) |
| 78 | COMMON_CFLAGS += $(wno_frame_address) |
| 79 | COMMON_CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,) |
Alexandru Elisei | c98ce6e | 2022-02-23 12:55:37 +0000 | [diff] [blame] | 80 | ifeq ($(CONFIG_EFI),y) |
Zixuan Wang | ad5fb88 | 2021-10-04 13:49:19 -0700 | [diff] [blame] | 81 | COMMON_CFLAGS += $(EFI_CFLAGS) |
| 82 | else |
Thomas Huth | e8f8554 | 2023-08-22 09:43:15 +0200 | [diff] [blame] | 83 | COMMON_CFLAGS += $(fno_pic) |
Zixuan Wang | ad5fb88 | 2021-10-04 13:49:19 -0700 | [diff] [blame] | 84 | endif |
Bill Wendling | c62b1fd | 2019-11-06 17:08:43 -0800 | [diff] [blame] | 85 | COMMON_CFLAGS += $(wclobbered) |
| 86 | COMMON_CFLAGS += $(wunused_but_set_parameter) |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 87 | |
Thomas Huth | 7cd9735 | 2017-06-29 20:42:51 +0200 | [diff] [blame] | 88 | CFLAGS += $(COMMON_CFLAGS) |
Bill Wendling | c62b1fd | 2019-11-06 17:08:43 -0800 | [diff] [blame] | 89 | CFLAGS += $(wmissing_parameter_type) |
| 90 | CFLAGS += $(wold_style_declaration) |
| 91 | CFLAGS += -Woverride-init -Wmissing-prototypes -Wstrict-prototypes |
Thomas Huth | 6b07148 | 2017-06-29 20:42:52 +0200 | [diff] [blame] | 92 | |
David Woodhouse | 3d92b97 | 2023-09-13 09:29:56 +0200 | [diff] [blame] | 93 | autodepend-flags = -MMD -MP -MF $(dir $*).$(notdir $*).d |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 94 | |
Thomas Huth | e8f8554 | 2023-08-22 09:43:15 +0200 | [diff] [blame] | 95 | LDFLAGS += -nostdlib $(no_pie) -z noexecstack |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 96 | |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 97 | $(libcflat): $(cflatobjs) |
| 98 | $(AR) rcs $@ $^ |
| 99 | |
Andrew Jones | f7f76b8 | 2014-04-03 14:00:34 +0200 | [diff] [blame] | 100 | include $(LIBFDT_srcdir)/Makefile.libfdt |
Alex Bennée | 241e178 | 2017-05-12 17:39:58 +0100 | [diff] [blame] | 101 | $(LIBFDT_archive): CFLAGS += -ffreestanding -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -Wno-sign-compare |
Andrew Jones | f7f76b8 | 2014-04-03 14:00:34 +0200 | [diff] [blame] | 102 | $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) |
| 103 | $(AR) rcs $@ $^ |
| 104 | |
Nikos Nikoleris | 76ed5ff | 2021-03-18 18:07:26 +0000 | [diff] [blame] | 105 | libfdt_clean: VECHO = echo " " |
| 106 | libfdt_clean: STD_CLEANFILES = *.o .*.d |
| 107 | libfdt_clean: LIBFDT_dir = $(LIBFDT_objdir) |
| 108 | libfdt_clean: SHAREDLIB_EXT = so |
Alex Bennée | c7eb0b7 | 2017-05-12 17:39:57 +0100 | [diff] [blame] | 109 | |
| 110 | # Build directory target |
| 111 | .PHONY: directories |
| 112 | directories: |
| 113 | @mkdir -p $(OBJDIRS) |
| 114 | |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 115 | %.o: %.S |
| 116 | $(CC) $(CFLAGS) -c -nostdlib -o $@ $< |
| 117 | |
Andrew Jones | 761db0b | 2014-06-11 16:01:18 +0200 | [diff] [blame] | 118 | -include */.*.d */*/.*.d |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 119 | |
Ricardo Koller | ac54015 | 2020-12-11 19:43:31 +0000 | [diff] [blame] | 120 | all: directories $(shell (cd $(SRCDIR) && git rev-parse --verify --short=8 HEAD) >build-head 2>/dev/null) |
Andrew Jones | 3244d84 | 2016-03-03 15:33:54 +0100 | [diff] [blame] | 121 | |
Andrew Jones | 2b30b76 | 2015-07-13 19:03:00 +0200 | [diff] [blame] | 122 | standalone: all |
| 123 | @scripts/mkstandalone.sh |
| 124 | |
Andrew Jones | 93e7b44 | 2015-07-13 19:03:02 +0200 | [diff] [blame] | 125 | install: standalone |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 126 | mkdir -p $(DESTDIR) |
Andrew Jones | 93e7b44 | 2015-07-13 19:03:02 +0200 | [diff] [blame] | 127 | install tests/* $(DESTDIR) |
Avi Kivity | 7d36db3 | 2010-08-03 14:07:34 +0300 | [diff] [blame] | 128 | |
Nikos Nikoleris | 76ed5ff | 2021-03-18 18:07:26 +0000 | [diff] [blame] | 129 | clean: arch_clean libfdt_clean |
| 130 | $(RM) $(LIBFDT_archive) |
Andrew Jones | 761db0b | 2014-06-11 16:01:18 +0200 | [diff] [blame] | 131 | $(RM) lib/.*.d $(libcflat) $(cflatobjs) |
Andrew Jones | 8922306 | 2014-06-11 16:01:19 +0200 | [diff] [blame] | 132 | |
Nikos Nikoleris | 76ed5ff | 2021-03-18 18:07:26 +0000 | [diff] [blame] | 133 | distclean: clean |
Alexandru Elisei | 9431507 | 2019-02-04 13:44:08 +0000 | [diff] [blame] | 134 | $(RM) lib/asm lib/config.h config.mak $(TEST_DIR)-run msr.out cscope.* build-head |
Zixuan Wang | ad5fb88 | 2021-10-04 13:49:19 -0700 | [diff] [blame] | 135 | $(RM) -r tests logs logs.old efi-tests |
Andrew Jones | 34cc65d | 2014-06-11 16:01:20 +0200 | [diff] [blame] | 136 | |
Andrew Jones | b39ad08 | 2016-06-04 20:20:50 +0200 | [diff] [blame] | 137 | cscope: cscope_dirs = lib lib/libfdt lib/linux $(TEST_DIR) $(ARCH_LIBDIRS) lib/asm-generic |
Andrew Jones | 34cc65d | 2014-06-11 16:01:20 +0200 | [diff] [blame] | 138 | cscope: |
| 139 | $(RM) ./cscope.* |
Andrew Jones | a01c0f7 | 2016-02-10 14:47:25 +0100 | [diff] [blame] | 140 | find -L $(cscope_dirs) -maxdepth 1 \ |
Andrew Jones | 3d4eb24 | 2021-08-27 12:25:27 +0200 | [diff] [blame] | 141 | -name '*.[chsS]' -exec realpath --relative-base=$(CURDIR) {} \; | sort -u > ./cscope.files |
Andrew Jones | 34cc65d | 2014-06-11 16:01:20 +0200 | [diff] [blame] | 142 | cscope -bk |
Siddharth Chandrasekaran | 4e0b958 | 2021-06-10 13:31:28 +0200 | [diff] [blame] | 143 | |
Nicholas Piggin | ddfdcc3 | 2024-05-01 21:29:30 +1000 | [diff] [blame] | 144 | .PHONY: shellcheck |
| 145 | shellcheck: |
| 146 | shellcheck -a run_tests.sh */run */efi/run scripts/mkstandalone.sh |
| 147 | |
Siddharth Chandrasekaran | 4e0b958 | 2021-06-10 13:31:28 +0200 | [diff] [blame] | 148 | .PHONY: tags |
| 149 | tags: |
| 150 | ctags -R |
Nico Boehr | ea4ca8a | 2023-11-06 13:50:57 +0100 | [diff] [blame] | 151 | |
| 152 | check-kerneldoc: |
| 153 | find . -name '*.[ch]' -exec scripts/kernel-doc -none {} + |