]> git.plutz.net Git - blast/blobdiff - Makefile
branch config not wanted in master
[blast] / Makefile
index 887422ca7fe17b56fd69e05b639273eed489cc95..8da2961171dc795d65fbe15b80f4517561a26eba 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,10 +5,13 @@ comma_:= ,
 space_:= ${nul_} ${nul_}
 
 .PHONY: clean .FORCE _target
-.PHONY: _bootloader_raspi _bootloader_pc _bootloader_iso _partition_gpt _partition_raspi
-.PHONY: _squash_modules
-.PHONY: _qemu _bootstrap _install _copy _config _squash _isosquash
-.PHONY: _format _mount _sparse _umount _partcopy _mbr _iso_image
+.PHONY: _qemu _bootstrap _install _copy _config 
+.PHONY: _partition_gpt _partition_raspi _sparse _partcopy _mbr
+.PHONY: _format _format_root _format_boot
+.PHONY: _bootloader_raspi _bootloader_pc _bootloader_iso
+.PHONY: _mount _mount_root _mount_boot _efi_mount
+.PHONY: _umount _umount_root _umount_boot _efi_umount
+.PHONY: _squash_modules _squash _isosquash _iso_image
 
 ARCH := amd64
 BOOTSTRAP := http://cdn.debian.net/debian
@@ -36,12 +39,12 @@ endif
 
 ifndef SOURCES
 define SOURCES := 
-deb    http://cdn.debian.net/debian stretch main
-deb    http://cdn.debian.net/debian buster main
 deb    http://cdn.debian.net/debian ${release} main
 endef
 endif
 
+fstype := ext4
+
 ifdef disk
   VOLUME := ${disk}
   PBOOT := ${disk}1
@@ -99,10 +102,12 @@ else ifdef squash
   _squash: _config
 
 else ifdef iso
-  ISO := iso
+  ISO := ${iso}
   ISOROOT := iso_root/
   SYSROOT := sys_root_${release}/
   CFGROOT := cfg_root/
+  BOOT_MB := 2
+  PBOOT := ${ISOROOT}/efi.img
 
   PACKAGES += squashfs-tools
   
@@ -113,8 +118,12 @@ else ifdef iso
   _copy: _install
   _config: _copy _squash_modules
   _isosquash: _config
+#  ${PBOOT}: ${ISOROOT}
+#  _format_boot: ${PBOOT}
+#  _efi_mount: ${PBOOT} _format_boot
+#  _efi_umount: _config
   _bootloader_iso: _config
-  _iso_image: _bootloader_iso _isosquash
+  _iso_image: _bootloader_iso _isosquash # _efi_umount
 
 else ifdef raspi
   VOLUME := ${raspi}
@@ -132,7 +141,8 @@ else ifdef raspi
   deb  http://archive.raspberrypi.org/debian ${release} main
   endef
 
-  PACKAGES += firmware-brcm80211 libraspberrypi-bin libraspberrypi0 pi-bluetooth raspberrypi-bootloader raspberrypi-kernel
+  PACKAGES += firmware-brcm80211 libraspberrypi-bin libraspberrypi0 pi-bluetooth raspberrypi-bootloader raspberrypi-kernel initramfs-tools nilfs-tools
+  fstype := nilfs2
 
   _target: _umount _config
   
@@ -214,7 +224,7 @@ _norecommends: ${SYSROOT}/etc/apt/apt.conf.d/10norecommends
 
 ${SYSROOT}/etc/apt/apt.conf.d/10norecommends: ${SYSROOT}
        mkdir -p -m 755 "$(dir $@)"
-       printf 'APT::Install-Recommends "false";\n' >"$@"
+       printf 'APT::%s "false";\n' "Install-Recommends" "Keep-Recommends" "Install-Suggests" "Keep-Suggests" >"$@"
        chmod 644 "$@"
 
 ${SYSROOT}/etc/apt/trusted.gpg.d/: ${SYSROOT} _bootstrap
