1276846Simp# $FreeBSD$
2276846Simp#
3276846Simp# The include file <dtb.mk> handles building and installing dtb files.
4276846Simp#
5276846Simp# +++ variables +++
6276846Simp#
7276846Simp# DTS		List of the dts files to build and install.
8276846Simp#
9276846Simp# DTBDIR	Base path for dtb modules [/boot/dtb]
10276846Simp#
11276846Simp# DTBOWN	.dtb file owner. [${BINOWN}]
12276846Simp#
13276846Simp# DTBGRP	.dtb file group. [${BINGRP}]
14276846Simp#
15276846Simp# DTBMODE	Module file mode. [${BINMODE}]
16276846Simp#
17276846Simp# DESTDIR	The tree where the module gets installed. [not set]
18276846Simp#
19276846Simp# +++ targets +++
20276846Simp#
21276846Simp# 	install:
22276846Simp#               install the kernel module; if the Makefile
23276846Simp#               does not itself define the target install, the targets
24276846Simp#               beforeinstall and afterinstall may also be used to cause
25276846Simp#               actions immediately before and after the install target
26276846Simp#		is executed.
27276846Simp#
28276846Simp
29276846Simp.include <bsd.init.mk>
30276846Simp# Grab all the options for a kernel build. For backwards compat, we need to
31276846Simp# do this after bsd.own.mk.
32283930Simp#.include "kern.opts.mk" # commented out to minize difference with 11.x and newer
33276846Simp
34276846Simp# Search for kernel source tree in standard places.
35276846Simp.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
36276846Simp.if !defined(SYSDIR) && exists(${_dir}/kern/)
37276846SimpSYSDIR=	${_dir}
38276846Simp.endif
39276846Simp.endfor
40276846Simp.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/)
41276846Simp.error "can't find kernel source tree"
42276846Simp.endif
43276846Simp
44276846Simp.SUFFIXES: .dtb .dts
45276846Simp
46276846Simp.PATH: ${SYSDIR}/gnu/dts/${MACHINE} ${SYSDIR}/boot/fdt/dts/${MACHINE}
47276846Simp
48276846SimpDTB=${DTS:R:S/$/.dtb/}
49276846Simp
50276846Simpall: ${DTB}
51276846Simp
52276846Simp.if defined(DTS)
53276846Simp.for _dts in ${DTS}
54276846Simp${_dts:R:S/$/.dtb/}:	${_dts}
55276846Simp	@echo Generating ${.TARGET} from ${_dts}
56276846Simp	@${SYSDIR}/tools/fdt/make_dtb.sh ${SYSDIR} ${_dts} ${.OBJDIR}
57276846SimpCLEANFILES+=${_dts:R:S/$/.dtb/}
58276846Simp.endfor
59276846Simp.endif
60276846Simp
61276846Simp.if !target(install)
62276846Simp.if !target(realinstall)
63276846Simprealinstall: _dtbinstall
64276846Simp.ORDER: beforeinstall _kmodinstall
65276846Simp_dtbinstall:
66284002Simp# Need to create this because installkernel doesn't invoke mtree with BSD.root.mtree
67284002Simp# to make sure the tree is setup properly. This may break ownership of ${DTBDIR}
68284002Simp# for no-root build.
69284002Simp	mkdir -p ${DESTDIR}${DTBDIR}
70276846Simp.for _dtb in ${DTB}
71276846Simp	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
72276846Simp	    ${_INSTALLFLAGS} ${_dtb} ${DESTDIR}${DTBDIR}
73276846Simp.endfor
74276846Simp.endif # !target(realinstall)
75276846Simp.endif # !target(install)
76276846Simp
77276846Simp.include <bsd.dep.mk>
78276846Simp.include <bsd.obj.mk>
79