Skip to content

Commit 8ca64bb

Browse files
committed
rules.mk: Use better names in macros
This wasn't possible in initial iterations but after some refactors I thought it might be doable again. Indeed it is and this makes it easier to see whats going on in the macros. Signed-off-by: Manuel Mendez <github@i.m.mmlb.dev>
1 parent 45831e9 commit 8ca64bb

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

rules.mk

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,49 +29,50 @@ hook-bootkit-deps := $(wildcard hook-bootkit/*)
2929
hook-docker-deps := $(wildcard hook-docker/*)
3030

3131
define foreach_mode_arch_rules =
32-
# mode := $(1)
33-
# arch := $(2)
32+
mode := $(1)
33+
arch := $(2)
3434

35-
$$(shell mkdir -p out/$T/$(1)/$(2))
35+
$$(shell mkdir -p out/$T/$(mode)/$(arch))
3636

37-
.PHONY: hook-$(1)-$(2)
38-
image-$(1)-$(2): out/$T/$(1)/$(2)/hook.tar
39-
out/$T/$(1)/$(2)/hook.tar: out/$T/$(1)/$(2)/hook.yaml out/$T/hook-bootkit-$(2) out/$T/hook-docker-$(2)
40-
linuxkit build -docker -arch $(2) -format tar-kernel-initrd -name hook -dir $$(@D) $$<
37+
.PHONY: image-$(mode)-$(arch)
38+
image-$(mode)-$(arch): out/$T/$(mode)/$(arch)/hook.tar
39+
40+
out/$T/$(mode)/$(arch)/hook.tar: out/$T/$(mode)/$(arch)/hook.yaml out/$T/hook-bootkit-$(arch) out/$T/hook-docker-$(arch)
41+
linuxkit build -docker -arch $(arch) -format tar-kernel-initrd -name hook -dir $$(@D) $$<
4142
mv $$(@D)/hook-initrd.tar $$@
4243

43-
out/$T/$(1)/$(2)/cmdline out/$T/$(1)/$(2)/initrd.img out/$T/$(1)/$(2)/kernel: out/$T/$(1)/$(2)/hook.tar
44+
out/$T/$(mode)/$(arch)/cmdline out/$T/$(mode)/$(arch)/initrd.img out/$T/$(mode)/$(arch)/kernel: out/$T/$(mode)/$(arch)/hook.tar
4445
tar xf $$^ -C $$(@D) $$(@F)
4546
touch $$@
4647

47-
out/$T/$(1)/$(2)/hook.yaml: $$(LINUXKIT_CONFIG)
48-
sed '/hook-\(bootkit\|docker\):/ { s|:latest|:$T-$(2)|; s|quay.io/tinkerbell|$(ORG)|; }' $$< > $$@
49-
if [[ $(1) == dbg ]]; then
48+
out/$T/$(mode)/$(arch)/hook.yaml: $$(LINUXKIT_CONFIG)
49+
sed '/hook-\(bootkit\|docker\):/ { s|:latest|:$T-$(arch)|; s|quay.io/tinkerbell|$(ORG)|; }' $$< > $$@
50+
if [[ $(mode) == dbg ]]; then
5051
sed -i '/^\s*#dbg/ s|#dbg||' $$@
5152
fi
5253
endef
5354
$(foreach m,$(modes),$(foreach a,$(arches),$(eval $(call foreach_mode_arch_rules,$m,$a))))
5455

5556
define foreach_arch_rules =
56-
# arch := $(1)
57+
arch := $(1)
5758

58-
debug: dbg-image-$(1)
59-
dbg-image-$(1): out/$T/dbg/$(1)/hook.tar
60-
images: out/$T/rel/$(1)/hook.tar
59+
debug: dbg-image-$(arch)
60+
dbg-image-$(arch): out/$T/dbg/$(arch)/hook.tar
61+
images: out/$T/rel/$(arch)/hook.tar
6162

62-
hook-bootkit: out/$T/hook-bootkit-$(1)
63-
hook-docker: out/$T/hook-docker-$(1)
63+
hook-bootkit: out/$T/hook-bootkit-$(arch)
64+
hook-docker: out/$T/hook-docker-$(arch)
6465

65-
out/$T/hook-bootkit-$(1): $$(hook-bootkit-deps)
66-
out/$T/hook-docker-$(1): $$(hook-docker-deps)
67-
out/$T/hook-bootkit-$(1) out/$T/hook-docker-$(1): platform=linux/$$(lastword $$(subst -, ,$$(notdir $$@)))
68-
out/$T/hook-bootkit-$(1) out/$T/hook-docker-$(1): container=hook-$$(word 2,$$(subst -, ,$$(notdir $$@)))
69-
out/$T/hook-bootkit-$(1) out/$T/hook-docker-$(1):
70-
docker buildx build --platform $$(platform) --load -t $(ORG)/$$(container):$T-$(1) $$(container)
66+
out/$T/hook-bootkit-$(arch): $$(hook-bootkit-deps)
67+
out/$T/hook-docker-$(arch): $$(hook-docker-deps)
68+
out/$T/hook-bootkit-$(arch) out/$T/hook-docker-$(arch): platform=linux/$$(lastword $$(subst -, ,$$(notdir $$@)))
69+
out/$T/hook-bootkit-$(arch) out/$T/hook-docker-$(arch): container=hook-$$(word 2,$$(subst -, ,$$(notdir $$@)))
70+
out/$T/hook-bootkit-$(arch) out/$T/hook-docker-$(arch):
71+
docker buildx build --platform $$(platform) --load -t $(ORG)/$$(container):$T-$(arch) $$(container)
7172
touch $$@
7273

73-
run-$(1): out/$T/dbg/$(1)/hook.tar
74-
run-$(1):
74+
run-$(arch): out/$T/dbg/$(arch)/hook.tar
75+
run-$(arch):
7576
linuxkit run qemu --mem 2048 $$^
7677
endef
7778
$(foreach a,$(arches),$(eval $(call foreach_arch_rules,$a)))

0 commit comments

Comments
 (0)