initrd: Rework build and install stages
[dragonfly.git] / initrd / Makefile
1 INITRD_MAKE=    LC_ALL=C \
2                 make -m ${.CURDIR}/../share/mk
3 INITRD_SUBDIRS= etc
4 RESCUE_SUBDIRS= oinit rescue rescue.libcrypto
5
6 # Temporary directory to stage the files for creating the initrd image.
7 #
8 # NOTE: Do not place this directory in the object tree, so that the entire
9 #       object tree can be exported read-only for upgrading other machines.
10 #
11 TMPDIR?=        /tmp
12 STAGEDIR:=      ${TMPDIR}/initrd_staged.${.MAKE.PID}
13
14
15 all:
16         @echo "--------------------------------------------------------------"
17         @echo ">>> building rescue tools and initrd contents ..."
18         @echo "--------------------------------------------------------------"
19 .for _dir in ${RESCUE_SUBDIRS} ${INITRD_SUBDIRS}
20         (cd ${.CURDIR}/${_dir}; \
21             ${INITRD_MAKE} obj; \
22             ${INITRD_MAKE} depend all)
23 .endfor
24
25
26 install:
27         # If called by 'installworld' (i.e., 'WORLDINSTALL' defined),
28         # do not overwrite the existing ones.
29 .if !(defined(WORLDINSTALL) && exists(${DESTDIR}/rescue/rescue))
30         @echo "--------------------------------------------------------------"
31         @echo ">>> installing rescue tools to ${DESTDIR}/rescue ..."
32         @echo "--------------------------------------------------------------"
33 .for _dir in ${RESCUE_SUBDIRS}
34         (cd ${.CURDIR}/${_dir}; \
35             ${INITRD_MAKE} BINDIR=/rescue install)
36 .endfor
37 .endif
38
39 .if !(defined(WORLDINSTALL) && exists(${DESTDIR}/boot/kernel/initrd.img.gz))
40         @echo "--------------------------------------------------------------"
41         @echo ">>> setting up ${DESTDIR}/boot/kernel/initrd.img.gz ..."
42         @echo "--------------------------------------------------------------"
43         rm -rf ${STAGEDIR}
44 .for _dir in ${INITRD_SUBDIRS}
45         (cd ${.CURDIR}/${_dir}; \
46             mkdir -p ${STAGEDIR}/${_dir}; \
47             ${INITRD_MAKE} BINDIR=${STAGEDIR}/${_dir} DESTDIR="" install)
48 .endfor
49         sh ${.CURDIR}/mkinitrd.sh \
50             -b ${DESTDIR}/boot \
51             -r ${DESTDIR}/rescue \
52             -c ${STAGEDIR}
53         rm -rf ${STAGEDIR}
54 .endif
55
56
57 clean:
58 .for _dir in ${RESCUE_SUBDIRS} ${INITRD_SUBDIRS}
59         (cd ${.CURDIR}/${_dir} && ${INITRD_MAKE} clean cleandepend)
60 .endfor
61
62
63 .ORDER: all install
64 .MAIN: all