PAGE_FRAG_TEST_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

# Build the modules against the kernel tree these tests are part of, or
# its O= build directory, when that tree is configured and built; fall
# back to the running kernel's build tree.
KSRC_TREE := $(abspath $(PAGE_FRAG_TEST_DIR)/../../../../..)
KOUT := $(or $(O),$(KBUILD_OUTPUT))
ifeq ($(KOUT),)
KDIR_TREE := $(KSRC_TREE)
else ifneq (,$(filter /%,$(KOUT)))
KDIR_TREE := $(abspath $(KOUT))
else
KDIR_TREE := $(abspath $(KSRC_TREE)/$(KOUT))
endif
ifneq (,$(wildcard $(KDIR_TREE)/include/config/auto.conf))
ifneq (,$(wildcard $(KDIR_TREE)/Module.symvers))
KDIR ?= $(KDIR_TREE)
endif
endif
KDIR ?= /lib/modules/$(shell uname -r)/build

ifeq ($(V),1)
Q =
else
Q = @
endif

MODULES = page_frag_test.ko

obj-m += page_frag_test.o

all:
	+$(Q)make -C $(KDIR) M=$(PAGE_FRAG_TEST_DIR) modules

clean:
	+$(Q)make -C $(KDIR) M=$(PAGE_FRAG_TEST_DIR) clean
