sonic-buildimage/platform/broadcom/saibcm-modules/sdklt/make/lkm.mk

74 lines
1.8 KiB
Makefile
Raw Normal View History

#
2021-10-28 02:12:32 -05:00
# $Copyright: Copyright 2018-2021 Broadcom. All rights reserved.
# The term 'Broadcom' refers to Broadcom Inc. and/or its subsidiaries.
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# A copy of the GNU General Public License version 2 (GPLv2) can
# be found in the LICENSES folder.$
#
# Shared makefile include for building Linux kernel modules.
#
# KDIR must point to the Linux kernel sources
ifndef KDIR
nokdir:; @echo 'The $$KDIR variable is not set'; exit 1
endif
# Required for older kernels
export EXTRA_CFLAGS = $(ccflags-y)
PWD := $(shell pwd)
ifneq ($(LKM_BLDDIR),)
#
# If a build directory has been specified, then we symlink all sources
# to this directory and redirect the module build path.
#
# Note that the KBUILD_OUTPUT variable cannot be used to redirect the
# output as we want it.
#
2021-10-28 02:12:32 -05:00
MDIR := $(LKM_BLDDIR)
MSRCS := $(patsubst %.o,%.c,$($(MOD_NAME)-y))
MSRCS += Makefile Kbuild
2021-10-28 02:12:32 -05:00
BSRCS := $(addprefix $(PWD)/,$(MSRCS))
else
#
# Build in current directory by default.
#
2021-10-28 02:12:32 -05:00
MDIR := $(PWD)
endif
2021-10-28 02:12:32 -05:00
all: mlinks
$(Q)echo Building kernel module $(MOD_NAME)
$(MAKE) -C $(KDIR) M=$(MDIR)
2021-10-28 02:12:32 -05:00
clean:: mlinks
$(Q)echo Cleaning kernel module $(MOD_NAME)
$(MAKE) -C $(KDIR) M=$(MDIR) clean
2021-10-28 02:12:32 -05:00
ifneq ($(MDIR),$(PWD))
rm -rf $(MDIR)
endif
2021-10-28 02:12:32 -05:00
mlinks:
ifneq ($(MDIR),$(PWD))
$(Q)mkdir -p $(MDIR)
(cd $(MDIR); \
rm -rf $(MSRCS); \
for f in $(BSRCS); do \
ln -s $$f; \
done)
endif
2021-10-28 02:12:32 -05:00
.PHONY: all mlinks clean
# Standard documentation targets
-include $(SDK)/make/doc.mk