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