patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Demi Marie Obenour <demiobenour@gmail.com>
To: Spectrum OS Development <devel@spectrum-os.org>
Cc: Demi Marie Obenour <demiobenour@gmail.com>, Alyssa Ross <hi@alyssa.is>
Subject: [PATCH v2 3/3] Common make rules for building erofs images
Date: Wed, 10 Sep 2025 01:29:56 -0400	[thread overview]
Message-ID: <20250910-genfiles-v2-3-37ebe07a3cdc@gmail.com> (raw)
In-Reply-To: <20250910-genfiles-v2-0-37ebe07a3cdc@gmail.com>

Instead of duplicating the logic in three different places, write common
code for all three makefiles to use instead.  This will make future
changes much easier.

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
---
 host/rootfs/Makefile    | 45 +++------------------------------------------
 host/rootfs/default.nix |  1 +
 img/app/Makefile        | 41 ++---------------------------------------
 img/app/default.nix     |  1 +
 lib/erofs.mk            | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 vm/sys/net/Makefile     | 39 ++++-----------------------------------
 vm/sys/net/default.nix  |  1 +
 7 files changed, 61 insertions(+), 116 deletions(-)

diff --git a/host/rootfs/Makefile b/host/rootfs/Makefile
index 795d0018ea2858c4d21a9ec42370597fd102473a..e100c9fa240d76a0210b553f5aaa34de93b05e78 100644
--- a/host/rootfs/Makefile
+++ b/host/rootfs/Makefile
@@ -3,10 +3,8 @@
 
 .POSIX:
 
-include ../../lib/common.mk
-include file-list.mk
-
-dest = build/rootfs.erofs
+basedir = ../..
+include $(basedir)/lib/erofs.mk
 
 DIRS = \
 	dev \
@@ -44,44 +42,7 @@ DIRS = \
 
 FIFOS = etc/s6-linux-init/run-image/service/s6-svscan-log/fifo
 
