1 # $NetBSD: Makefile.image,v 1.38 2014/08/12 11:48:22 martin Exp $
3 # Makefile snippet to build a tree from the provided lists,
4 # and make an ffs file system image from that tree
7 # NETBSDSRCDIR top level of src tree (set by <bsd.own.mk>)
8 # LISTS list file(s) to use
9 # IMAGEDEPENDS depends for ${IMAGE}
10 # IMAGEENDIAN endianness of ${IMAGE}
11 # IMAGESIZE size of ${IMAGE}
12 # MTREECONF mtree specfiles to use to build a master specfile
15 # IMAGE name of target image
16 # IMAGEPREBUILD additional operations to run pre image creation
17 # IMAGEPOSTBUILD operation to run on ${IMAGE} ${.TARGET} after its built
18 # (if this returns non zero, ${.TARGET} is removed)
19 # CRUNCHBIN name of crunchgen(1)ed binary
20 # DESTDIR destination directory
21 # MAKEFS_FLAGS extra options to ${TOOL_MAKEFS}
22 # PARSELISTENV environment variables to set for parselist.awk
23 # WORKDIR directory to build image in to
24 # IMAGETAR tar.gz file to create containing ${IMAGE}'s contents
26 # IMAGE_RELEASEDIR where to install ${IMAGE}.gz
27 # IMAGETAR_RELEASEDIR where to install ${IMAGETAR}
30 .if !defined(_MAKEFILE_IMAGE_)
36 WORKBUILT?= work.built
38 .include "${DISTRIBDIR}/common/Makefile.parselist"
40 PARSELISTENV+= TARGETDIR=${.OBJDIR}/${WORKDIR:Q}
42 GZIP_FLAGS= -9 ${GZIP_N_FLAG}
44 .if !target(${WORKBUILT}) # {
45 ${WORKBUILT}: ${IMAGEDEPENDS} ${WORKSPEC} ${PARSELISTDEP} ${LISTS}
46 # There is a .PHONY ${CRUNCHBIN}, so check if out of date by hand
47 # Default to `.' if ${CRUNCHBIN} isn't set, to always force a rebuild.
48 [ "${.OODATE}" = ${CRUNCHBIN:U.} -a -f ${WORKBUILT} -a ${WORKBUILT} -nt ${CRUNCHBIN:U.} ] || { \
49 ${_MKSHMSG} " build " ${.CURDIR:T}/${WORKDIR}; \
50 rm -rf ${WORKDIR} ${WORKBUILT}; \
51 mkdir -m 755 ${WORKDIR} && \
52 ${TOOL_MTREE} -def ${WORKSPEC} -p ${WORKDIR}/ -UW && \
53 ${PARSELIST} -v mode=populate ${LISTS} | \
54 ${HOST_SH} -e ${POPULATE_DEBUG} \
55 && touch ${WORKBUILT} ; \
58 CLEANFILES+= ${WORKBUILT}
60 clean cleandir distclean: cleanfsimage
65 -rm -rf ${WORKDIR} ${WORKBUILT}
67 .endif # ! target (${WORKBUILT}) # }
69 .if !target(${WORKSPEC}) # {
70 ${WORKSPEC}: ${MTREECONF} ${LISTS} ${PARSELISTDEP}
72 -rm -f ${.TARGET} ${.TARGET}.tmp
73 ( for i in ${MTREECONF}; do \
75 echo "# entries from: $$i" ; \
79 done ) >> ${.TARGET}.tmp
80 ${PARSELIST} -v mode=mtree ${LISTS} >> ${.TARGET}.tmp \
81 && mv ${.TARGET}.tmp ${.TARGET}
83 CLEANFILES+= ${WORKSPEC} ${WORKSPEC}.tmp
84 .endif # ! target (${WORKSPEC}) # }
86 .if defined(IMAGE) # {
87 IMGMAKEFSOPTIONS?= -o bsize=4096,fsize=512
88 ${IMAGE}: ${WORKBUILT}
89 .if defined(IMAGEPREBUILD)
92 [ "${.OODATE}" = ${WORKBUILT} -a -f ${IMAGE} -a ! ${IMAGE} -ot ${WORKBUILT} ] || { \
93 ${_MKSHMSG_CREATE} ${.CURDIR:T}/${.TARGET}; \
94 rm -f ${.TARGET} ${.TARGET}.tmp; \
95 ${TOOL_MAKEFS} -t ffs -B ${IMAGEENDIAN} -s ${IMAGESIZE} -F ${WORKSPEC} \
96 -N ${NETBSDSRCDIR}/etc ${IMGMAKEFSOPTIONS} \
97 -o optimization=space,minfree=0 \
98 ${MAKEFS_FLAGS} ${.TARGET}.tmp ${WORKDIR} \
99 && mv -f ${.TARGET}.tmp ${.TARGET}; \
101 .if defined(IMAGEPOSTBUILD)
102 ${IMAGEPOSTBUILD} || { rm -f ${.TARGET} ; false; }
108 ${IMAGE}.gz: ${IMAGE}
111 ${TOOL_GZIP} ${GZIP_FLAGS} -c ${.ALLSRC} > ${.TARGET}
115 .if defined(IMAGE_RELEASEDIR)
116 release:: check_RELEASEDIR .WAIT ${IMAGE}.gz
117 ${RELEASE_INSTALL} ${IMAGE}.gz \
118 ${RELEASEDIR}/${RELEASEMACHINEDIR}/${IMAGE_RELEASEDIR}
121 CLEANFILES+= ${IMAGE} ${IMAGE}.gz ${IMAGE}.tmp
122 .endif # ! defined(IMAGE) # }
125 .if defined(IMAGETAR) # {
126 ${IMAGETAR}: ${WORKBUILT} ${WORKSPEC} ${IMAGEDEPENDS}
129 GZIP=${GZIP_FLAGS:Q} \
130 ${TOOL_PAX} --use-compress-program=${TOOL_GZIP:Q} \
131 -ON ${NETBSDSRCDIR}/etc -wdM <${.OBJDIR}/${WORKSPEC} \
133 && mv ${.TARGET}.tmp ${.TARGET}
137 CLEANFILES+= ${IMAGETAR} ${IMAGETAR}.tmp
139 .if defined(IMAGETAR_RELEASEDIR)
140 release:: check_RELEASEDIR .WAIT ${IMAGETAR}
141 ${RELEASE_INSTALL} ${IMAGETAR} \
142 ${RELEASEDIR}/${RELEASEMACHINEDIR}/${IMAGETAR_RELEASEDIR}
145 .endif # ! defined(IMAGETAR) # }
148 .endif # _MAKEFILE_IMAGE_