Drop main() prototype. Syncs with NetBSD-8
[minix.git] / distrib / common / Makefile.bootcd
blob3059b2fca467a159d46c7602c73035d076e46757
1 #       $NetBSD: Makefile.bootcd,v 1.32 2015/05/29 06:28:50 martin Exp $
3 # Makefile snipped to create a CD/DVD ISO
6 # XXX TODO:
7 # 1) merge with src/distrib/cdrom
8 # 2) teach makefs to add data from more than 1 directory (see below)
11 # Required variables:
12 #       CDBASE          Basename of the iso
14 # Optional variables:
15 #       CDRELEASE       Set to 'true' to include $RELEASEDIR/$MACHINE on the CD
16 #       CDRELEASE_NOISOS Excludes installation/cdrom directory if set
17 #       CDSOURCE        Set to 'true' to include $RELEASEDIR/source on the CD
18 #       CDEXTRA         Set to a list of files or directories containing extra
19 #                       stuff to put on CD (set by build.sh -C flag)
20 #       CDBUILDEXTRA    Set to a list of files or directories containing extra
21 #                       stuff to put on CD (use in Makefiles)
22 #       CDEXTRA_SKIP    A list of file exclusion paths to exclude when copying
23 #                       directories of extra stuff in CDEXTRA AND CDBUILDEXTRA
24 #       BOOT            Defaults to $DESTDIR/usr/mdec/boot
25 #       BOOTXX_CD9660   Defaults to $DESTDIR/usr/mdec/bootxx_cd9660
26 #       CDBOOTOPTIONS   Options for installboot, eg -o console=com0,speed=9600
27 #       CDMAKEFSOPTIONS Options for makefs, eg bootimage=i386;bootxx,no-emul-boot
28 #       CDMAKEFSEXTRAOPTS additional options for makefs, e.g. -F specfile
29 #       CDROMS_RELEASEDIR Where to install ${CDBASE}.iso
30 #       CDINSTKERNEL    instkernel directory (relative to ${.CURDIR})
31 #       CDKERNELS       couples of the form:
32 #                               source  name_on_cd
33 #       CDRUNTIME       files/directories to copy from $DESTDIR onto the CD
34 #       CD_SETS         sets to be extracted onto the CD
35 #       SETS_DIR        where the CD_SETS are found (default provided)
36 # source kernels are copied from ${CDINSTKERNEL} (or its obj dir)
37 # note that as of yet, bootxx_cd9660 can't load kernel names of more than
38 # 8 chars (though they can be in a sub-directory meaning the pathname is
39 # longer than 8 chars)
42 BOOT?=          ${DESTDIR}/usr/mdec/boot
43 BOOTXX_CD9660?= ${DESTDIR}/usr/mdec/bootxx_cd9660
44 CDRELEASE?=     false
45 CDSOURCE?=      false
46 .if ${CDRELEASE} == false
47 CDROMS_RELEASEDIR?=     ${MACHINE}/installation/cdrom
48 .else
49 CDROMS_RELEASEDIR?=     images
50 .endif
51 .if defined(CDRELEASE_NOISOS)
52 CDRELEASE_EXCLUDE=      -s ',./installation/cdrom.*,,gp'
53 .endif
54 .if !defined(CDRELEASE_LIVEIMAGE)
55 CDRELEASE_EXCLUDE+=     -s ',./installation/liveimage.*,,gp'
56 .endif
57 .if !defined(CDRELEASE_INSTALLIMAGE)
58 CDRELEASE_EXCLUDE+=     -s ',./installation/installimage.*,,gp'
59 .endif
61 SETS_DIR?=      ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
63 .include <bsd.own.mk>           # For PRINTOBJDIR
64 .include <bsd.kernobj.mk>       # For KERNSRCDIR
66 DISTRIBVER!=    ${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh
67 DISTRIBREV!=    ${HOST_SH} ${KERNSRCDIR}/conf/osrelease.sh -s
68 CUROBJDIR!=     cd ${.CURDIR} && ${PRINTOBJDIR}
69 ISO_VOLID!=     echo NETBSD_${DISTRIBREV} | tr a-z A-Z
70 PUBLISHER?= The_NetBSD_Project
71 .if defined(CDMAKEFSOPTIONS)
72 _CDMAKEFSOPTIONS=       rockridge,label=${ISO_VOLID},publisher=${PUBLISHER},${CDMAKEFSOPTIONS}
73 .else
74 _CDMAKEFSOPTIONS=       rockridge,label=${ISO_VOLID},publisher=${PUBLISHER}
75 .endif
77 .if ${MKUNPRIVED} == "no"
78 CD_METALOG.unpriv=
79 mtunpriv=
80 .else
81 CD_METALOG.unpriv=-M ${METALOG}.sanitised
82 mtunpriv="-U"
83 .endif
85 # Stuff that should come from elsewhere - XXX where? - HF
86 CP?=            cp
87 RM?=            rm
88 MKDIR?=         mkdir -p
89 CHMOD?=         chmod
90 ECHO?=          echo
92 .if ${CDRELEASE} == false
93 CDIMAGE=        ${CDBASE}.iso
94 .else
95 CDIMAGE=        NetBSD-${DISTRIBVER}-${CDBASE:S/cd$//}.iso
96 .endif
97 WORKSPEC=       fs.spec
99 CLEANFILES+=    ${CDIMAGE}
100 CLEANFILES+=    bootxx.${MACHINE}
101 CLEANFILES+=    ${WORKSPEC}
103 CDSETSENV=      DESTDIR=${DESTDIR:Q} \
104                 MACHINE=${MACHINE:Q} \
105                 MACHINE_ARCH=${MACHINE_ARCH:Q} \
106                 AWK=${TOOL_AWK:Q} \
107                 CKSUM=${TOOL_CKSUM:Q} \
108                 DB=${TOOL_DB:Q} \
109                 HOST_SH=${HOST_SH:Q} \
110                 MAKE=${MAKE:Q} \
111                 MKTEMP=${TOOL_MKTEMP:Q} \
112                 MTREE=${TOOL_MTREE:Q} \
113                 PAX=${TOOL_PAX:Q} \
114                 COMPRESS_PROGRAM=${COMPRESS_PROGRAM:Q} \
115                 GZIP=${GZIP_FLAGS:Q} \
116                 PKG_CREATE=${TOOL_PKG_CREATE:Q} \
117                 SED=${TOOL_SED:Q} \
118                 TSORT=${TSORT:Q} \
119                 MKRUMP=no \
120                 MKCOMPAT=no \
121                 MKDEBUG=no \
122                 MKDEBUGLIB=no
124 CDSETSCMD=      cd ${NETBSDSRCDIR}/distrib/sets && \
125                 ${CDSETSENV} \
126                 ${HOST_SH}
128 .include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
130 .if defined(CDINSTKERNEL)
131 _INSTKERNELNOBJDIR!=    cd ${.CURDIR}/${CDINSTKERNEL} && ${PRINTOBJDIR}
132 .endif
133 .if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
134 .if exists(${DESTDIR}/usr/mdec/boot.${MACHINE})
135 BOOT2=boot.${MACHINE}
136 .else
137 BOOT2=boot
138 .endif
139 .endif
141 prepare:
142         ${MKDIR} "${CUROBJDIR}/cdrom"
143 .if defined(CDKERNELS)
144 .for kernel target in ${CDKERNELS}
145         ${CP} ${_INSTKERNELNOBJDIR}/${kernel} cdrom/${target}
146 .endfor
147 .if exists(${DESTDIR}/usr/mdec/bootxx_cd9660)
148         ${RM} -f cdrom/${BOOT2}
149         ${CP} ${DESTDIR}/usr/mdec/${BOOT2} cdrom/${BOOT2}
150         ${RM} -f bootxx.${MACHINE}
151         ${CP} ${DESTDIR}/usr/mdec/bootxx_cd9660 bootxx.${MACHINE}
152         ${CHMOD} +w bootxx.${MACHINE}
153 .if defined(CDBOOTOPTIONS)
154         ${TOOL_INSTALLBOOT} -m${MACHINE} -e ${CDBOOTOPTIONS} bootxx.${MACHINE}
155 .endif
156 .endif
157 .endif
159 .if ${MAKEVERBOSE} >= 2
160 PAX_v?= -v
161 .else
162 PAX_v?=
163 .endif
165 # Copy $RELEASEDIR/${MACHINE} in the CDROM dir
167 # XXX This could be done a lot easier if makefs(8) could
168 # XXX include more than one directory on the image - HF
170 copy-releasedir:
171         ${RM} -f ${RELEASEDIR}/${CDROMS_RELEASEDIR}/${CDIMAGE}
172         if ${CDRELEASE}; then                                           \
173                 if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then    \
174                         echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
175                         exit 1;                                         \
176                 fi;                                                     \
177                 ${MKDIR} "${CUROBJDIR}/cdrom/${MACHINE}";               \
178                 release_destdir="${CUROBJDIR}/cdrom/${MACHINE}";        \
179                 cd ${RELEASEDIR}/${RELEASEMACHINEDIR};                  \
180                 echo Copying $$(pwd) to $$release_destdir ...;          \
181                 ${TOOL_PAX}                                             \
182                         -rw -pe ${PAX_v}                                \
183                         ${CDRELEASE_EXCLUDE}                            \
184                         . $$release_destdir;                            \
185                 cd "${CUROBJDIR}";                                      \
186         fi
187         if ${CDSOURCE}; then                                            \
188                 if [ ! -d ${RELEASEDIR}/source ]; then                  \
189                         echo "Missing ${RELEASEDIR}/source, aborting";  \
190                         exit 1;                                         \
191                 fi;                                                     \
192                 ${MKDIR} "${CUROBJDIR}/cdrom/source";                   \
193                 release_destdir="${CUROBJDIR}/cdrom/source";            \
194                 cd ${RELEASEDIR}/source;                                \
195                 echo Copying $$(pwd) to $$release_destdir ...;          \
196                 ${TOOL_PAX}                                             \
197                         -rw -pe ${PAX_v}                                \
198                         . $$release_destdir;                            \
199                 cd "${CUROBJDIR}";                                      \
200         fi
201         if [ "X${CDRUNTIME}" != "X" ]; then                             \
202                 release_destdir=$${curdir}/cdrom;                       \
203                 cd $$release_destdir;                                   \
204                 cd ${DESTDIR};                                          \
205                 for cde in ${CDRUNTIME};                                \
206                 do                                                      \
207                         ${TOOL_PAX} -rw -pp ${PAX_v} $${cde} $$release_destdir;\
208                 done;                                                   \
209                 cd "${CUROBJDIR}";                                      \
210         fi
211         if [ "X${CDEXTRA}${CDBUILDEXTRA}" != "X" ]; then                \
212                 skipflag="";                                            \
213                 cdextra_skip="${CDEXTRA_SKIP}";                         \
214                 if [ "X$${cdextra_skip}" != "X" ]; then                 \
215                         rm -f cdskip;                                   \
216                         for skip in $${cdextra_skip};                   \
217                         do                                              \
218                                 echo $${skip} >> cdskip;                \
219                         done;                                           \
220                         skipflag="-X ${CUROBJDIR:Q}/cdskip";            \
221                 fi;                                                     \
222                 cdextra="${CDEXTRA}";                                   \
223                 cdbuildextra="${CDBUILDEXTRA}";                         \
224                 for cde in $${cdextra} $${cdbuildextra};                \
225                 do                                                      \
226                         release_destdir="${CUROBJDIR}/cdrom";           \
227                         if [ -f $${cde} ]; then                         \
228                                 echo Copying $${cde} to $$release_destdir ...;  \
229                                 ${CP} $${cde} $${release_destdir};      \
230                         elif [ -d $${cde} ]; then                       \
231                                 cd $${cde};                             \
232                                 echo Copying $$(pwd) to $$release_destdir ...;  \
233                                 ${TOOL_MTREE} -c $${skipflag} |         \
234                                         ${TOOL_PAX} -rw -pe ${PAX_v} -M \
235                                         $$release_destdir;              \
236                         else                                            \
237                                 echo "Missing $${cde}, aborting";       \
238                                 exit 1;                                 \
239                         fi;                                             \
240                         cd "${CUROBJDIR}";                              \
241                 done;                                                   \
242         fi
243 .if !empty(CD_SETS)
244         ${MKDIR} "${CUROBJDIR}/cdrom/etc/mtree"
245 .for set in ${CD_SETS}
246         if [ -f ${CUROBJDIR:Q}/cdrom/etc/mtree/set.${set} ]; then       \
247                 ${CHMOD} +w ${CUROBJDIR:Q}/cdrom/etc/mtree/set.${set};  \
248         fi;                                                             \
249         ${CDSETSCMD} ./maketars -i "${CUROBJDIR}/cdrom"                 \
250             ${CD_METALOG.unpriv} ${mtunpriv} -N ${NETBSDSRCDIR}/etc     \
251             -F "${CUROBJDIR}/cdrom/etc/mtree"                           \
252             -d "${DESTDIR:S,^$,/,}" ${set}
253 .endfor
254         if [ -d "${CUROBJDIR}/cdrom/var/spool/ftp/hidden" ]; then       \
255                 ${CHMOD} +r "${CUROBJDIR}/cdrom/var/spool/ftp/hidden";  \
256         fi
257 .endif
259 image:
260         @echo Preparing spec files for makefs...
261         ${RM} -f ${WORKSPEC}
262         if [ -d cdrom/etc/mtree ]; then                         \
263                 cat cdrom/etc/mtree/* |                         \
264                     ${TOOL_SED} -e 's/ size=[0-9]*//'           \
265                      -e '/^\.\/etc\/gettytab/d' > ${WORKSPEC};  \
266         fi
267         if [ -r cdrom/dev/MAKEDEV ]; then                       \
268                 ${HOST_SH} cdrom/dev/MAKEDEV -s init |          \
269                     ${TOOL_SED} -e '/^\. type=dir/d'            \
270                         -e 's,^\.,./dev,' >> ${WORKSPEC};       \
271         fi
272 .if defined(SPEC_IN)
273         cat ${SPEC_IN} >> ${WORKSPEC}
274 .endif
275 .if defined(SECONDARY_BOOT)
276         echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
277             >> ${WORKSPEC}
278 .endif
279 .if defined(SPEC_EXTRA)
280         cat ${SPEC_EXTRA} >> ${WORKSPEC}
281 .endif
282         if [ -s ${WORKSPEC} ]; then specarg="-F ${WORKSPEC}"; fi;       \
283         ${TOOL_MAKEFS} -N ${NETBSDSRCDIR}/etc -t cd9660 $${specarg}     \
284                 ${CDMAKEFSEXTRAOPTS} -o ${_CDMAKEFSOPTIONS:Q} ${CDIMAGE} cdrom
286 .if ${CDRELEASE} == false
287 release: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
288         ${MKDIR} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
289         ${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
291 iso_image:
292 .else
293 release:
295 iso_image: prepare .WAIT prepare_md_post .WAIT copy-releasedir .WAIT image_md_pre .WAIT image .WAIT image_md_post
296         ${MKDIR} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
297         ${RELEASE_INSTALL} ${CDIMAGE} ${RELEASEDIR}/${CDROMS_RELEASEDIR}
298 .endif
300 clean:
301         @if [ -d cdrom/var/spool/ftp/hidden ]; then             \
302                 ${CHMOD} +r cdrom/var/spool/ftp/hidden;         \
303         fi      # XXX
304         ${RM} -fr cdrom
306 prepare_md_post: .PHONY
307 image_md_post: .PHONY
308 image_md_pre: .PHONY
310 .include <bsd.prog.mk>