Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 1 | QUIET_TEST := @ |
| 2 | |
| 3 | include Makefile.targets |
| 4 | |
| 5 | CC := ccache cc |
| 6 | MAKECMD := make |
| 7 | MAKEARGS := CONFIG_EVERYTHING=yes |
| 8 | |
| 9 | spc := |
| 10 | spc := $(spc) $(spc) |
| 11 | |
Nico Huber | 05f0f7c | 2023-03-03 17:08:16 +0000 | [diff] [blame] | 12 | # Get stem of multiarch tags of the form `stem[-variation]:arch-version` |
| 13 | ma_stem = $(word 1,$(subst -,$(spc),$(subst :,$(spc),$(subst \:,$(spc),$(1))))) |
| 14 | # Get stem of official tags of the form `arch/stem:version` |
| 15 | official_stem = $(word 2,$(subst /,$(spc),$(subst :,$(spc),$(subst \:,$(spc),$(1))))) |
| 16 | |
| 17 | ident = $(subst /,_,$(subst :,_,$(subst \:,_,$(1)))) |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 18 | |
Nico Huber | 6f6a1c3 | 2023-03-17 12:56:49 +0000 | [diff] [blame] | 19 | include Makefile.env |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 20 | include Makefile.anita |
| 21 | |
Nico Huber | 05f0f7c | 2023-03-03 17:08:16 +0000 | [diff] [blame] | 22 | # $(1): mani tag |
| 23 | # $(2): from tag |
| 24 | # $(3): Dockerfile suffix |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 25 | define build_template |
Nico Huber | 05f0f7c | 2023-03-03 17:08:16 +0000 | [diff] [blame] | 26 | Dockerfile.$(call ident,$(1)): Dockerfile.$(3) mani-wrapper.sh |
| 27 | $(QUIET_SETUP)sed -e 's|^FROM manibase|FROM $(2)|' $$< >$$@ |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 28 | |
| 29 | .INTERMEDIATE: Dockerfile.$(call ident,$(1)) |
| 30 | |
| 31 | $(1)-build: Dockerfile.$(call ident,$(1)) |
Nico Huber | fb433ba | 2023-03-04 19:09:47 +0000 | [diff] [blame] | 32 | $(QUIET_SETUP)docker build . -f $$< -t mani/$(1) --build-arg IDENT=$(call ident,$(1)) $$(DOCKER_BUILD_ARGS) |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 33 | endef |
| 34 | |
| 35 | $(foreach tag,$(MULTIARCH_TAGS), \ |
Nico Huber | 05f0f7c | 2023-03-03 17:08:16 +0000 | [diff] [blame] | 36 | $(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 Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 40 | |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 41 | djgpp\:6.1.0-build: %-build: Dockerfile.djgpp mani-wrapper.sh |
Nico Huber | fb433ba | 2023-03-04 19:09:47 +0000 | [diff] [blame] | 42 | $(QUIET_SETUP)docker build . -f $< -t mani/$* --build-arg IDENT=$(call ident,$*) |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 43 | |
Nico Huber | fb9c18a | 2022-12-10 23:59:19 +0100 | [diff] [blame] | 44 | git-check-build $(addsuffix -check-build,$(ALL_TAGS)): %-check-build: |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 45 | $(QUIET_SETUP)\ |
| 46 | [ $$(docker image ls -q mani/$*) ] \ |
| 47 | || $(MAKE) $*-build $(if $(QUIET_SETUP),>/dev/null 2>/dev/null) |
| 48 | |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 49 | $(ALL_TAGS): export QUIET_SETUP=$(QUIET_TEST) |
Nico Huber | 725a19e | 2022-12-11 00:01:04 +0100 | [diff] [blame] | 50 | $(ALL_TAGS): export TEST_REMOTE?=$(if $(TEST_LOCAL),\ |
Nico Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame^] | 51 | git://mani-git/flashprog.git,\ |
Nico Huber | 725a19e | 2022-12-11 00:01:04 +0100 | [diff] [blame] | 52 | origin) |
Nico Huber | 25ea717 | 2023-03-03 17:06:30 +0000 | [diff] [blame] | 53 | $(ALL_TAGS): export TEST_REVISION?=$(if $(TEST_LOCAL),HEAD,main) |
Nico Huber | 725a19e | 2022-12-11 00:01:04 +0100 | [diff] [blame] | 54 | $(ALL_TAGS): %: %-check-build mani-net $(if $(TEST_LOCAL),local-git) |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 55 | $(QUIET_TEST)docker rm -f mani_$(call ident,$*) >/dev/null 2>&1 || true |
| 56 | $(QUIET_TEST)\ |
| 57 | docker run \ |
Nico Huber | 48b1fde | 2022-12-11 17:15:27 +0000 | [diff] [blame] | 58 | $(MANI_DOCKER_ARGS) \ |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 59 | --env IDENT=$(call ident,$*) \ |
Nico Huber | fb433ba | 2023-03-04 19:09:47 +0000 | [diff] [blame] | 60 | --volume manicache:/ccache \ |
Nico Huber | bfe6484 | 2022-12-10 23:54:24 +0100 | [diff] [blame] | 61 | --network=manibuilder \ |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 62 | --name mani_$(call ident,$*) mani/$* \ |
Nico Huber | aa359a7 | 2022-12-10 23:52:46 +0100 | [diff] [blame] | 63 | "git fetch $(TEST_REMOTE) $(TEST_REVISION) && \ |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 64 | git checkout FETCH_HEAD && \ |
| 65 | $(MAKECMD) clean && $(MAKECMD) -j$${CPUS:-1} CC='$(CC)' \ |
| 66 | $(if $(STRIP),STRIP='$(STRIP)') \ |
| 67 | $(if $(LIBS_BASE),LIBS_BASE='$(LIBS_BASE)') \ |
| 68 | $(MAKEARGS)" \ |
Nico Huber | d4fbbb4 | 2022-12-11 17:02:57 +0000 | [diff] [blame] | 69 | $(if $(QUIET_TEST),>/dev/null 2>&1) \ |
| 70 | || { RET=$$?; echo $*: $${RET}; exit $${RET}; } |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 71 | |
| 72 | $(addsuffix -shell,$(ALL_TAGS)): %-shell: %-check-build |
| 73 | $(QUIET_SETUP)\ |
| 74 | if [ $$(docker ps -a -q -f name=mani_$(call ident,$*)) ]; then \ |
| 75 | docker commit mani_$(call ident,$*) mani_run/$* && \ |
| 76 | docker run --rm -it \ |
Nico Huber | 48b1fde | 2022-12-11 17:15:27 +0000 | [diff] [blame] | 77 | $(MANI_DOCKER_ARGS) \ |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 78 | --env IDENT=$(call ident,$*) \ |
Nico Huber | fb433ba | 2023-03-04 19:09:47 +0000 | [diff] [blame] | 79 | --volume manicache:/ccache \ |
Nico Huber | bfe6484 | 2022-12-10 23:54:24 +0100 | [diff] [blame] | 80 | --network=manibuilder \ |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 81 | --entrypoint /bin/sh mani_run/$* \ |
| 82 | /home/mani/mani-wrapper.sh \ |
| 83 | $(patsubst %,"%",$(SHELL_ARG)); \ |
| 84 | docker image rm mani_run/$*; \ |
| 85 | else \ |
| 86 | docker run --rm -it \ |
Nico Huber | 48b1fde | 2022-12-11 17:15:27 +0000 | [diff] [blame] | 87 | $(MANI_DOCKER_ARGS) \ |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 88 | --env IDENT=$(call ident,$*) \ |
Nico Huber | fb433ba | 2023-03-04 19:09:47 +0000 | [diff] [blame] | 89 | --volume manicache:/ccache \ |
Nico Huber | bfe6484 | 2022-12-10 23:54:24 +0100 | [diff] [blame] | 90 | --network=manibuilder \ |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 91 | mani/$* $(patsubst %,"%",$(SHELL_ARG)); \ |
| 92 | fi |
| 93 | |
| 94 | .PHONY: $(foreach s,-build -check-build -shell, $(addsuffix $(s),$(ALL_TAGS))) |
| 95 | |
| 96 | register: |
| 97 | docker build . \ |
| 98 | -f Dockerfile.qemu-user-static \ |
Nico Huber | 93bffcd | 2023-03-03 17:15:40 +0000 | [diff] [blame] | 99 | -t mani/qemu-user-static |
| 100 | docker run --rm --privileged mani/qemu-user-static --reset -p yes |
Nico Huber | c0b52db | 2022-12-15 12:42:32 +0000 | [diff] [blame] | 101 | |
Nico Huber | bfe6484 | 2022-12-10 23:54:24 +0100 | [diff] [blame] | 102 | mani-net: |
| 103 | $(QUIET_SETUP)\ |
| 104 | if [ -z "$$(docker network ls -qf name=manibuilder)" ]; then \ |
| 105 | docker network create manibuilder \ |
| 106 | $(if $(QUIET_SETUP),>/dev/null); \ |
| 107 | fi |
| 108 | |
Nico Huber | fb9c18a | 2022-12-10 23:59:19 +0100 | [diff] [blame] | 109 | git-build: Dockerfile.git |
| 110 | $(QUIET_SETUP)docker build . -f $< -t mani/git |
| 111 | |
| 112 | local-git: TEST_LOCAL_GIT:=$(abspath $(wildcard \ |
| 113 | $(TEST_LOCAL)$(if $(filter %.git,$(TEST_LOCAL)),,/.git))) |
| 114 | local-git: git-check-build mani-net |
| 115 | $(QUIET_SETUP)\ |
| 116 | if [ -z "$(TEST_LOCAL_GIT)" ]; then \ |
| 117 | echo '$${TEST_LOCAL} should point to a Git repository.'; \ |
| 118 | exit 1; \ |
| 119 | fi; \ |
| 120 | if [ -n "$$(docker container ls -qf name=mani-git)" ]; then \ |
| 121 | if docker inspect -f '{{ .Mounts }}' mani-git | \ |
| 122 | grep -q ' $(TEST_LOCAL_GIT) '; then \ |
| 123 | exit 0; \ |
| 124 | else \ |
| 125 | docker stop mani-git >/dev/null; \ |
| 126 | fi; \ |
| 127 | fi; \ |
| 128 | docker run --rm --detach \ |
| 129 | --name mani-git \ |
Nico Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame^] | 130 | --volume=$(TEST_LOCAL_GIT):/git/flashprog.git:ro \ |
Nico Huber | fb9c18a | 2022-12-10 23:59:19 +0100 | [diff] [blame] | 131 | --network=manibuilder \ |
| 132 | mani/git $(if $(QUIET_SETUP),>/dev/null) |
| 133 | |
| 134 | .PHONY: register mani-net git-build local-git |