@@ -229,6 +239,9 @@ _install: ${SYSROOT} _aptkeys _norecommends
        chroot "$${SYSROOT}" ln -sf /bin/true /usr/local/sbin/invoke-rc.d
        chroot "$${SYSROOT}" ln -sf /bin/true /usr/sbin/udevadm
        chroot "$${SYSROOT}" apt-get --yes install ${PACKAGES}
+       mkdir -p -m 755 "$${SYSROOT}/var/lib/deborphan/"
+       chroot "$${SYSROOT}" sh -c 'printf "%s\\n" ${PACKAGES} >/var/lib/deborphan/keep'
+       -chroot "$${SYSROOT}" sh -c 'apt-get --yes purge $$(deborphan -an |sed "s;^.* ;;g")'
        chroot "$${SYSROOT}" apt-get --yes --auto-remove purge
        -chroot "$${SYSROOT}" apt-get --yes --auto-remove upgrade
        chroot "$${SYSROOT}" apt-get clean
@@ -241,11 +254,11 @@ _copy: ${SYSROOT} ${CFGROOT}
 _config: ${CFGROOT}
        ln -sf /dev/null "$${CFGROOT}/etc/systemd/network/99-default.link"
        printf '\nsession       optional        pam_mkhomedir.so umask=0027\n' >>"$${CFGROOT}/etc/pam.d/common-session"
-       printf 'LABEL=FSROOT / ext4 auto,nofail,rw 0 0\nLABEL=BOOT /boot vfat auto,nofail,ro 0 0\n' \
+       printf 'LABEL=FSROOT / ${fstype} auto,nofail,rw 0 0\nLABEL=BOOT /boot vfat auto,nofail,ro 0 0\n' \
                >"$${CFGROOT}/etc/fstab"
        chroot "$${CFGROOT}" update-initramfs -u
 
-${SQUASH}: ${CFGROOT} .FORCE
+${SQUASH}: ${CFGROOT}
        -rm "$${SQUASH}"
        mksquashfs "$${CFGROOT}" "$${SQUASH}" -comp xz
 
@@ -255,9 +268,10 @@ _squash_modules: ${CFGROOT}
 _squash: ${SQUASH} _squash_modules
 
 _isosquash: ${ISOROOT}/live/live.squashfs
-${ISOROOT}/live/live.squashfs: ${CFGROOT} ${ISOROOT}
+${ISOROOT}/live/live.squashfs: ${CFGROOT} ${ISOROOT} .FORCE
        -rm "$@"
