]> git.plutz.net Git - blast/blobdiff - Makefile
raspi build, config modules, cli options
[blast] / Makefile
index 03a66ae2432f1a1cc738d660c7ec2a7b4c4ff02c..da5d3e44ef0330c777212c3641f3ca6a1f590180 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,11 @@
-
 DEFAULT: _target
+
+nul_:=
+comma_:=,
+space_:=${nul_} ${nul_}
+
 .PHONY: clean .FORCE
-.PHONY: _qemu _bootstrap _install _copy _config _bootloader _squash
+.PHONY: _qemu _bootstrap _install _copy _config_raspi _config _bootloader _squash
 .PHONY: _target _partition _format _mount _sparse _umount _partcopy _mbr
 
 ARCH := amd64
@@ -18,6 +22,11 @@ endef
 
 PACKAGES := ${PACKAGES} apt btrfs-tools busybox-static bzip2 ca-certificates cron debian-archive-keyring deborphan firmware-linux-free gzip htop ifupdown init iputils-ping irqbalance isc-dhcp-client less make net-tools nmap ntpdate openssh-client psmisc rsync sshfs sudo systemd traceroute unzip vim wget wireless-tools wpasupplicant xz-utils zip
 
+config.mk:
+       cp "config.example" "$@"
+
+include config.mk
+
 ifdef disk
 VOLUME := ${disk}
 PBOOT := ${disk}1
@@ -87,7 +96,7 @@ define SOURCES =
 deb    http://raspbian.raspberrypi.org/raspbian stretch main non-free firmware rpi
 deb    http://archive.raspberrypi.org/debian stretch main
 endef
-PACKAGES := ${PACKAGES} firmware-brcm8011 libraspberrypi-bin libraspberrypi0 pi-bluetooth raspberrypi-bootloader raspberrypi-kernel
+PACKAGES := ${PACKAGES} firmware-brcm80211 libraspberrypi-bin libraspberrypi0 pi-bluetooth raspberrypi-bootloader raspberrypi-kernel
 
 _target: _umount _partcopy _config _install
 
@@ -98,7 +107,8 @@ _sparse:
 _format: _sparse
 _mount: _format
 _copy: _install _mount
-_config: _copy _mount
+_config_raspi: _copy _mount
+_config: _copy _mount _config_raspi
 _umount: _mount _config
 _partition:
 _partcopy: _partition _umount
@@ -109,6 +119,11 @@ _target:
 
 endif
 
+include modules/default.mk
+ifdef modules
+include $(addsuffix .mk, $(addprefix modules/, $(subst ${comma_},${space},${modules})))
+endif
+
 ifeq "${ARCH}" "amd64"
 PACKAGES := ${PACKAGES} linux-image-amd64
 else ifeq "${ARCH}" "i386"
@@ -125,18 +140,21 @@ cfg_root/: sys_root/ _install
        btrfs sub snap "$<" "$@" || mkdir -p "$@"
        chmod 755 "$@"
 
+rpi_root/:
+       btrfs subvol create "$@" || mkdir -p "$@"
+       chmod 755 "$@"
+
 img_mount/:
-       mkdir -p "$@"
+       mkdir -p -m 755 "$@"
        chmod 755 "$@"
 
 hdd_mount/:
-       mkdir -p "$@"
-       chmod 755 "$@"
+       mkdir -p -m 755 "$@"
 
 _qemu: ${SYSROOT}/usr/bin/qemu-arm-static
 ${SYSROOT}/usr/bin/qemu-arm-static: /usr/bin/qemu-arm-static ${SYSROOT}
-       mkdir -p "$${SYSROOT}"/usr/bin
-       chmod 755 "$${SYSROOT}/usr" "$${SYSROOT}/usr/bin"
+       mkdir -p -m 755 "$${SYSROOT}"/usr/bin
+       chmod 755 "$${SYSROOT}"/usr
        cp -p "$<" "$@"
 
 _bootstrap: ${SYSROOT}/bin/sh
@@ -150,12 +168,12 @@ _aptkeys: ${SYSROOT}/etc/apt/trusted.gpg.d/
 _norecommends: ${SYSROOT}/etc/apt/apt.conf.d/10norecommends
 
 ${SYSROOT}/etc/apt/apt.conf.d/10norecommends: ${SYSROOT}
-       mkdir -p "$(dir $@)"
+       mkdir -p -m 755 "$(dir $@)"
        printf 'APT::Install-Recommends "false";\n' >"$@"
        chmod 644 "$@"
 
 ${SYSROOT}/etc/apt/trusted.gpg.d/: ${SYSROOT}
-       mkdir -p "$@"
+       mkdir -p -m 755 "$@"
        cp keys/*.gpg "$@"
 
 _install: ${SYSROOT} _aptkeys _norecommends
@@ -173,10 +191,16 @@ _install: ${SYSROOT} _aptkeys _norecommends
 _copy: ${SYSROOT} ${CFGROOT}
        cp -au "$${SYSROOT}/." "$${CFGROOT}/"
 
-.PHONY: _main_config
-_config: _main_config
-_main_config: ${CFGROOT} cfg_seed/
-       cp -au cfg_seed/. "$${CFGROOT}"
+_config_raspi: ${CFGROOT}/boot/cmdline.txt
+${CFGROOT}/boot/cmdline.txt: ${CFGROOT}
+       printf 'dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet' >"$@"
+
+.PHONY: _common_config
+_config: _common_config
+_common_config: ${CFGROOT} cfg_seed/
+       ln -sf /dev/null "$${CFGROOT}/etc/systemd/network/99-default.link"
+       printf 'LABEL=FSROOT / ext4 auto,nofail,rw 0 0\nLABEL=BOOT /boot vfat auto,nofail,ro 0 0\n' \
+               >"$${CFGROOT}/etc/fstab"
 
 ${SQUASH}: ${CFGROOT}
        -rm "$${SQUASH}"
@@ -243,8 +267,6 @@ _grub_efi64: ${CFGROOT}
        grub-mkimage -p / -O x86_64-efi fat part_gpt normal linux all_video >"$${CFGROOT}/boot/EFI/BOOT/BOOTX64.EFI"
 
 _bootloader: ${CFGROOT} _grub_efi32 _grub_efi64 _syslinux_bios #_syslinux_efi32 _syslinux_efi64
-       # cp -L "$${CFGROOT}/vmlinuz" "$${CFGROOT}/initrd.img" "$${CFGROOT}/boot/"
-       # cp -r cfg_syslinux/. "$${CFGROOT}/"
        printf 'UI menu.c32\nDEFAULT stretch\nTIMEOUT 30\n' >"$${CFGROOT}/boot/bootmenu.cfg"
        printf 'set timeout=3\ndefault=stretch\n\n' >"$${CFGROOT}/boot/grub.cfg"
        k="$$(printf ' %s' "$${CFGROOT}/boot/"vmlinuz-*)"; k="$${k##*/}"; \
@@ -276,10 +298,8 @@ _partcopy: ${VOLUME} ${PROOT} ${PBOOT}
 _mount: ${PBOOT} ${PROOT} ${CFG_ROOT}
        mount -t ext4 "$${PROOT}" "$${CFGROOT}"
        chmod 755 "$${CFGROOT}"
-       mkdir -p "$${CFGROOT}/boot"
-       chmod 755 "$${CFGROOT}/boot"
+       mkdir -p -m 755 "$${CFGROOT}/boot"
        mount -t vfat "$${PBOOT}" "$${CFGROOT}/boot"
-       chmod 755 "$${CFGROOT}/boot"
 
 _umount: ${CFGROOT}
        -umount "$${CFGROOT}/boot"