#!/usr/bin/make -f

# Debian rules for custom kernel module build
#
# This software is a part of ISAR.
# Copyright (c) Siemens AG, 2018
#
# SPDX-License-Identifier: MIT

export DEB_BUILD_OPTIONS=parallel=$(shell nproc)

export CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)-

ifeq ($(DEB_HOST_GNU_CPU), arm)
export ARCH=arm
endif
ifeq ($(DEB_HOST_GNU_CPU), aarch64)
export ARCH=arm64
endif
ifeq ($(DEB_HOST_GNU_CPU), riscv64)
export ARCH=riscv
endif
ifneq (,$(findstring 86,$(DEB_HOST_GNU_CPU)))
export ARCH=x86
endif

override_dh_auto_clean:
	$(MAKE) -C $(KDIR) M=$(PWD) clean

override_dh_auto_build:
	$(MAKE) -C $(KDIR) M=$(PWD) modules

override_dh_auto_install:
	$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(PWD)/debian/$(PN) modules_install

%:
	CFLAGS= LDFLAGS= dh $@ --parallel
