1 # $NetBSD: Makefile.image,v 1.31 2009/04/03 22:36:35 perry 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 # IMAGEPOSTBUILD operation to run on ${IMAGE} ${.TARGET} after its built
17 # (if this returns non zero, ${.TARGET} is removed)
18 # CRUNCHBIN name of crunchgen(1)ed binary
19 # DESTDIR destination directory
20 # MAKEFS_FLAGS extra options to ${TOOL_MAKEFS}
21 # PARSELISTENV environment variables to set for parselist.awk
22 # WORKDIR directory to build image in to
23 # IMAGETAR tar.gz file to create containing ${IMAGE}'s contents
25 # IMAGE_RELEASEDIR where to install ${IMAGE}.gz
26 # IMAGETAR_RELEASEDIR where to install ${IMAGETAR}
29 .if !defined(_MAKEFILE_IMAGE_)
35 WORKBUILT?= work.built
37 .include "${DISTRIBDIR}/common/Makefile.parselist"
39 PARSELISTENV+= TARGETDIR=${.OBJDIR}/${WORKDIR:Q}
42 .if !target(${WORKBUILT}) # {
43 ${WORKBUILT}: ${IMAGEDEPENDS} ${WORKSPEC} ${PARSELISTDEP} ${LISTS}
44 # There is a .PHONY ${CRUNCHBIN}, so check if out of date by hand
45 # Default to `.' if ${CRUNCHBIN} isn't set, to always force a rebuild.
46 [ "${.OODATE}" = ${CRUNCHBIN:U.} -a -f ${WORKBUILT} -a ${WORKBUILT} -nt ${CRUNCHBIN:U.} ] || { \
47 ${_MKSHMSG} " build " ${.CURDIR:T}/${WORKDIR}; \
48 rm -rf ${WORKDIR} ${WORKBUILT}; \
49 mkdir -m 755 ${WORKDIR} && \
50 ${TOOL_MTREE} -def ${WORKSPEC} -p ${WORKDIR}/ -UW && \
51 ${PARSELIST} -v mode=populate ${LISTS} | \
52 ${HOST_SH} -e ${POPULATE_DEBUG} \
53 && touch ${WORKBUILT} ; \
56 CLEANFILES+= ${WORKBUILT}
58 clean cleandir distclean: cleanfsimage
63 -rm -rf ${WORKDIR} ${WORKBUILT}
65 .endif # ! target (${WORKBUILT}) # }
67 .if !target(${WORKSPEC}) # {
68 ${WORKSPEC}: ${MTREECONF} ${LISTS} ${PARSELISTDEP}
70 -rm -f ${.TARGET} ${.TARGET}.tmp
71 ( for i in ${MTREECONF}; do \
73 echo "# entries from: $$i" ; \
77 done ) >> ${.TARGET}.tmp
78 ${PARSELIST} -v mode=mtree ${LISTS} >> ${.TARGET}.tmp \
79 && mv ${.TARGET}.tmp ${.TARGET}
81 CLEANFILES+= ${WORKSPEC} ${WORKSPEC}.tmp
82 .endif # ! target (${WORKSPEC}) # }
84 .if defined(IMAGE) # {
85 ${IMAGE}: ${WORKBUILT}
86 [ "${.OODATE}" = ${WORKBUILT} -a -f ${IMAGE} -a ! ${IMAGE} -ot ${WORKBUILT} ] || { \
87 ${_MKSHMSG_CREATE} ${.CURDIR:T}/${.TARGET}; \
88 rm -f ${.TARGET} ${.TARGET}.tmp; \
89 ${TOOL_MAKEFS} -t ffs -B ${IMAGEENDIAN} -s ${IMAGESIZE} -F ${WORKSPEC} \
90 -N ${NETBSDSRCDIR}/etc -o bsize=4096,fsize=512 \
91 -o optimization=space,minfree=0 \
92 ${MAKEFS_FLAGS} ${.TARGET}.tmp ${WORKDIR} \
93 && mv -f ${.TARGET}.tmp ${.TARGET}; \
95 .if defined(IMAGEPOSTBUILD)
96 ${IMAGEPOSTBUILD} || { rm -f ${.TARGET} ; false; }
102 ${IMAGE}.gz: ${IMAGE}
105 gzip -9nc ${.ALLSRC} > ${.TARGET}
109 .if defined(IMAGE_RELEASEDIR)
110 release:: check_RELEASEDIR .WAIT ${IMAGE}.gz
111 ${RELEASE_INSTALL} ${IMAGE}.gz \
112 ${RELEASEDIR}/${RELEASEMACHINEDIR}/${IMAGE_RELEASEDIR}
115 CLEANFILES+= ${IMAGE} ${IMAGE}.gz ${IMAGE}.tmp
116 .endif # ! defined(IMAGE) # }
119 .if defined(IMAGETAR) # {
120 ${IMAGETAR}: ${WORKBUILT} ${WORKSPEC} ${IMAGEDEPENDS}
123 GZIP=-9n ${TOOL_PAX} -ON ${NETBSDSRCDIR}/etc -wdzM <${.OBJDIR}/${WORKSPEC} \
125 && mv ${.TARGET}.tmp ${.TARGET}
129 CLEANFILES+= ${IMAGETAR} ${IMAGETAR}.tmp
131 .if defined(IMAGETAR_RELEASEDIR)
132 release:: check_RELEASEDIR .WAIT ${IMAGETAR}
133 ${RELEASE_INSTALL} ${IMAGETAR} \
134 ${RELEASEDIR}/${RELEASEMACHINEDIR}/${IMAGETAR_RELEASEDIR}
137 .endif # ! defined(IMAGETAR) # }
140 .endif # _MAKEFILE_IMAGE_