-BUILD_FILES = build/etc/s6-rc
-
-$(dest): ../../scripts/make-erofs.sh $(PACKAGES_FILE) $(FILES) $(BUILD_FILES) build/empty build/fifo file-list.mk
-	( \
-	    cat $(PACKAGES_FILE) ;\
-	    for file in $(FILES) $(LINKS); do printf '%s\n%s\n' $$file "$${file#image/}"; done ;\
-	    for file in $(BUILD_FILES); do printf '%s\n%s\n' $$file $${file#build/}; done ;\
-	    printf 'build/empty\n%s\n' $(DIRS) ;\
-	    printf 'build/fifo\n%s\n' $(FIFOS) ;\
-	) | ../../scripts/make-erofs.sh $@
-
-build/fifo:
-	mkdir -p build
-	mkfifo -m 0600 $@
-
-build/empty:
-	mkdir -p $@
-
-# s6-rc-compile's input is a directory, but that doesn't play nice
-# with Make, because it won't know to update if some file in the
-# directory is changed, or a file is created or removed in a
-# subdirectory.  Using the whole source directory could also end up
-# including files that aren't intended to be part of the input, like
-# temporary editor files or .license files.  So for all these reasons,
-# only explicitly listed files are made available to s6-rc-compile.
-build/etc/s6-rc: $(S6_RC_FILES) file-list.mk
-	mkdir -p $$(dirname $@)
-	rm -rf $@
-
-	dir=$$(mktemp -d) && \
-	    tar -c $(S6_RC_FILES) | tar -C $$dir -x --strip-components 3 && \
-	    s6-rc-compile $@ $$dir; \
-	    exit=$$?; rm -r $$dir; exit $$exit
-
-clean:
-	-chmod -Rf +w build
-	rm -rf build
-.PHONY: clean
+all: $(dest)
 
 # veritysetup format produces two files, but Make only (portably)
 # supports one output per rule, so we combine the two outputs then
diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix
index 998220d7b6ed322f64ee52c704e71ec9b4643f59..561bf660829dcd5f5e2ee841662727b262d43ed3 100644
--- a/host/rootfs/default.nix
+++ b/host/rootfs/default.nix
@@ -178,6 +178,7 @@ stdenvNoCC.mkDerivation {
     fileset = fileset.intersection src (fileset.unions [
       ./.
       ../../lib/common.mk
+      ../../lib/erofs.mk
       ../../scripts/make-erofs.sh
     ]);
   };
diff --git a/img/app/Makefile b/img/app/Makefile
index 04fbf99c7d2e30527aa54e5e549043d03ce6362b..409c0156bf0d336c17dec6e2324e6fbd6bd4c788 100644
--- a/img/app/Makefile
+++ b/img/app/Makefile
@@ -4,8 +4,8 @@
 
 .POSIX:
 
-include ../../lib/common.mk
-include file-list.mk
+basedir = ../..
+include $(basedir)/lib/erofs.mk
 
 prefix = build/host
 libdir = $(prefix)/lib
@@ -18,7 +18,6 @@ HOST_BUILD_FILES = \
 	$(imgdir)/appvm/vmlinux
 
 all: $(HOST_BUILD_FILES)
-.PHONY: all
 
 $(imgdir)/appvm/vmlinux: $(KERNEL)
 	mkdir -p $$(dirname $@)
@@ -36,33 +35,6 @@ DIRS = dev run proc sys tmp \
 	etc/s6-linux-init/run-image/wait
 FIFOS = etc/s6-linux-init/run-image/service/s6-linux-init-shutdownd/fifo
 
-BUILD_FILES = build/etc/s6-rc
-
-build/fifo:
-	mkdir -p build
-	mkfifo -m 0600 $@
-
-build/empty:
-	mkdir -p $@
-
-build/rootfs.erofs: ../../scripts/make-erofs.sh $(PACKAGES_FILE) $(addprefix image/,$(FILES)) $(BUILD_FILES) build/empty build/fifo file-list.mk
-	( \
-	    cat $(PACKAGES_FILE) ;\
-	    for file in $(FILES) $(LINKS); do printf 'image/%s\n%s\n' $$file $$file; done ;\
-	    for file in $(BUILD_FILES); do printf '%s\n%s\n' $$file $${file#build/}; done ;\
-	    printf 'build/empty\n%s\n' $(DIRS) ;\
-	    printf 'build/fifo\n%s\n' $(FIFOS) ;\
-	) | ../../scripts/make-erofs.sh $@
-
-
-build/etc/s6-rc: $(S6_RC_FILES) file-list.mk
-	mkdir -p $$(dirname $@)
-	rm -rf $@
-
-	dir=$$(mktemp -d) && \
-	    tar -C image -c $(S6_RC_FILES) | tar -C $$dir -x --strip-components 3 && \
-	    s6-rc-compile $@ $$dir; \
-	    exit=$$?; rm -r $$dir; exit $$exit
 
 debug:
 	$(GDB) -q \
@@ -139,14 +111,5 @@ run-crosvm: $(imgdir)/appvm/blk/root.img start-vhost-user-gpu start-virtiofsd
 	    $(KERNEL)
 .PHONY: run-crosvm
 
-update-file-list:
-	../../scripts/genfiles.awk image > file-list.mk
-
-.PHONY: update-file-list
-
 run: run-$(VMM)
 .PHONY: run
-
-clean:
-	rm -rf build
-.PHONY: clean
diff --git a/img/app/default.nix b/img/app/default.nix
index 71a939c1c053ebd37fc02fa4eed49b883d50ef49..8c2a114e6b4db52afe9c92f9adb3d5ec52ea2260 100644
--- a/img/app/default.nix
+++ b/img/app/default.nix
@@ -105,6 +105,7 @@ stdenvNoCC.mkDerivation {
     fileset = lib.fileset.intersection src (lib.fileset.unions [
       ./.
       ../../lib/common.mk
+      ../../lib/erofs.mk
       ../../scripts/make-erofs.sh
       ../../scripts/make-gpt.sh
       ../../scripts/sfdisk-field.awk
diff --git a/lib/erofs.mk b/lib/erofs.mk
new file mode 100644
index 0000000000000000000000000000000000000000..1166e2153eb8fde48558affb2a59198a0f0ea917
--- /dev/null
+++ b/lib/erofs.mk
@@ -0,0 +1,49 @@
+# SPDX-License-Identifier: EUPL-1.2+
+# SPDX-FileCopyrightText: 2021-2024 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2022 Unikie
+# SPDX-FileCopyrightText: 2025 Demi Marie Obenour <demiobenour@gmail.com>
+
+include $(basedir)/lib/common.mk
+include file-list.mk
+BUILD_FILES += build/etc/s6-rc
+dest = build/rootfs.erofs
+
+all:
+.PHONY: all
+$(dest): $(basedir)/scripts/make-erofs.sh $(PACKAGES_FILE) $(FILES) $(BUILD_FILES) build/empty build/fifo file-list.mk
+	set -euo pipefail; ( \
+	    cat $(PACKAGES_FILE);\
+	    for file in $(FILES) $(LINKS); do printf '%s\n%s\n' "$$file" "$${file#image/}"; done;\
+	    for file in $(BUILD_FILES); do printf '%s\n%s\n' "$$file" "$${file#build/}"; done;\
+	    for dir in $(DIRS); do printf 'build/empty\n%s\n' "$$dir"; done;\
+	    for fifo in $(FIFOS); do printf 'build/fifo\n%s\n' "$$fifo"; done;\
+	) | $(basedir)/scripts/make-erofs.sh $@
+
+clean:
+	-chmod -Rf +w build
+	rm -rf build
+.PHONY: clean
+	false
+
+build/fifo:
+	mkdir -p build
+	mkfifo -m 0600 $@
+
+build/empty:
+	mkdir -p $@
+
+# s6-rc-compile's input is a directory, but that doesn't play nice
+# with Make, because it won't know to update if some file in the
+# directory is changed, or a file is created or removed in a
+# subdirectory.  Using the whole source directory could also end up
+# including files that aren't intended to be part of the input, like
+# temporary editor files or .license files.  So for all these reasons,
+# only explicitly listed files are made available to s6-rc-compile.
+build/etc/s6-rc: $(S6_RC_FILES) file-list.mk
+	mkdir -p build/etc
+	rm -rf $@
+	set -euo pipefail; \
+	dir=$$(mktemp -d); \
+	{ tar -c $(S6_RC_FILES) | tar -C "$$dir" -x --strip-components 3;}; \
+	s6-rc-compile $@ $$dir; \
+	exit=$$?; rm -r $$dir; exit $$exit
diff --git a/vm/sys/net/Makefile b/vm/sys/net/Makefile
index 11f9215b58a89569ead0c5cc7a4a24b0cc4eec22..217f95bfeabd80bc6fea1e3264296891ee495ee5 100644
--- a/vm/sys/net/Makefile
+++ b/vm/sys/net/Makefile
@@ -3,21 +3,22 @@
 
 .POSIX:
 
-include ../../../lib/common.mk
-include file-list.mk
+basedir = ../../..
+include $(basedir)/lib/erofs.mk
 
 prefix = build/host
 libdir = $(prefix)/lib
 vmdir = $(libdir)/spectrum/vm
 
 VMM = cloud-hypervisor
+DIRS =
+FIFOS =
 
 HOST_BUILD_FILES = \
 	$(vmdir)/netvm/blk/root.img \
 	$(vmdir)/netvm/vmlinux
 
 all: $(HOST_BUILD_FILES)
-.PHONY: all
 
 $(vmdir)/netvm/vmlinux: $(KERNEL)
 	mkdir -p $$(dirname $@)
@@ -29,29 +30,6 @@ $(vmdir)/netvm/blk/root.img: ../../../scripts/make-gpt.sh ../../../scripts/sfdis
 	    build/rootfs.erofs:root:ea21da27-0391-48da-9235-9d2ab2ca7844:root
 	mv $@.tmp $@
 
-BUILD_FILES = build/etc/s6-rc
-
-build/empty:
-	mkdir -p $@
-
-build/rootfs.erofs: ../../../scripts/make-erofs.sh $(PACKAGES_FILE) $(FILES) $(BUILD_FILES) build/empty file-list.mk
-	( \
-	    cat $(PACKAGES_FILE) ;\
-	    for file in $(FILES) $(LINKS); do printf '%s\n%s\n' $$file "$${file#image/}"; done ;\
-	    for file in $(BUILD_FILES); do printf '%s\n%s\n' $$file $${file#build/}; done ;\
-	    printf 'build/empty\n%s\n' $(DIRS) ;\
-	) | ../../../scripts/make-erofs.sh $@
-
-
-build/etc/s6-rc: $(S6_RC_FILES) file-list.mk
-	mkdir -p $$(dirname $@)
-	rm -rf $@
-
-	dir=$$(mktemp -d) && \
-	    tar -c $(S6_RC_FILES) | tar -C $$dir -x --strip-components 3 && \
-	    s6-rc-compile $@ $$dir; \
-	    exit=$$?; rm -r $$dir; exit $$exit
-
 debug:
 	$(GDB) -q \
 	    -ex 'set substitute-path .. $(LINUX_SRC)' \
@@ -103,14 +81,5 @@ run-crosvm: $(vmdir)/netvm/blk/root.img
 	    $(KERNEL)
 .PHONY: run-crosvm
 
-update-file-list:
-	../../scripts/genfiles.awk image > file-list.mk
-
-.PHONY: update-file-list
-
 run: run-$(VMM)
 .PHONY: run
-
-clean:
-	rm -rf build
-.PHONY: clean
diff --git a/vm/sys/net/default.nix b/vm/sys/net/default.nix
index 7b2b8b1fbb9b9027781812307bed0551b80f5a78..c453f02cb204e97d0627b18c66c29a9767159d40 100644
--- a/vm/sys/net/default.nix
+++ b/vm/sys/net/default.nix
@@ -104,6 +104,7 @@ stdenvNoCC.mkDerivation {
     fileset = lib.fileset.intersection src (lib.fileset.unions [
       ./.
       ../../../lib/common.mk
+      ../../../lib/erofs.mk
       ../../../scripts/make-erofs.sh
       ../../../scripts/make-gpt.sh
       ../../../scripts/sfdisk-field.awk

-- 
2.51.0


  parent reply	other threads:[~2025-09-10  5:37 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-04  1:56 [PATCH 0/4] Generate file lists from a script Demi Marie Obenour
2025-09-04  1:56 ` [PATCH 1/4] Move all files for the image into a subdirectory Demi Marie Obenour
2025-09-04  1:56 ` [PATCH 2/4] Generate makefile file lists from a script Demi Marie Obenour
2025-09-08  9:59   ` Alyssa Ross
2025-09-08 18:45     ` Demi Marie Obenour
2025-09-09 14:51       ` Alyssa Ross
2025-09-04  1:56 ` [PATCH 3/4] Common make rules for building erofs images Demi Marie Obenour
2025-09-08 10:01   ` Alyssa Ross
2025-09-08 18:53     ` Demi Marie Obenour
2025-09-09 14:56       ` Alyssa Ross
2025-09-04  1:56 ` [PATCH 4/4] Use /etc/s6-rc/compiled for compiled s6-rc directory Demi Marie Obenour
2025-09-10  5:29 ` [PATCH v2 0/3] Generate file lists from a script Demi Marie Obenour
2025-09-10  5:29   ` [PATCH v2 1/3] Move all files for the image into a subdirectory Demi Marie Obenour
2025-09-10 18:58     ` Alyssa Ross
2025-09-11 12:21       ` Demi Marie Obenour
2025-09-10  5:29   ` [PATCH v2 2/3] Generate makefile file lists from a script Demi Marie Obenour
2025-09-10  5:29   ` Demi Marie Obenour [this message]
2025-09-11 12:47   ` [PATCH v3 0/4] Generate " Demi Marie Obenour
2025-09-11 12:47     ` [PATCH v3 1/4] Do not ignore errors from tar Demi Marie Obenour
2025-09-17 11:48       ` Alyssa Ross
2025-09-18  2:45         ` Demi Marie Obenour
2025-09-19  7:46           ` Alyssa Ross
2025-09-30 12:59             ` Alyssa Ross
2025-09-19  7:55       ` Alyssa Ross
2025-09-19 19:03         ` Demi Marie Obenour
2025-09-11 12:47     ` [PATCH v3 2/4] Move all files for the image into a subdirectory Demi Marie Obenour
2025-09-17 12:30       ` Alyssa Ross
2025-09-17 12:39       ` Alyssa Ross
2025-09-17 13:03       ` Alyssa Ross
2025-09-11 12:47     ` [PATCH v3 3/4] Generate makefile file lists from a script Demi Marie Obenour
2025-09-11 12:47     ` [PATCH v3 4/4] Common make rules for building erofs images Demi Marie Obenour
2025-09-21  2:23   ` [PATCH v3] Generate file lists from a script Demi Marie Obenour
2025-09-21  8:47     ` Alyssa Ross
2025-09-21 16:51       ` Demi Marie Obenour
2025-09-21 17:07         ` Alyssa Ross
2025-09-21 17:24     ` [PATCH v4] " Demi Marie Obenour
2025-09-25 11:22       ` Alyssa Ross
2025-09-26 16:31       ` [PATCH v5] " Demi Marie Obenour
2025-09-27  8:19         ` Alyssa Ross
2025-09-27  8:42           ` Demi Marie Obenour
2025-09-27 16:22         ` [PATCH v6] " Demi Marie Obenour
2025-09-29  8:12           ` Alyssa Ross
2025-09-29 17:20             ` Demi Marie Obenour
2025-09-29 17:18           ` [PATCH v7] " Demi Marie Obenour
2025-10-01  9:20             ` Alyssa Ross
2025-10-01  9:24               ` Demi Marie Obenour
2025-10-01  9:35             ` Alyssa Ross
2025-10-01 18:30             ` [PATCH v8] " Demi Marie Obenour
2025-10-02  9:46               ` Alyssa Ross
2025-10-02 17:37               ` [PATCH v9] " Demi Marie Obenour
2025-10-03  9:04                 ` Alyssa Ross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250910-genfiles-v2-3-37ebe07a3cdc@gmail.com \
    --to=demiobenour@gmail.com \
    --cc=devel@spectrum-os.org \
    --cc=hi@alyssa.is \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).