# SPDX-License-Identifier: GPL-2.0
#
# Out-of-tree build of the in-kernel WireGuard driver (drivers/net/wireguard
# from Linux v7.0), for kernels built without CONFIG_WIREGUARD, e.g. the
# Arduino UNO Q's 7.0 kernel. Driver sources are unmodified upstream files.

KERNELRELEASE ?= $(shell uname -r)
KERNELDIR ?= /lib/modules/$(KERNELRELEASE)/build
PREFIX ?= /usr
DESTDIR ?=
SRCDIR ?= $(PREFIX)/src
DKMSDIR ?= $(SRCDIR)/wireguard-7.0
DEPMOD ?= depmod
DEPMODBASEDIR ?= /

PWD := $(shell pwd)

all: module

module:
	@$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

module-debug:
	@$(MAKE) -C $(KERNELDIR) M=$(PWD) V=1 CONFIG_WIREGUARD_DEBUG=y modules

clean:
	@$(MAKE) -C $(KERNELDIR) M=$(PWD) clean

module-install:
	@$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
	$(DEPMOD) -b "$(DEPMODBASEDIR)" -a $(KERNELRELEASE)

install: module-install

DKMS_SOURCES := Kbuild Makefile dkms.conf $(wildcard *.c *.h generated/*.c generated/*.h selftest/*.c crypto/*.c crypto/*.h)

dkms-install:
	@for f in $(DKMS_SOURCES); do install -v -m0644 -D $$f $(DESTDIR)$(DKMSDIR)/$$f; done

.PHONY: all module module-debug clean module-install install dkms-install
