xref: /freebsd/sys/conf/dtb.mk (revision ca987d4641cdcd7f27e153db17c5bf064934faf5)
1# $FreeBSD$
2#
3# The include file <dtb.mk> handles building and installing dtb files.
4#
5# +++ variables +++
6#
7# DTC		The Device Tree Compiler to use
8#
9# DTS		List of the dts files to build and install.
10#
11# DTBDIR	Base path for dtb modules [/boot/dtb]
12#
13# DTBOWN	.dtb file owner. [${BINOWN}]
14#
15# DTBGRP	.dtb file group. [${BINGRP}]
16#
17# DTBMODE	Module file mode. [${BINMODE}]
18#
19# DESTDIR	The tree where the module gets installed. [not set]
20#
21# +++ targets +++
22#
23# 	install:
24#               install the kernel module; if the Makefile
25#               does not itself define the target install, the targets
26#               beforeinstall and afterinstall may also be used to cause
27#               actions immediately before and after the install target
28#		is executed.
29#
30
31.include <bsd.init.mk>
32# Grab all the options for a kernel build. For backwards compat, we need to
33# do this after bsd.own.mk.
34.include "kern.opts.mk"
35
36DTC?=		dtc
37
38# Search for kernel source tree in standard places.
39.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
40.if !defined(SYSDIR) && exists(${_dir}/kern/)
41SYSDIR=	${_dir:tA}
42.endif
43.endfor
44.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/)
45.error "can't find kernel source tree"
46.endif
47
48.SUFFIXES: .dtb .dts
49
50.PATH: ${SYSDIR}/gnu/dts/${MACHINE} ${SYSDIR}/dts/${MACHINE}
51
52DTB=${DTS:R:S/$/.dtb/}
53
54all: ${DTB}
55
56.if defined(DTS)
57.export DTC
58.for _dts in ${DTS}
59${_dts:R:S/$/.dtb/}:	${_dts} ${OP_META}
60	@echo Generating ${.TARGET} from ${_dts}
61	@${SYSDIR}/tools/fdt/make_dtb.sh ${SYSDIR} ${_dts} ${.OBJDIR}
62CLEANFILES+=${_dts:R:S/$/.dtb/}
63.endfor
64.endif
65
66.if !target(install)
67.if !target(realinstall)
68realinstall: _dtbinstall
69.ORDER: beforeinstall _kmodinstall
70_dtbinstall:
71# Need to create this because installkernel doesn't invoke mtree with BSD.root.mtree
72# to make sure the tree is setup properly. We don't recreate it to avoid duplicate
73# entries in the NO_ROOT case.
74	test -d ${DESTDIR}${DTBDIR} || ${INSTALL} -d -o ${DTBOWN} -g ${DTBGRP} ${DESTDIR}${DTBDIR}
75.for _dtb in ${DTB}
76	${INSTALL} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
77	    ${_INSTALLFLAGS} ${_dtb} ${DESTDIR}${DTBDIR}/
78.endfor
79.endif # !target(realinstall)
80.endif # !target(install)
81
82.include <bsd.dep.mk>
83.include <bsd.obj.mk>
84.include <bsd.links.mk>
85