# SPDX-License-Identifier: GPL-2.0
################################################################################
#
# Driver for Solarflare and Xilinx network controllers and boards
# Copyright 2019 Solarflare Communications Inc.
# Copyright 2019-2020 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 KERNELRELEASE
# kbuild part of makefile
ifndef CONFIG_AUXILIARY_BUS
TOPDIR := $(src)/../..
include $(TOPDIR)/scripts/Makefile.common
export CONFIG_AUXILIARY_BUS := m

obj-m += auxiliary.o

ifndef EFX_UPSTREAM
$(obj)/auxiliary.o: $(obj)/.kpath $(obj)/autocompat.h
endif # !EFX_UPSTREAM
endif
else
# normal makefile
TOPDIR := ../..
include $(TOPDIR)/scripts/Makefile.common

all modules:
	$(MAKE) -C $(KDIR) $(EXTRA_MAKEFLAGS) M=$$(pwd) modules

ifndef EFX_UPSTREAM
# Do not overwrite the existing in-tree driver.
export:
	test -f $(KDIR)/drivers/base/auxiliary.c || \
		$(EXPORT_CMD) -s drivers/base $(KDIR) auxiliary.c

export-srpm:
	test -f $(KDIR)/drivers/base/auxiliary.c || \
		$(EXPORT_CMD) -o -s drivers/base $(KDIR) auxiliary.c kernel_compat.h kernel_compat.sh $(TOPDIR)/scripts/kernel_compat_funcs.sh
endif # !EFX_UPSTREAM
#
modules_install:
	mkdir -p $(INSTALL_MOD_PATH)/lib/modules/$(KVER)/$(INSTALL_MOD_DIR)
	$(MAKE) -C $(KDIR) $(EXTRA_MAKEFLAGS) M=$$(pwd) INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) modules_install
clean:
	$(MAKE) -C $(KDIR) $(EXTRA_MAKEFLAGS) M=$$(pwd) $@
ifndef EFX_UPSTREAM
	@$(RM) .kpath autocompat.h

.PHONY : export export-srpm
endif # !EFX_UPSTREAM
endif
