1 2SHELL := /bin/bash 3 4ifeq ($(wildcard config.mak),) 5$(error run ./configure first. See ./configure -h) 6endif 7 8include config.mak 9 10libdirs-get = $(shell [ -d "lib/$(1)" ] && echo "lib/$(1) lib/$(1)/asm") 11ARCH_LIBDIRS := $(call libdirs-get,$(ARCH)) $(call libdirs-get,$(TEST_DIR)) 12 13DESTDIR := $(PREFIX)/share/kvm-unit-tests/ 14 15.PHONY: arch_clean clean distclean cscope 16 17#make sure env CFLAGS variable is not used 18CFLAGS = 19 20libgcc := $(shell $(CC) --print-libgcc-file-name) 21 22libcflat := lib/libcflat.a 23cflatobjs := \ 24 lib/argv.o \ 25 lib/printf.o \ 26 lib/string.o \ 27 lib/abort.o \ 28 lib/report.o \ 29 lib/stack.o 30 31# libfdt paths 32LIBFDT_objdir = lib/libfdt 33LIBFDT_srcdir = lib/libfdt 34LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a 35LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES)) 36LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION)) 37 38#include architecure specific make rules 39include $(TEST_DIR)/Makefile 40 41# cc-option 42# Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0) 43 44cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \ 45 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) 46 47CFLAGS += -g 48CFLAGS += $(autodepend-flags) -Wall -Werror 49frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer 50fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "") 51fnostack_protector := $(call cc-option, -fno-stack-protector, "") 52fnostack_protector_all := $(call cc-option, -fno-stack-protector-all, "") 53wno_frame_address := $(call cc-option, -Wno-frame-address, "") 54CFLAGS += $(fomit_frame_pointer) 55CFLAGS += $(fno_stack_protector) 56CFLAGS += $(fno_stack_protector_all) 57CFLAGS += $(wno_frame_address) 58CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,) 59 60CXXFLAGS += $(CFLAGS) 61 62autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d 63 64LDFLAGS += $(CFLAGS) 65LDFLAGS += -pthread -lrt 66 67$(libcflat): $(cflatobjs) 68 $(AR) rcs $@ $^ 69 70include $(LIBFDT_srcdir)/Makefile.libfdt 71$(LIBFDT_archive): CFLAGS += -ffreestanding -I lib -I lib/libfdt -Wno-sign-compare 72$(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) 73 $(AR) rcs $@ $^ 74 75%.o: %.S 76 $(CC) $(CFLAGS) -c -nostdlib -o $@ $< 77 78-include */.*.d */*/.*.d 79 80all: $(shell git rev-parse --verify --short=8 HEAD >build-head 2>/dev/null) 81 82standalone: all 83 @scripts/mkstandalone.sh 84 85install: standalone 86 mkdir -p $(DESTDIR) 87 install tests/* $(DESTDIR) 88 89clean: arch_clean 90 $(RM) lib/.*.d $(libcflat) $(cflatobjs) 91 92libfdt_clean: 93 $(RM) $(LIBFDT_archive) \ 94 $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) \ 95 $(LIBFDT_objdir)/.*.d 96 97distclean: clean libfdt_clean 98 $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* \ 99 build-head 100 $(RM) -r tests 101 102cscope: cscope_dirs = lib lib/libfdt lib/linux $(TEST_DIR) $(ARCH_LIBDIRS) lib/asm-generic 103cscope: 104 $(RM) ./cscope.* 105 find -L $(cscope_dirs) -maxdepth 1 \ 106 -name '*.[chsS]' -print | sed 's,^\./,,' | sort -u > ./cscope.files 107 cscope -bk 108