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