xref: /netbsd/distrib/common/Makefile.mdset (revision ca671511)
1#	$NetBSD: Makefile.mdset,v 1.46 2019/08/12 08:04:28 martin Exp $
2#
3# Makefile snippet to ${TOOL_MDSETIMAGE} file system images into kernels
4#
5
6#
7# Required variables:
8#	NETBSDSRCDIR	Top level of src tree (set by <bsd.own.mk>)
9#	MDSETTARGETS	List of images to ${TOOL_MDSETIMAGE} into kernels,
10#			containing one or more tuples of the form:
11#				KERNEL	IMAGE	FILENAME
12#
13#			The kernel is ${TOOL_MDSETIMAGE} with ${IMAGE},
14#			${STRIP}ped (after the symbols are stored in
15#			${FILENAME}.symbols.gz), and gzipped into
16#			${FILENAME}.gz.
17#
18#			If KERNEL does not contain a `/', use
19#			${KERNOBJDIR}/KERNEL/netbsd as the kernel.
20#
21#			If FILENAME is "-", use "netbsd-${KERNEL}" as
22#			the target name.  This may not be a sensible
23#			name if KERNEL contains a `/'.
24#
25# Optional variables:
26#	MDSET_RELEASEDIR		Where to install release kernels.
27#
28#	MDSET_NOGZIP			If defined, don't gzip any kernels.
29#
30#	MDSET_NOGZIP.${FILENAME}	If defined, don't gzip ${FILENAME}
31#
32#	MDSET_NOIMAGE.${FILENAME}	If defined, don't add ${IMAGE} to
33#					${FILENAME}
34#
35#	MDSET_NOSTRIP			If defined, don't strip any kernels.
36#
37#	MDSET_NOSTRIP.${FILENAME}	If defined, don't strip ${FILENAME}
38#
39#	MDSET_NOSYMBOLS			If defined, don't generate *.symbols.gz
40#
41#	MDSET_NOSYMBOLS.${FILENAME}	If defined, don't generate
42#					${FILENAME}.symbols.gz
43#
44#	MDSET_POST			For each kernel,
45#					execute this after ${NM} / ${STRIP}.
46#					Kernel is available as "${.TARGET}"
47#
48#	MDSET_POST.${FILENAME}		For each kernel named ${FILENAME},
49#					execute this after ${NM} / ${STRIP}.
50#					Kernel is available as "${.TARGET}"
51#
52#	MDSET_SUFFIXES.${FILENAME}	List of extra install kernel suffixes
53#					and build commands to create from
54#					${FILENAME} after its created by
55#					${TOOL_MDSETIMAGE} ; ${NM} ; ${STRIP}:
56#						SUFFIX	COMMANDVAR
57#					"${.TARGET}" is "${FILENAME}.${SUFFIX}"
58#					COMMANDVAR is the name of the variable
59#					containing the command to build
60#					${.TARGET}.
61#
62# Variables modified by this:
63#	KERNELS			List of kernel .gz files to build
64#	KERNELSYMS		List of kernel .symbol.gz files to build
65#
66
67.if !defined(_MAKEFILE_MDSET_)
68_MAKEFILE_MDSET_=1
69
70.include <bsd.kernobj.mk>
71
72# The default is to build for all MDSETTARGETS
73ALL_KERNELS?= +
74
75.for _K _I _F in ${MDSETTARGETS}			# {
76.for currentsel in ${ALL_KERNELS}			# {
77.if ${currentsel} == "+" || ${_K} == ${currentsel}
78
79_KERNEL:=${_K}			# (work around obscure issue in make(1))
80.if (${_KERNEL:M*/*} != "")
81_KERNNAME.${_K}.${_F}:=	${_K}
82.else
83_KERNNAME.${_K}.${_F}:=	${KERNOBJDIR}/${_K}/netbsd
84.endif
85
86_FILENAME:=${_F}		# (work around obscure issue in make(1))
87.if ${_FILENAME} == "-"
88_KERNEL.${_K}.${_F}:=	netbsd-${_K}
89_FILENAME:=		${_KERNEL.${_K}.${_F}}
90.else
91_KERNEL.${_K}.${_F}:=	${_F}
92.endif
93
94.for _S _C in ${MDSET_SUFFIXES.${_F}}		# {
95CLEANFILES+=	${_KERNEL.${_K}.${_F}}.${_S}
96
97${_KERNEL.${_K}.${_F}}.${_S}: ${_KERNEL.${_K}.${_F}} ${MDSET_.${_K}.${_F}.${_S}.deps}
98.if defined(${_C})
99	${${_C}}
100.else
101	@echo "No such variable \"${_C}\""
102	false
103.endif
104
105.if defined(MDSET_NOGZIP.${_FILENAME}) || defined(MDSET_NOGZIP)
106KERNELS+=	${_KERNEL.${_K}.${_F}}.${_S}
107.else							# {
108KERNELS+=	${_KERNEL.${_K}.${_F}}.${_S}.gz
109
110${_KERNEL.${_K}.${_F}}.${_S}.gz: ${_KERNEL.${_K}.${_F}}.${_S}
111	${_MKTARGET_CREATE}
112	-rm -f ${.TARGET}
113	${TOOL_GZIP_N} -9c ${.ALLSRC} > ${.TARGET}
114.endif							# }
115
116.endfor							# }
117
118.if !defined(MDSET_NOSYMBOLS.${_FILENAME}) && !defined(MDSET_NOSYMBOLS)
119KERNELSYMS+=	${_KERNEL.${_K}.${_F}}.symbols.gz
120.endif
121
122.if defined(MDSET_POST.${_FILENAME})
123_POST.${_KERNEL.${_K}.${_F}}:= ${MDSET_POST.${_FILENAME}}
124.elif defined(MDSET_POST)
125_POST.${_KERNEL.${_K}.${_F}}:= ${MDSET_POST}
126.endif
127
128CLEANFILES+=	${_KERNEL.${_K}.${_F}} ${_KERNEL.${_K}.${_F}}.tmp
129
130.if defined(MDSET_NOIMAGE.${_FILENAME})
131${_I}=
132.endif
133
134# Darwin requires a special hack - this is documented in
135# doc/HACKS, and just works around the problems described more
136# fully in http://mail-index.netbsd.org/current-users/2008/06/27/msg003242.html
137OPSYS!= uname -s
138.if ${OPSYS} == "Darwin"
139MDSETIMAGEFLAGS=
140.else
141MDSETIMAGEFLAGS=-v
142.endif
143
144${_KERNEL.${_K}.${_F}}: .NOTMAIN ${_KERNNAME.${_K}.${_F}} ${_I}
145	${_MKTARGET_CREATE} "(from: ${.ALLSRC})"
146	@rm -f ${.TARGET} ${.TARGET}.tmp ${.TARGET}.symbols.gz
147	@cp ${_KERNNAME.${_K}.${_F}} ${.TARGET}.tmp
148.if !defined(MDSET_NOIMAGE.${_FILENAME})
149	${TOOL_MDSETIMAGE} ${MDSETIMAGEFLAGS} ${.TARGET}.tmp ${_I}
150.endif
151.if !defined(MDSET_NOSYMBOLS.${_FILENAME}) && !defined(MDSET_NOSYMBOLS)
152	${NM} ${.TARGET}.tmp | ${TOOL_GZIP_N} -9 > ${.TARGET}.symbols.gz
153.endif
154.if !defined(MDSET_NOSTRIP.${_FILENAME}) && !defined(MDSET_NOSTRIP)
155	${STRIP} -R .eh_frame -R .eh_frame_hdr -R .comment -R .ident ${MDSET_STRIPSECTIONS} ${.TARGET}.tmp
156.endif
157	@mv ${.TARGET}.tmp ${.TARGET}
158.if defined(MDSET_POST.${_FILENAME}) || defined(MDSET_POST)
159	${_POST.${.TARGET}}
160.endif
161
162.if defined(MDSET_NOGZIP.${_FILENAME}) || defined(MDSET_NOGZIP)
163KERNELS+=	${_KERNEL.${_K}.${_F}}
164.else							# {
165KERNELS+=	${_KERNEL.${_K}.${_F}}.gz
166
167${_KERNEL.${_K}.${_F}}.gz: ${_KERNEL.${_K}.${_F}}
168	${_MKTARGET_CREATE}
169	-rm -f ${.TARGET}
170	${TOOL_GZIP_N} -9c ${.ALLSRC} > ${.TARGET}
171.endif							# }
172
173.endif
174.endfor							# }
175.endfor							# }
176
177CLEANFILES+=	${KERNELS} ${KERNELSYMS}
178
179realall: ${KERNELS}
180
181.if defined(MDSET_RELEASEDIR)
182release:: check_RELEASEDIR .WAIT ${KERNELS}
183	test -z "${KERNELS}" || \
184	${RELEASE_INSTALL} ${KERNELS} ${KERNELSYMS} \
185	    ${RELEASEDIR}/${RELEASEMACHINEDIR}/${MDSET_RELEASEDIR}
186.endif
187
188
189.endif	# _MAKEFILE_MDSET_
190