From 53ed8f3ab41617a5f4a6f2257ad9e85ecabe323f Mon Sep 17 00:00:00 2001
From: Federico Vaga <federico.vaga@cern.ch>
Date: Mon, 9 Sep 2019 15:32:07 +0200
Subject: [PATCH] dist: build dkms dependencies first

Signed-off-by: Federico Vaga <federico.vaga@cern.ch>
---
 distribution/dkms.conf   | 13 ++++++++-----
 software/kernel/Makefile | 20 ++++++++++++++++++++
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/distribution/dkms.conf b/distribution/dkms.conf
index 9e0751f..50411d3 100644
--- a/distribution/dkms.conf
+++ b/distribution/dkms.conf
@@ -1,10 +1,10 @@
 PACKAGE_NAME="@PKGNAME@"
 PACKAGE_VERSION="@PKGVER@"
-CLEAN="make clean"
-MAKE[0]="make KVERSION=$kernelver all"
-MAKE[1]="make KVERSION=$kernelver all"
-MAKE[2]="make KVERSION=$kernelver all"
-MAKE[3]="make KVERSION=$kernelver all"
+CLEAN="make KVERSION=$kernelver DKMSTREE=$dkms_tree DKMS=1 clean"
+MAKE[0]="make KVERSION=$kernelver DKMSTREE=$dkms_tree DKMS=1 all"
+MAKE[1]="make KVERSION=$kernelver DKMSTREE=$dkms_tree DKMS=1 all"
+MAKE[2]="make KVERSION=$kernelver DKMSTREE=$dkms_tree DKMS=1 all"
+MAKE[3]="make KVERSION=$kernelver DKMSTREE=$dkms_tree DKMS=1 all"
 BUILT_MODULE_NAME[0]="@PKGNAME@"
 BUILT_MODULE_NAME[1]="gn412x-gpio"
 BUILT_MODULE_NAME[2]="gn412x-fcl"
@@ -13,4 +13,7 @@ DEST_MODULE_LOCATION[0]="/updates"
 DEST_MODULE_LOCATION[1]="/updates"
 DEST_MODULE_LOCATION[2]="/updates"
 DEST_MODULE_LOCATION[3]="/updates"
+BUILD_DEPENDS[0]="fmc"
+BUILD_DEPENDS[1]="fpga_mgr"
+BUILD_DEPENDS[2]="i2c-ocores"
 AUTOINSTALL="yes"
diff --git a/software/kernel/Makefile b/software/kernel/Makefile
index 9965763..c90eaf5 100644
--- a/software/kernel/Makefile
+++ b/software/kernel/Makefile
@@ -9,6 +9,26 @@ LINUX ?= /lib/modules/$(KVERSION)/build
 
 TOP_DIR ?= $(shell pwd)/../..
 HDL_DIR ?= $(TOP_DIR)/hdl
+DKMS ?= 0
+
+
+ifndef (CONFIG_FPGA_MGR_BACKPORT)
+ifeq ($(shell test $(shell uname -p) \> "4.4"), 0)
+CONFIG_FPGA_MGR_BACKPORT := n
+else
+CONFIG_FPGA_MGR_BACKPORT := y
+endif
+endif
+
+ifeq ($(DKMS), 1)
+FPGA_MGR_VERSION ?= $(shell basename $(shell ls -d $(DKMSTREE)/fpga_mgr/* | grep -E "\/[0-9]+\.[0-9]+\.[0-9]+" | sort -V | tail -n 1))
+FMC_VERSION ?= $(shell basename $(shell ls -d $(DKMSTREE)/fmc/* | grep -E "\/[0-9]+\.[0-9]+\.[0-9]+" | sort -V | tail -n 1))
+I2C_VERSION ?= $(shell basename $(shell ls -d $(DKMSTREE)/i2c-ocores/* | grep -E "\/[0-9]+\.[0-9]+\.[0-9]+" | sort -V | tail -n 1))
+
+CONFIG_FPGA_MGR_BACKPORT_PATH := $(DKMSTREE)/fpga_mgr/$(FPGA_MGR_VERSION)/source
+FMC := $(DKMSTREE)/fmc/$(FMC_VERSION)/source
+I2C := $(DKMSTREE)/i2c-ocores/$(I2C_VERSION)/source
+endif
 
 CONFIG_FPGA_MGR_BACKPORT_PATH_ABS ?= $(abspath $(CONFIG_FPGA_MGR_BACKPORT_PATH))
 FMC_ABS ?= $(abspath $(FMC))
-- 
GitLab