From 6cbeb4e42667bb4fd2f8abe6818865e700690d34 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 24 Jul 2022 17:10:10 +0200 Subject: make/user: generate the initrd.tar in a "smarter" way --- Makefile | 27 +++++++++++++-------------- initrd/init.elf | 1 - initrd/testelf.elf | 1 - 3 files changed, 13 insertions(+), 16 deletions(-) delete mode 120000 initrd/init.elf delete mode 120000 initrd/testelf.elf diff --git a/Makefile b/Makefile index 33469c2..81e128d 100644 --- a/Makefile +++ b/Makefile @@ -64,23 +64,22 @@ out/bootstrap: src/user_bootstrap/linker.ld $(call from_sources, src/user_bootst @mkdir -p $(@D) @$(CC) $(LFLAGS) -T $^ -o $@ -initrd/testelf.elf: out/testelf.elf - @# dummy - -initrd/init.elf: out/init.elf - @# dummy - -out/testelf.elf: src/user/linker.ld $(call from_sources, src/user/app/testelf/) $(call from_sources, src/user/lib/) $(call from_sources, src/shared/) - @mkdir -p $(@D) - @$(CC) $(LFLAGS) -Wl,-pie -Wl,-no-dynamic-linker -T $^ -o $@ +define userbin_template = +out/initrd/$(1).elf: src/user/linker.ld $(call from_sources, src/user/app/$(1)/) $(call from_sources, src/user/lib/) $(call from_sources, src/shared/) + @mkdir -p $$(@D) + @$(CC) $(LFLAGS) -Wl,-pie -Wl,-no-dynamic-linker -T $$^ -o $$@ +endef +USERBINS := $(shell ls src/user/app) +$(foreach bin,$(USERBINS),$(eval $(call userbin_template,$(bin)))) -out/init.elf: src/user/linker.ld $(call from_sources, src/user/app/init/) $(call from_sources, src/user/lib/) $(call from_sources, src/shared/) +out/initrd/%: initrd/% @mkdir -p $(@D) - @$(CC) $(LFLAGS) -Wl,-pie -Wl,-no-dynamic-linker -T $^ -o $@ + @cp $< $@ -# TODO automatically resolve symlinks -out/initrd.tar: $(shell find initrd/) out/testelf.elf out/init.elf - cd initrd; tar chf ../$@ * +out/initrd.tar: $(patsubst %,out/%,$(shell find initrd/ -type f)) \ + $(patsubst %,out/initrd/%.elf,$(USERBINS)) + echo $^ + cd out/initrd; tar chf ../initrd.tar * out/fs/boot/init: out/bootstrap out/initrd.tar @mkdir -p $(@D) diff --git a/initrd/init.elf b/initrd/init.elf deleted file mode 120000 index 21a467a..0000000 --- a/initrd/init.elf +++ /dev/null @@ -1 +0,0 @@ -../out/init.elf \ No newline at end of file diff --git a/initrd/testelf.elf b/initrd/testelf.elf deleted file mode 120000 index 8f2f99c..0000000 --- a/initrd/testelf.elf +++ /dev/null @@ -1 +0,0 @@ -../out/testelf.elf \ No newline at end of file -- cgit v1.2.3