No empty .Rs/.Re
[netbsd-mini2440.git] / distrib / common / Makefile.image
blobdfa8b835a2fc129edf2d69a29738379a7476b86f
1 #       $NetBSD: Makefile.image,v 1.30 2008/06/23 02:16:53 matt Exp $
3 # Makefile snippet to build a tree from the provided lists,
4 # and make an ffs file system image from that tree
6 # Required variables:
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
14 # Optional variables:
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_)
30 _MAKEFILE_IMAGE_=1
33 WORKDIR?=       work
34 WORKSPEC?=      work.spec
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} ; \
54         }
56 CLEANFILES+=    ${WORKBUILT}
58 clean cleandir distclean: cleanfsimage
60 .PHONY: cleanfsimage
62 cleanfsimage:
63         -rm -rf ${WORKDIR} ${WORKBUILT}
65 .endif  # ! target (${WORKBUILT})                               # }
67 .if !target(${WORKSPEC})                                        # {
68 ${WORKSPEC}: ${MTREECONF} ${LISTS} ${PARSELISTDEP}
69         ${_MKTARGET_CREATE}
70         -rm -f ${.TARGET} ${.TARGET}.tmp
71         ( for i in ${MTREECONF}; do     \
72                 echo "# --" ; \
73                 echo "# entries from: $$i" ; \
74                 echo "#" ; \
75                 cat $$i ;               \
76                 echo "/unset all" ;     \
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}; \
94         }
95 .if defined(IMAGEPOSTBUILD)
96         ${IMAGEPOSTBUILD} || { rm -f ${.TARGET} ; false; }
97 .endif
99 .PHONY: fsimage
100 fsimage: ${IMAGE}
102 ${IMAGE}.gz: ${IMAGE}
103         ${_MKTARGET_CREATE}
104         -rm -f ${.TARGET}
105         gzip -9nc ${.ALLSRC} > ${.TARGET}
107 realall: ${IMAGE}
109 .if defined(IMAGE_RELEASEDIR)
110 release:: check_RELEASEDIR .WAIT ${IMAGE}.gz
111         ${RELEASE_INSTALL} ${IMAGE}.gz \
112             ${RELEASEDIR}/${RELEASEMACHINEDIR}/${IMAGE_RELEASEDIR}
113 .endif
115 CLEANFILES+=    ${IMAGE} ${IMAGE}.gz ${IMAGE}.tmp
116 .endif  # ! defined(IMAGE)                                      # }
119 .if defined(IMAGETAR)                                           # {
120 ${IMAGETAR}: ${WORKBUILT} ${WORKSPEC} ${IMAGEDEPENDS}
121         ${_MKTARGET_CREATE}
122         ( cd ${WORKDIR}; \
123           GZIP=-9n ${TOOL_PAX} -ON ${NETBSDSRCDIR}/etc -wdzM <${.OBJDIR}/${WORKSPEC} \
124         ) > ${.TARGET}.tmp \
125         && mv ${.TARGET}.tmp ${.TARGET}
127 realall: ${IMAGETAR}
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}
135 .endif
137 .endif  # ! defined(IMAGETAR)                                   # }
140 .endif  # _MAKEFILE_IMAGE_