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