Makefile: Add partitioning targets, open-rc services

This commit is contained in:
Andrea Rogers 2024-10-26 05:09:43 -05:00
commit abf8cf6a8c
5 changed files with 107 additions and 5 deletions

3
.gitmodules vendored
View file

@ -10,3 +10,6 @@
[submodule "modules/aports"] [submodule "modules/aports"]
path = modules/aports path = modules/aports
url = https://git.alpinelinux.org/aports/ url = https://git.alpinelinux.org/aports/
[submodule "modules/bash-util"]
path = modules/bash-util
url = https://github.com/targetdisk/bash-util

View file

@ -1,5 +1,5 @@
ARCH ?= x86_64 ARCH ?= x86_64
PLATFORM ?= UEFI PLATFORM ?= uefi
DESTROOT ?= destroot DESTROOT ?= destroot
REPO ?= repo REPO ?= repo
DOSU ?= sudo DOSU ?= sudo
@ -8,6 +8,38 @@ PKGS ?=
BUSYBOX ?= busybox BUSYBOX ?= busybox
APORTSDIR ?= $(APORTS_MODULE) APORTSDIR ?= $(APORTS_MODULE)
SHELL := /usr/bin/env bash SHELL := /usr/bin/env bash
BLKDEV ?=
ROOTFS_TYPE ?= btrfs
MOUNTPOINT ?= mnt
RUNLEVEL_SYSINIT ?= devfs dmesg mdev hwdrivers
RUNLEVEL_SHUTDOWN ?= killprocs mount-ro savecache
ifeq ($(PLATFORM),raspi)
include mk/raspi.mk
else ifeq ($(PLATFORM),uefi)
include mk/uefi.mk
endif
RUNLEVEL_BOOT_CMDS := $(foreach SERVICE,$(RUNLEVEL_BOOT),\
rc-update add $(SERVICE) boot &&)
RUNLEVEL_SYSINIT_CMDS := $(foreach SERVICE,$(RUNLEVEL_SYSINIT),\
rc-update add $(SERVICE) sysinit &&)
RUNLEVEL_DEFAULT_CMDS := $(foreach SERVICE,$(RUNLEVEL_DEFAULT),\
rc-update add $(SERVICE) default &&)
RUNLEVEL_SHUTDOWN_CMDS := $(foreach SERVICE,$(RUNLEVEL_SHUTDOWN),\
rc-update add $(SERVICE) shutdown &&)
RUNLEVEL_CMDS := $(RUNLEVEL_BOOT_CMDS) $(RUNLEVEL_SYSINIT_CMDS) \
$(RUNLEVEL_DEFAULT_CMDS) $(RUNLEVEL_SHUTDOWN_CMDS) :
ifneq (,$(findstring /dev/mmcblk,$(BLKDEV)))
P := p
else ifneq (,$(findstring /dev/nvme,$(BLKDEV)))
P := p
else
P :=
endif
GIMME_MODULE := git submodule update --init --recursive GIMME_MODULE := git submodule update --init --recursive
@ -15,13 +47,18 @@ ABUILD_MODULE := modules/abuild
ARCH_MODULE := modules/arch-install-scripts ARCH_MODULE := modules/arch-install-scripts
APK_MODULE := modules/apk-tools APK_MODULE := modules/apk-tools
APORTS_MODULE := modules/aports APORTS_MODULE := modules/aports
BASH_UTIL_MODULE := modules/bash-util
ABUILD_SCRIPT := $(ABUILD_MODULE)/abuild ABUILD_SCRIPT := $(ABUILD_MODULE)/abuild
APK_BIN := $(APK_MODULE)/src/apk APK_BIN := $(APK_MODULE)/src/apk
ABUILD := $(BUSYBOX) ash $(CURDIR)/$(ABUILD_SCRIPT) -c -P $(CURDIR)/$(REPO) rootbld ABUILD := $(BUSYBOX) ash $(CURDIR)/$(ABUILD_SCRIPT) -c -P $(CURDIR)/$(REPO) rootbld
ACHROOT := $(ARCH_MODULE)/arch-chroot ACHROOT := $(ARCH_MODULE)/arch-chroot
ACHROOT_CMD := $(DOSU) $(ACHROOT) $(DESTROOT) /bin/sh -c '. /etc/profile'
APK := LD_LIBRARY_PATH=$(APK_MODULE)/src $(APK_BIN) APK := LD_LIBRARY_PATH=$(APK_MODULE)/src $(APK_BIN)
BUTIL := . $(BASH_UTIL_MODULE)
default-target: install
### TOOLS ### ### TOOLS ###
@ -45,6 +82,9 @@ $(ABUILD_MODULE)/Makefile: .gitmodules
$(ABUILD_SCRIPT): $(ABUILD_MODULE)/Makefile $(ABUILD_SCRIPT): $(ABUILD_MODULE)/Makefile
$(MAKE) -j -C $(ABUILD_MODULE) all $(MAKE) -j -C $(ABUILD_MODULE) all
$(BASH_UTIL_MODULE)/Makefile: .gitmodules
$(GIMME_MODULE) -- $(BASH_UTIL_MODULE)
### PORTS TREE ### ### PORTS TREE ###
$(APORTS_MODULE)/README.md: .gitmodules $(APORTS_MODULE)/README.md: .gitmodules
@ -56,7 +96,7 @@ aports: $(APORTS_MODULE)/README.md
# Something will go here... # Something will go here...
### INSTALLATION ### ### BOOTSTRAPPING ###
$(DESTROOT): $(DESTROOT):
mkdir -p $(DESTROOT) || $(DOSU) mkdir -p $(DESTROOT) mkdir -p $(DESTROOT) || $(DOSU) mkdir -p $(DESTROOT)
@ -65,16 +105,51 @@ $(DESTROOT)/.bootstrap-done: $(DESTROOT) $(APK_BIN)
$(DOSU) $(APK) --arch $(ARCH) -X $(ALPINE_REPO) --root $(DESTROOT) \ $(DOSU) $(APK) --arch $(ARCH) -X $(ALPINE_REPO) --root $(DESTROOT) \
-U --allow-untrusted --initdb add alpine-keys $(PKGS) && touch $@ -U --allow-untrusted --initdb add alpine-keys $(PKGS) && touch $@
$(DOSU) $(APK) --arch $(ARCH) -X $(ALPINE_REPO) --root $(DESTROOT) \ $(DOSU) $(APK) --arch $(ARCH) -X $(ALPINE_REPO) --root $(DESTROOT) \
add alpine-base $(PKGS) && touch $@ add alpine-base btrfs-progs e2fsprogs $(PKGS) && touch $@
bootstrap: $(DESTROOT)/.bootstrap-done bootstrap: $(DESTROOT)/.bootstrap-done
### PARTITIONING ###
blkcheck: $(BASH_UTIL_MODULE)/Makefile
@[ -z "$(BLKDEV)" ] && $(BUTIL)/logging.bash \
&& die 'ERROR: Must define BLKDEV env variable!' \
|| :
format: partition
$(DOSU) mkfs.vfat $(BLKDEV)$(P)1
$(DOSU) mkfs.$(ROOTFS_TYPE) $(BLKDEV)$(P)2
$(BLKDEV)$(P)2: partition
### INSTALLATION ###
services: $(DESTROOT)/.bootstrap-done $(ACHROOT)
$(ACHROOT_CMD)' && $(RUNLEVEL_CMDS)'
fastest-repo: $(DESTROOT)/.bootstrap-done $(ACHROOT)
$(ACHROOT_CMD)' && setup-apkrepos -f'
$(MOUNTPOINT):
mkdir -p $@ || $(DOSU) mkdir -p $@
mount: $(BLKDEV)$(P)2 $(MOUNTPOINT)
$(DOSU) mount $(BLKDEV)$(P)2 $(MOUNTPOINT)
$(DOSU) mkdir -p $(MOUNTPOINT)/boot
$(DOSU) mount $(BLKDEV)$(P)1 $(MOUNTPOINT)/boot
install: services fastest-repo
### CLEANLINESS ### ### CLEANLINESS ###
clean: clean:
git submodule deinit -f -- \ git submodule deinit -f -- \
$(APK_MODULE) $(ABUILD_MODULE) $(APORTS_MODULE) $(ARCH_MODULE) $(APK_MODULE) $(ABUILD_MODULE) $(APORTS_MODULE) $(ARCH_MODULE) \
$(BASH_UTIL_MODULE)
$(DOSU) umount mnt/boot || :
$(DOSU) umount mnt || :
$(DOSU) rm -rf destroot/* repo/* $(DOSU) rm -rf destroot/* repo/*
### MAKEY-MAKEY ### ### MAKEY-MAKEY ###
.PHONY: tools bootstrap aports .PHONY: default-target tools bootstrap aports blkcheck format install \
$(PLATFORM_PHONYS)

15
mk/raspi.mk Normal file
View file

@ -0,0 +1,15 @@
ifeq ($(ARCH),aarch64)
else ifeq ($(ARCH),armhf)
else ifeq ($(ARCH),armv7)
else
$(error $(ARCH) is unsupported on the raspi platform)
endif
PLATFORM_PHONYS := partition kernel
RUNLEVEL_BOOT ?= modules bootmisc hostname networking seedrng swap
RUNLEVEL_DEFAULT ?= crond
partition: blkcheck
$(DOSU) fdisk $(BLKDEV) <<<$$'o\nw\n'
$(DOSU) sfdisk $(BLKDEV) <<<$$',1G,c,*\n,,83,\n'

8
mk/uefi.mk Normal file
View file

@ -0,0 +1,8 @@
PLATFORM_PHONYS := partition kernel
RUNLEVEL_BOOT ?= hwclock modules bootmisc hostname networking seedrng swap
RUNLEVEL_DEFAULT ?= acpid crond
partition: blkcheck
$(DOSU) fdisk $(BLKDEV) <<<$$'g\nw\n'
$(DOSU) sfdisk $(BLKDEV) <<<$$',1G,C12A7328-F81F-11D2-BA4B-00A0C93EC93B,*\n,,0FC63DAF-8483-4772-8E79-3D69D8477DE4,\n'

1
modules/bash-util Submodule

@ -0,0 +1 @@
Subproject commit bd3ddab28f6a754e7ffc15e88257614aff0892ff