################################################################################
#
# Driver for Xilinx network controllers and boards
# Copyright 2021 Xilinx Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation, incorporated herein by reference.
#
################################################################################

ifdef KPATH
	KDIR ?= $(KPATH)
else
	KDIR ?= /lib/modules/$(shell uname -r)/build
endif

ifdef AUX_BUS_PATH
	cmd = make AUX_BUS_PATH=$(AUX_BUS_PATH)
else
	cmd = make
endif

all modules:
	$(MAKE) -C drivers/net/ethernet/xilinx $@

install modules_install:
	$(MAKE) -C drivers/net/ethernet/xilinx modules_install

clean:
	$(MAKE) -C drivers/net/ethernet/xilinx $@
	$(RM) -r deb rpm .version
test-clean:
	cd tests/selftests/ktf/; autoreconf; \
	rm kernel/autocompat.h; \
        ./configure KDIR=$(KDIR); make clean
export-srpm export:
	$(MAKE) -C drivers/net/ethernet/xilinx $@
	$(MAKE) -C include/linux $@
util:
	$(MAKE) -C drivers/net/ethernet/xilinx $@
test:
	cd tests/selftests/ktf/; autoreconf; \
	./configure KDIR=$(KDIR); ./ktf_kernel_compat.sh; $(cmd)

.PHONY: deb
version:
	@if [ -d .git ] && [ "$(USE_BASE_DRIVER_VERSION)" == "" ]; then \
		git describe --tags --match v* HEAD | sed 's/^v//; s/_/./g'; \
	else \
		grep EFCT_DRIVER_VERSION drivers/net/ethernet/xilinx/net_driver.h | cut -d\" -f2; \
	fi

srpm:
	+scripts/makesrpm --$@

deb:
	+scripts/mkdeb

sdeb:
	+scripts/mkdeb -S