-       printf '%s\n' boot |mksquashfs "$${CFGROOT}" "$@" -comp xz -ef /dev/stdin
+       { cd "$${CFGROOT}"; printf '%s\n' boot/*; } \
+       | mksquashfs "$${CFGROOT}" "$@" -comp xz -ef /dev/stdin
 
 ${VOLUME}: .FORCE
        ! printf '%s\n' "$${VOLUME}" |grep -q '^/dev/'  # abort if volume should be real device
@@ -285,16 +299,24 @@ _partition_gpt: ${VOLUME}
 
 _sparse: ${PBOOT} ${PROOT}
 
-_format: ${PBOOT} ${PROOT}
-       -umount "$${CFGROOT}/boot" "$${CFGROOT}"
-       mkfs.fat -F 32 -n BOOT "$${PBOOT}"
+ifdef raspi
+_format_root: ${PROOT}
+       -umount "$${CFGROOT}/boot" "$${CFGROOT}" "${PROOT}"
+       mkfs.nilfs2 -f -L FSROOT "$${PROOT}"
+else
+_format_root: ${PROOT}
+       -umount "$${CFGROOT}/boot" "$${CFGROOT}" "${PROOT}"
        mkfs.ext4 -F -L FSROOT "$${PROOT}"
+endif
+
+_format_boot: ${PBOOT}
+       -umount "$${CFGROOT}/boot" "${PBOOT}"
+       mkfs.fat -F 32 -n BOOT "$${PBOOT}"
+
+_format: _format_root _format_boot
 
 _iso_image: ${ISOROOT}
-       xorriso -as mkisofs -o "$${ISO}" -b grub.bin -c boot.cat \
-               -no-emul-boot -boot-load-size 4 -boot-info-table \
-               -eltorito-alt-boot -e efi.img -no-emul-boot \
-               "$${ISOROOT}"
+       grub-mkrescue -o "$${ISO}" "$${ISOROOT}"
 
 .PHONY: _syslinux_efi32 _syslinux_efi64 _syslinux_bios
 .PHONY: _grub_efi32 _grub_efi64
@@ -329,7 +351,7 @@ _grub_efi64: ${CFGROOT}
        grub-mkimage -p / -O x86_64-efi fat part_gpt normal linux all_video >"$${CFGROOT}/boot/EFI/BOOT/BOOTX64.EFI"
 
 ${CFGROOT}/boot/cmdline.txt: ${CFGROOT}
-       printf 'root=/dev/mmcblk0p2 rootfstype=ext4 fsck.repair=yes rootwait' >"$@"
+       printf 'root=/dev/mmcblk0p2 rootfstype=${fstype} fsck.repair=yes rootwait' >"$@"
 
 _bootloader_raspi: ${CFGROOT} ${CFGROOT}/boot/cmdline.txt
 
@@ -347,14 +369,25 @@ _bootloader_pc: ${CFGROOT} _grub_efi32 _grub_efi64 _syslinux_bios #_syslinux_efi
        printf "menuentry 'Rescue' --id 'rescue' {\n linux '/%s' root=LABEL=FSROOT init=/bin/sh\n initrd '/%s'\n}\n" \
                "$$k" "$$i" >>"$${CFGROOT}/boot/grub.cfg"
 
-_bootloader_iso: ${CFGROOT} ${ISOROOT} _grub_efi32 _grub_efi64
-       grub-mkimage -p / -O i386-pc-eltorito biosdisk iso9660 normal linux all_video >"$${ISOROOT}/grub.bin"
-       grub-glue-efi -3 "$${CFGROOT}/boot/EFI/BOOT/BOOTIA32.EFI" -6 "$${CFGROOT}/boot/EFI/BOOT/BOOTX64.EFI" >"$${ISOROOT}/efi.img"
+_bootloader_iso: ${CFGROOT} ${ISOROOT}
+       mkdir -p "$${ISOROOT}/boot/grub/"
        cp -L "$${CFGROOT}/vmlinuz" "$${CFGROOT}/initrd.img" "$${ISOROOT}"
        printf '%s\n' "set timeout=10" "default=buster" \
                "menuentry 'Debian Buster' --id 'buster' {" \
                "linux '/vmlinuz' boot=live" "initrd '/initrd.img'" "}" \
-               >"$${ISOROOT}/grub.cfg"
+               >"$${ISOROOT}/boot/grub/grub.cfg"
+       -[ -f "$${ISOROOT}/install/initrd.gz" -a -f "$${ISOROOT}/install/linux" ] && \
+       printf '%s\n' "menuentry 'Install Debian' --id 'install' {" \
+               "linux '/install/linux'" "initrd '/install/initrd.gz'" "}" \
+               >>"$${ISOROOT}/boot/grub/grub.cfg"
+
+_efi_mount: ${PBOOT}
+       -umount "efi/"
+       mkdir -p -m 755 "efi/"
+       mount -t vfat -o loop "$${PBOOT}" "efi/"
+
+_efi_umount: _efi_mount
+       umount efi/ && rmdir efi/
 
 .PHONY: _syslinux_mbr _grub_mbr
 
@@ -371,24 +404,40 @@ _partcopy: ${VOLUME} ${PROOT} ${PBOOT}
        dd conv=notrunc,sparse bs=1M seek=2 if="$${PBOOT}" of="$${VOLUME}"
        dd conv=notrunc,sparse bs=1M seek=$$((2 + ${BOOT_MB})) if="$${PROOT}" of="$${VOLUME}"
 
-_mount: ${PBOOT} ${PROOT} ${CFG_ROOT}
-       mount -t ext4 "$${PROOT}" "$${CFGROOT}"
+_mount_root: ${PROOT} ${CFGROOT}
+       mountpoint "$${CFGROOT}" \
+       || mount -t ${fstype} "$${PROOT}" "$${CFGROOT}"
        chmod 755 "$${CFGROOT}"
+
+_mount_boot: ${PBOOT}
        mkdir -p -m 755 "$${CFGROOT}/boot"
-       mount -t vfat "$${PBOOT}" "$${CFGROOT}/boot"
+       mountpoint "$${CFGROOT}/boot" \
+       || mount -t vfat "$${PBOOT}" "$${CFGROOT}/boot"
+
+ifdef disk
+  _mount_boot: _mount_root
+endif
+
+_mount: _mount_root _mount_boot
 
-_img_mount:
-       mount -o loop,offset="$$((${BOOT_MB} + 2))"M,sizelimit=${ROOT_MB}M \
-         -t ext4 "$${VOLUME}" "$${CFGROOT}"
+_img_mount: ${CFGROOT}
+       mountpoint "$${CFGROOT}" \
+       || mount -o loop,offset="$$((${BOOT_MB} + 2))"M,sizelimit=${ROOT_MB}M \
+                -t ${fstype} "$${VOLUME}" "$${CFGROOT}"
        chmod 755 "$${CFGROOT}"
        mkdir -p -m 755 "$${CFGROOT}/boot"
-       mount -o loop,offset=2M,sizelimit=${BOOT_MB}M \
-         -t vfat "$${VOLUME}" "$${CFGROOT}/boot"
+       mountpoint "$${CFGROOT}/boot" \
+       || mount -o loop,offset=2M,sizelimit=${BOOT_MB}M \
+                -t vfat "$${VOLUME}" "$${CFGROOT}/boot"
 
-_umount: ${CFGROOT}
+_umount_boot: ${CFGROOT}
        -umount "$${CFGROOT}/boot"
+
+_umount_root: _umount_boot
        umount "$${CFGROOT}" && rmdir "$${CFGROOT}"
 
+_umount: _umount_boot _umount_root
+
 clean:
        [ "$${SYSROOT#/}" ] && [ "$${CFGROOT#/}" ] || false  # (abort receipe)
        -umount img_mount/boot
@@ -397,12 +446,14 @@ clean:
        -umount hdd_mount/boot
        -umount hdd_mount
        -rmdir hdd_mount
-       if [ -d "sys_root_${release}/" ]; then btrfs sub del "sys_root_${release}/" || echo rm -r "sys_root_${release}/"; fi
-       if [ -d "cfg_root/" ]; then btrfs sub del "cfg_root/" || echo rm -r "cfg_root/"; fi
-       if [ -d "rpi_root_${release}/" ]; then btrfs sub del "rpi_root_${release}/" || echo rm -r "rpi_root_${release}/"; fi
+       if [ -d "cfg_root/" ]; then btrfs sub del "cfg_root/" || rm -r "cfg_root/"; fi
+       if [ -d "iso_root/" ]; then btrfs sub del "iso_root/" || rm -r "iso_root/"; fi
+       if [ -d "sys_root_${release}/" ]; then btrfs sub del "sys_root_${release}/" || rm -r "sys_root_${release}/"; fi
+       if [ -d "rpi_root_${release}/" ]; then btrfs sub del "rpi_root_${release}/" || rm -r "rpi_root_${release}/"; fi
        -rm part_boot.img
        -rm part_root.img
        -rm rpi_boot.img
        -rm rpi_root.img
        -[ -f "$${SQUASH}" ] && rm "$${SQUASH}"
        -[ -f "$${VOLUME}" ] && rm "$${VOLUME}"
+       -[ -f "$${ISO}" ] && rm "$${ISO}"