blob: fe5cdcf74e281527429234bf692c672583cbb0d4 [file] [log] [blame]
Nico Huberc0b52db2022-12-15 12:42:32 +00001QUIET_TEST := @
2
3include Makefile.targets
4
5CC := ccache cc
6MAKECMD := make
7MAKEARGS := CONFIG_EVERYTHING=yes
8
9spc :=
10spc := $(spc) $(spc)
11
Nico Huber05f0f7c2023-03-03 17:08:16 +000012# Get stem of multiarch tags of the form `stem[-variation]:arch-version`
13ma_stem = $(word 1,$(subst -,$(spc),$(subst :,$(spc),$(subst \:,$(spc),$(1)))))
14# Get stem of official tags of the form `arch/stem:version`
15official_stem = $(word 2,$(subst /,$(spc),$(subst :,$(spc),$(subst \:,$(spc),$(1)))))
16
17ident = $(subst /,_,$(subst :,_,$(subst \:,_,$(1))))
Nico Huberc0b52db2022-12-15 12:42:32 +000018
Nico Huber6f6a1c32023-03-17 12:56:49 +000019include Makefile.env
Nico Huberc0b52db2022-12-15 12:42:32 +000020include Makefile.anita
21
Nico Huber05f0f7c2023-03-03 17:08:16 +000022# $(1): mani tag
23# $(2): from tag
24# $(3): Dockerfile suffix
Nico Huberc0b52db2022-12-15 12:42:32 +000025define build_template
Nico Huber05f0f7c2023-03-03 17:08:16 +000026Dockerfile.$(call ident,$(1)): Dockerfile.$(3) mani-wrapper.sh
27 $(QUIET_SETUP)sed -e 's|^FROM manibase|FROM $(2)|' $$< >$$@
Nico Huberc0b52db2022-12-15 12:42:32 +000028
29.INTERMEDIATE: Dockerfile.$(call ident,$(1))
30
31$(1)-build: Dockerfile.$(call ident,$(1))
Nico Huberfb433ba2023-03-04 19:09:47 +000032 $(QUIET_SETUP)docker build . -f $$< -t mani/$(1) --build-arg IDENT=$(call ident,$(1)) $$(DOCKER_BUILD_ARGS)
Nico Huberc0b52db2022-12-15 12:42:32 +000033endef
34
35$(foreach tag,$(MULTIARCH_TAGS), \
Nico Huber05f0f7c2023-03-03 17:08:16 +000036 $(eval $(call build_template,$(tag),multiarch/$(tag),$(call ma_stem,$(tag)))))
37
38$(foreach tag,$(OFFICIAL_TAGS), \
39 $(eval $(call build_template,$(tag),$(tag),$(call official_stem,$(tag)))))
Nico Huberc0b52db2022-12-15 12:42:32 +000040
Nico Huberc0b52db2022-12-15 12:42:32 +000041djgpp\:6.1.0-build: %-build: Dockerfile.djgpp mani-wrapper.sh
Nico Huberfb433ba2023-03-04 19:09:47 +000042 $(QUIET_SETUP)docker build . -f $< -t mani/$* --build-arg IDENT=$(call ident,$*)
Nico Huberc0b52db2022-12-15 12:42:32 +000043
Nico Huberfb9c18a2022-12-10 23:59:19 +010044git-check-build $(addsuffix -check-build,$(ALL_TAGS)): %-check-build:
Nico Huberc0b52db2022-12-15 12:42:32 +000045 $(QUIET_SETUP)\
46 [ $$(docker image ls -q mani/$*) ] \
47 || $(MAKE) $*-build $(if $(QUIET_SETUP),>/dev/null 2>/dev/null)
48
Nico Huberc0b52db2022-12-15 12:42:32 +000049$(ALL_TAGS): export QUIET_SETUP=$(QUIET_TEST)
Nico Huber725a19e2022-12-11 00:01:04 +010050$(ALL_TAGS): export TEST_REMOTE?=$(if $(TEST_LOCAL),\
Nico Huberc3b02dc2023-08-12 01:13:45 +020051 git://mani-git/flashprog.git,\
Nico Huber39152af2024-04-20 16:42:33 +020052 https://review.sourcearcade.org/flashprog.git)
Nico Huber25ea7172023-03-03 17:06:30 +000053$(ALL_TAGS): export TEST_REVISION?=$(if $(TEST_LOCAL),HEAD,main)
Nico Huber725a19e2022-12-11 00:01:04 +010054$(ALL_TAGS): %: %-check-build mani-net $(if $(TEST_LOCAL),local-git)
Nico Huberc0b52db2022-12-15 12:42:32 +000055 $(QUIET_TEST)docker rm -f mani_$(call ident,$*) >/dev/null 2>&1 || true
56 $(QUIET_TEST)\
57 docker run \
Nico Huber48b1fde2022-12-11 17:15:27 +000058 $(MANI_DOCKER_ARGS) \
Nico Huberc0b52db2022-12-15 12:42:32 +000059 --env IDENT=$(call ident,$*) \
Nico Huberfb433ba2023-03-04 19:09:47 +000060 --volume manicache:/ccache \
Nico Huberbfe64842022-12-10 23:54:24 +010061 --network=manibuilder \
Nico Huberc0b52db2022-12-15 12:42:32 +000062 --name mani_$(call ident,$*) mani/$* \
Nico Huberaa359a72022-12-10 23:52:46 +010063 "git fetch $(TEST_REMOTE) $(TEST_REVISION) && \
Nico Huberc0b52db2022-12-15 12:42:32 +000064 git checkout FETCH_HEAD && \
Nico Huber61da8c72024-04-21 21:26:38 +020065 export $(ENV_VARS) && \
Nico Huberc0b52db2022-12-15 12:42:32 +000066 $(MAKECMD) clean && $(MAKECMD) -j$${CPUS:-1} CC='$(CC)' \
67 $(if $(STRIP),STRIP='$(STRIP)') \
68 $(if $(LIBS_BASE),LIBS_BASE='$(LIBS_BASE)') \
69 $(MAKEARGS)" \
Nico Huberd4fbbb42022-12-11 17:02:57 +000070 $(if $(QUIET_TEST),>/dev/null 2>&1) \
71 || { RET=$$?; echo $*: $${RET}; exit $${RET}; }
Nico Huberc0b52db2022-12-15 12:42:32 +000072
73$(addsuffix -shell,$(ALL_TAGS)): %-shell: %-check-build
74 $(QUIET_SETUP)\
75 if [ $$(docker ps -a -q -f name=mani_$(call ident,$*)) ]; then \
76 docker commit mani_$(call ident,$*) mani_run/$* && \
77 docker run --rm -it \
Nico Huber48b1fde2022-12-11 17:15:27 +000078 $(MANI_DOCKER_ARGS) \
Nico Huberc0b52db2022-12-15 12:42:32 +000079 --env IDENT=$(call ident,$*) \
Nico Huberfb433ba2023-03-04 19:09:47 +000080 --volume manicache:/ccache \
Nico Huberbfe64842022-12-10 23:54:24 +010081 --network=manibuilder \
Nico Huberc0b52db2022-12-15 12:42:32 +000082 --entrypoint /bin/sh mani_run/$* \
83 /home/mani/mani-wrapper.sh \
84 $(patsubst %,"%",$(SHELL_ARG)); \
85 docker image rm mani_run/$*; \
86 else \
87 docker run --rm -it \
Nico Huber48b1fde2022-12-11 17:15:27 +000088 $(MANI_DOCKER_ARGS) \
Nico Huberc0b52db2022-12-15 12:42:32 +000089 --env IDENT=$(call ident,$*) \
Nico Huberfb433ba2023-03-04 19:09:47 +000090 --volume manicache:/ccache \
Nico Huberbfe64842022-12-10 23:54:24 +010091 --network=manibuilder \
Nico Huberc0b52db2022-12-15 12:42:32 +000092 mani/$* $(patsubst %,"%",$(SHELL_ARG)); \
93 fi
94
95.PHONY: $(foreach s,-build -check-build -shell, $(addsuffix $(s),$(ALL_TAGS)))
96
97register:
98 docker build . \
99 -f Dockerfile.qemu-user-static \
Nico Huber93bffcd2023-03-03 17:15:40 +0000100 -t mani/qemu-user-static
101 docker run --rm --privileged mani/qemu-user-static --reset -p yes
Nico Huberc0b52db2022-12-15 12:42:32 +0000102
Nico Huberbfe64842022-12-10 23:54:24 +0100103mani-net:
104 $(QUIET_SETUP)\
105 if [ -z "$$(docker network ls -qf name=manibuilder)" ]; then \
106 docker network create manibuilder \
107 $(if $(QUIET_SETUP),>/dev/null); \
108 fi
109
Nico Huberfb9c18a2022-12-10 23:59:19 +0100110git-build: Dockerfile.git
111 $(QUIET_SETUP)docker build . -f $< -t mani/git
112
113local-git: TEST_LOCAL_GIT:=$(abspath $(wildcard \
114 $(TEST_LOCAL)$(if $(filter %.git,$(TEST_LOCAL)),,/.git)))
115local-git: git-check-build mani-net
116 $(QUIET_SETUP)\
117 if [ -z "$(TEST_LOCAL_GIT)" ]; then \
118 echo '$${TEST_LOCAL} should point to a Git repository.'; \
119 exit 1; \
120 fi; \
121 if [ -n "$$(docker container ls -qf name=mani-git)" ]; then \
122 if docker inspect -f '{{ .Mounts }}' mani-git | \
123 grep -q ' $(TEST_LOCAL_GIT) '; then \
124 exit 0; \
125 else \
126 docker stop mani-git >/dev/null; \
127 fi; \
128 fi; \
129 docker run --rm --detach \
130 --name mani-git \
Nico Huberc3b02dc2023-08-12 01:13:45 +0200131 --volume=$(TEST_LOCAL_GIT):/git/flashprog.git:ro \
Nico Huberfb9c18a2022-12-10 23:59:19 +0100132 --network=manibuilder \
133 mani/git $(if $(QUIET_SETUP),>/dev/null)
134
135.PHONY: register mani-net git-build local-git