blob: 6240d8dfa76b6b4fb85248d17c1219b14f39d809 [file] [log] [blame]
Sergey Bronnikov1b7dd7d2017-03-15 14:12:33 +03001SHELL := /usr/bin/env bash
Andrew Jones48fadf82015-11-05 18:24:26 -06002
Andrew Jones89223062014-06-11 16:01:19 +02003ifeq ($(wildcard config.mak),)
4$(error run ./configure first. See ./configure -h)
5endif
6
Avi Kivity7d36db32010-08-03 14:07:34 +03007include config.mak
8
Alex Bennée5ba83e72017-05-12 17:39:55 +01009# Set search path for all sources
10VPATH = $(SRCDIR)
11
Andrew Jonesb39ad082016-06-04 20:20:50 +020012libdirs-get = $(shell [ -d "lib/$(1)" ] && echo "lib/$(1) lib/$(1)/asm")
Andrew Jonesc3758c02023-09-25 15:32:52 +020013ARCH_LIBDIRS := $(call libdirs-get,$(ARCH_LIBDIR)) $(call libdirs-get,$(TEST_DIR))
Alex Bennéec7eb0b72017-05-12 17:39:57 +010014OBJDIRS := $(ARCH_LIBDIRS)
Andrew Jonesb39ad082016-06-04 20:20:50 +020015
Andrew Jones93e7b442015-07-13 19:03:02 +020016DESTDIR := $(PREFIX)/share/kvm-unit-tests/
Avi Kivity7d36db32010-08-03 14:07:34 +030017
Andrew Jones34cc65d2014-06-11 16:01:20 +020018.PHONY: arch_clean clean distclean cscope
Avi Kivity7d36db32010-08-03 14:07:34 +030019
Andrew Jones4e40b022020-07-28 14:17:51 +020020# cc-option
21# Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
22cc-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 Kivity7d36db32010-08-03 14:07:34 +030025libcflat := lib/libcflat.a
26cflatobjs := \
Andrew Jones1b468b32014-06-11 16:01:17 +020027 lib/argv.o \
Avi Kivity7d36db32010-08-03 14:07:34 +030028 lib/printf.o \
Jan Kiszkaf3cdd152014-01-04 18:59:16 +010029 lib/string.o \
Andrew Jonesce42dc82014-07-11 10:19:34 +020030 lib/abort.o \
Peter Feiner52266792016-03-22 16:35:02 -070031 lib/report.o \
32 lib/stack.o
Avi Kivity7d36db32010-08-03 14:07:34 +030033
Andrew Jonesf7f76b82014-04-03 14:00:34 +020034# libfdt paths
35LIBFDT_objdir = lib/libfdt
Alex Bennée6d90fad2017-05-12 17:39:56 +010036LIBFDT_srcdir = $(SRCDIR)/lib/libfdt
Andrew Jonesf7f76b82014-04-03 14:00:34 +020037LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a
Andrew Jonesf7f76b82014-04-03 14:00:34 +020038
Alex Bennéec7eb0b72017-05-12 17:39:57 +010039OBJDIRS += $(LIBFDT_objdir)
40
Zixuan Wangad5fb882021-10-04 13:49:19 -070041# EFI App
Alexandru Eliseic98ce6e2022-02-23 12:55:37 +000042ifeq ($(CONFIG_EFI),y)
Nadav Amit35c167a2023-06-28 00:13:51 +000043EFI_CFLAGS := -DCONFIG_EFI -DCONFIG_RELOC
Zixuan Wangad5fb882021-10-04 13:49:19 -070044# The following CFLAGS and LDFLAGS come from:
45# - GNU-EFI/Makefile.defaults
46# - GNU-EFI/apps/Makefile
Zixuan Wangad5fb882021-10-04 13:49:19 -070047# GCC defines wchar to be 32 bits, but EFI expects 16 bits
48EFI_CFLAGS += -fshort-wchar
49# EFI applications use PIC as they are loaded to dynamic addresses, not a fixed
50# starting address
51EFI_CFLAGS += -fPIC
52# Create shared library
53EFI_LDFLAGS := -Bsymbolic -shared -nostdlib
54endif
55
Alex Bennée6d90fad2017-05-12 17:39:56 +010056#include architecture specific make rules
57include $(SRCDIR)/$(TEST_DIR)/Makefile
Avi Kivity7d36db32010-08-03 14:07:34 +030058
Thomas Huthac9e0752020-05-12 11:50:48 +020059COMMON_CFLAGS += -g $(autodepend-flags) -fno-strict-aliasing -fno-common
Bill Wendlingc62b1fd2019-11-06 17:08:43 -080060COMMON_CFLAGS += -Wall -Wwrite-strings -Wempty-body -Wuninitialized
Thomas Huth01c070a2022-03-22 18:15:04 +010061COMMON_CFLAGS += -Wignored-qualifiers -Wno-missing-braces $(CONFIG_WERROR)
Bill Wendlingc62b1fd2019-11-06 17:08:43 -080062
Peter Feiner52266792016-03-22 16:35:02 -070063frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer
64fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "")
Alexandru Elisei2087da52020-01-31 16:37:19 +000065fno_stack_protector := $(call cc-option, -fno-stack-protector, "")
66fno_stack_protector_all := $(call cc-option, -fno-stack-protector-all, "")
Paolo Bonzini29ff4882016-10-25 15:26:43 +020067wno_frame_address := $(call cc-option, -Wno-frame-address, "")
Gavin Guocdb91f62017-01-16 14:38:24 +010068fno_pic := $(call cc-option, -fno-pic, "")
69no_pie := $(call cc-option, -no-pie, "")
Bill Wendlingc62b1fd2019-11-06 17:08:43 -080070wclobbered := $(call cc-option, -Wclobbered, "")
71wunused_but_set_parameter := $(call cc-option, -Wunused-but-set-parameter, "")
72wmissing_parameter_type := $(call cc-option, -Wmissing-parameter-type, "")
73wold_style_declaration := $(call cc-option, -Wold-style-declaration, "")
74
Thomas Huth7cd97352017-06-29 20:42:51 +020075COMMON_CFLAGS += $(fomit_frame_pointer)
76COMMON_CFLAGS += $(fno_stack_protector)
77COMMON_CFLAGS += $(fno_stack_protector_all)
78COMMON_CFLAGS += $(wno_frame_address)
79COMMON_CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,)
Alexandru Eliseic98ce6e2022-02-23 12:55:37 +000080ifeq ($(CONFIG_EFI),y)
Zixuan Wangad5fb882021-10-04 13:49:19 -070081COMMON_CFLAGS += $(EFI_CFLAGS)
82else
Thomas Huthe8f85542023-08-22 09:43:15 +020083COMMON_CFLAGS += $(fno_pic)
Zixuan Wangad5fb882021-10-04 13:49:19 -070084endif
Bill Wendlingc62b1fd2019-11-06 17:08:43 -080085COMMON_CFLAGS += $(wclobbered)
86COMMON_CFLAGS += $(wunused_but_set_parameter)
Avi Kivity7d36db32010-08-03 14:07:34 +030087
Thomas Huth7cd97352017-06-29 20:42:51 +020088CFLAGS += $(COMMON_CFLAGS)
Bill Wendlingc62b1fd2019-11-06 17:08:43 -080089CFLAGS += $(wmissing_parameter_type)
90CFLAGS += $(wold_style_declaration)
91CFLAGS += -Woverride-init -Wmissing-prototypes -Wstrict-prototypes
Thomas Huth6b071482017-06-29 20:42:52 +020092
David Woodhouse3d92b972023-09-13 09:29:56 +020093autodepend-flags = -MMD -MP -MF $(dir $*).$(notdir $*).d
Avi Kivity7d36db32010-08-03 14:07:34 +030094
Thomas Huthe8f85542023-08-22 09:43:15 +020095LDFLAGS += -nostdlib $(no_pie) -z noexecstack
Avi Kivity7d36db32010-08-03 14:07:34 +030096
Avi Kivity7d36db32010-08-03 14:07:34 +030097$(libcflat): $(cflatobjs)
98 $(AR) rcs $@ $^
99
Andrew Jonesf7f76b82014-04-03 14:00:34 +0200100include $(LIBFDT_srcdir)/Makefile.libfdt
Alex Bennée241e1782017-05-12 17:39:58 +0100101$(LIBFDT_archive): CFLAGS += -ffreestanding -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -Wno-sign-compare
Andrew Jonesf7f76b82014-04-03 14:00:34 +0200102$(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
103 $(AR) rcs $@ $^
104
Nikos Nikoleris76ed5ff2021-03-18 18:07:26 +0000105libfdt_clean: VECHO = echo " "
106libfdt_clean: STD_CLEANFILES = *.o .*.d
107libfdt_clean: LIBFDT_dir = $(LIBFDT_objdir)
108libfdt_clean: SHAREDLIB_EXT = so
Alex Bennéec7eb0b72017-05-12 17:39:57 +0100109
110# Build directory target
111.PHONY: directories
112directories:
113 @mkdir -p $(OBJDIRS)
114
Avi Kivity7d36db32010-08-03 14:07:34 +0300115%.o: %.S
116 $(CC) $(CFLAGS) -c -nostdlib -o $@ $<
117
Andrew Jones761db0b2014-06-11 16:01:18 +0200118-include */.*.d */*/.*.d
Avi Kivity7d36db32010-08-03 14:07:34 +0300119
Ricardo Kollerac540152020-12-11 19:43:31 +0000120all: directories $(shell (cd $(SRCDIR) && git rev-parse --verify --short=8 HEAD) >build-head 2>/dev/null)
Andrew Jones3244d842016-03-03 15:33:54 +0100121
Andrew Jones2b30b762015-07-13 19:03:00 +0200122standalone: all
123 @scripts/mkstandalone.sh
124
Andrew Jones93e7b442015-07-13 19:03:02 +0200125install: standalone
Avi Kivity7d36db32010-08-03 14:07:34 +0300126 mkdir -p $(DESTDIR)
Andrew Jones93e7b442015-07-13 19:03:02 +0200127 install tests/* $(DESTDIR)
Avi Kivity7d36db32010-08-03 14:07:34 +0300128
Nikos Nikoleris76ed5ff2021-03-18 18:07:26 +0000129clean: arch_clean libfdt_clean
130 $(RM) $(LIBFDT_archive)
Andrew Jones761db0b2014-06-11 16:01:18 +0200131 $(RM) lib/.*.d $(libcflat) $(cflatobjs)
Andrew Jones89223062014-06-11 16:01:19 +0200132
Nikos Nikoleris76ed5ff2021-03-18 18:07:26 +0000133distclean: clean
Alexandru Elisei94315072019-02-04 13:44:08 +0000134 $(RM) lib/asm lib/config.h config.mak $(TEST_DIR)-run msr.out cscope.* build-head
Zixuan Wangad5fb882021-10-04 13:49:19 -0700135 $(RM) -r tests logs logs.old efi-tests
Andrew Jones34cc65d2014-06-11 16:01:20 +0200136
Andrew Jonesb39ad082016-06-04 20:20:50 +0200137cscope: cscope_dirs = lib lib/libfdt lib/linux $(TEST_DIR) $(ARCH_LIBDIRS) lib/asm-generic
Andrew Jones34cc65d2014-06-11 16:01:20 +0200138cscope:
139 $(RM) ./cscope.*
Andrew Jonesa01c0f72016-02-10 14:47:25 +0100140 find -L $(cscope_dirs) -maxdepth 1 \
Andrew Jones3d4eb242021-08-27 12:25:27 +0200141 -name '*.[chsS]' -exec realpath --relative-base=$(CURDIR) {} \; | sort -u > ./cscope.files
Andrew Jones34cc65d2014-06-11 16:01:20 +0200142 cscope -bk
Siddharth Chandrasekaran4e0b9582021-06-10 13:31:28 +0200143
Nicholas Pigginddfdcc32024-05-01 21:29:30 +1000144.PHONY: shellcheck
145shellcheck:
146 shellcheck -a run_tests.sh */run */efi/run scripts/mkstandalone.sh
147
Siddharth Chandrasekaran4e0b9582021-06-10 13:31:28 +0200148.PHONY: tags
149tags:
150 ctags -R
Nico Boehrea4ca8a2023-11-06 13:50:57 +0100151
152check-kerneldoc:
153 find . -name '*.[ch]' -exec scripts/kernel-doc -none {} +