blob: 5611de8df41c37415daa43b4ef019df1beeb322f [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
19include Makefile.anita
20
Nico Huber05f0f7c2023-03-03 17:08:16 +000021# $(1): mani tag
22# $(2): from tag
23# $(3): Dockerfile suffix
Nico Huberc0b52db2022-12-15 12:42:32 +000024define build_template
Nico Huber05f0f7c2023-03-03 17:08:16 +000025Dockerfile.$(call ident,$(1)): Dockerfile.$(3) mani-wrapper.sh
26 $(QUIET_SETUP)sed -e 's|^FROM manibase|FROM $(2)|' $$< >$$@
Nico Huberc0b52db2022-12-15 12:42:32 +000027
28.INTERMEDIATE: Dockerfile.$(call ident,$(1))
29
30$(1)-build: Dockerfile.$(call ident,$(1))
Nico Huberfb433ba2023-03-04 19:09:47 +000031 $(QUIET_SETUP)docker build . -f $$< -t mani/$(1) --build-arg IDENT=$(call ident,$(1)) $$(DOCKER_BUILD_ARGS)
Nico Huberc0b52db2022-12-15 12:42:32 +000032endef
33
34$(foreach tag,$(MULTIARCH_TAGS), \
Nico Huber05f0f7c2023-03-03 17:08:16 +000035 $(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 Huberc0b52db2022-12-15 12:42:32 +000039
Nico Huberc0b52db2022-12-15 12:42:32 +000040djgpp\:6.1.0-build: %-build: Dockerfile.djgpp mani-wrapper.sh
Nico Huberfb433ba2023-03-04 19:09:47 +000041 $(QUIET_SETUP)docker build . -f $< -t mani/$* --build-arg IDENT=$(call ident,$*)
Nico Huberc0b52db2022-12-15 12:42:32 +000042
Nico Huberfb9c18a2022-12-10 23:59:19 +010043git-check-build $(addsuffix -check-build,$(ALL_TAGS)): %-check-build:
Nico Huberc0b52db2022-12-15 12:42:32 +000044 $(QUIET_SETUP)\
45 [ $$(docker image ls -q mani/$*) ] \
46 || $(MAKE) $*-build $(if $(QUIET_SETUP),>/dev/null 2>/dev/null)
47
Nico Huberb7501492023-03-17 12:42:16 +000048$(ALMALINUX_TAGS) $(filter centos%,$(MULTIARCH_TAGS)): CC=cc
Nico Huberc0b52db2022-12-15 12:42:32 +000049djgpp\:6.1.0: CC=ccache i586-pc-msdosdjgpp-gcc
50djgpp\:6.1.0: STRIP=i586-pc-msdosdjgpp-strip
51djgpp\:6.1.0: LIBS_BASE=../
52djgpp\:6.1.0: MAKEARGS+=strip CONFIG_JLINK_SPI=no
Nico Huberc0b52db2022-12-15 12:42:32 +000053$(filter alpine% centos%,$(MULTIARCH_TAGS)): MAKEARGS+=CONFIG_JLINK_SPI=no
54$(filter %-xenial %-stretch,$(MULTIARCH_TAGS)): MAKEARGS+=CONFIG_JLINK_SPI=no
55$(filter centos%,$(MULTIARCH_TAGS)): MAKEARGS+=WARNERROR=no
56$(ALL_TAGS): export QUIET_SETUP=$(QUIET_TEST)
Nico Huber725a19e2022-12-11 00:01:04 +010057$(ALL_TAGS): export TEST_REMOTE?=$(if $(TEST_LOCAL),\
58 git://mani-git/flashrom.git,\
59 origin)
Nico Huber25ea7172023-03-03 17:06:30 +000060$(ALL_TAGS): export TEST_REVISION?=$(if $(TEST_LOCAL),HEAD,main)
Nico Huber725a19e2022-12-11 00:01:04 +010061$(ALL_TAGS): %: %-check-build mani-net $(if $(TEST_LOCAL),local-git)
Nico Huberc0b52db2022-12-15 12:42:32 +000062 $(QUIET_TEST)docker rm -f mani_$(call ident,$*) >/dev/null 2>&1 || true
63 $(QUIET_TEST)\
64 docker run \
Nico Huber48b1fde2022-12-11 17:15:27 +000065 $(MANI_DOCKER_ARGS) \
Nico Huberc0b52db2022-12-15 12:42:32 +000066 --env IDENT=$(call ident,$*) \
Nico Huberfb433ba2023-03-04 19:09:47 +000067 --volume manicache:/ccache \
Nico Huberbfe64842022-12-10 23:54:24 +010068 --network=manibuilder \
Nico Huberc0b52db2022-12-15 12:42:32 +000069 --name mani_$(call ident,$*) mani/$* \
Nico Huberaa359a72022-12-10 23:52:46 +010070 "git fetch $(TEST_REMOTE) $(TEST_REVISION) && \
Nico Huberc0b52db2022-12-15 12:42:32 +000071 git checkout FETCH_HEAD && \
72 $(MAKECMD) clean && $(MAKECMD) -j$${CPUS:-1} CC='$(CC)' \
73 $(if $(STRIP),STRIP='$(STRIP)') \
74 $(if $(LIBS_BASE),LIBS_BASE='$(LIBS_BASE)') \
75 $(MAKEARGS)" \
Nico Huberd4fbbb42022-12-11 17:02:57 +000076 $(if $(QUIET_TEST),>/dev/null 2>&1) \
77 || { RET=$$?; echo $*: $${RET}; exit $${RET}; }
Nico Huberc0b52db2022-12-15 12:42:32 +000078
79$(addsuffix -shell,$(ALL_TAGS)): %-shell: %-check-build
80 $(QUIET_SETUP)\
81 if [ $$(docker ps -a -q -f name=mani_$(call ident,$*)) ]; then \
82 docker commit mani_$(call ident,$*) mani_run/$* && \
83 docker run --rm -it \
Nico Huber48b1fde2022-12-11 17:15:27 +000084 $(MANI_DOCKER_ARGS) \
Nico Huberc0b52db2022-12-15 12:42:32 +000085 --env IDENT=$(call ident,$*) \
Nico Huberfb433ba2023-03-04 19:09:47 +000086 --volume manicache:/ccache \
Nico Huberbfe64842022-12-10 23:54:24 +010087 --network=manibuilder \
Nico Huberc0b52db2022-12-15 12:42:32 +000088 --entrypoint /bin/sh mani_run/$* \
89 /home/mani/mani-wrapper.sh \
90 $(patsubst %,"%",$(SHELL_ARG)); \
91 docker image rm mani_run/$*; \
92 else \
93 docker run --rm -it \
Nico Huber48b1fde2022-12-11 17:15:27 +000094 $(MANI_DOCKER_ARGS) \
Nico Huberc0b52db2022-12-15 12:42:32 +000095 --env IDENT=$(call ident,$*) \
Nico Huberfb433ba2023-03-04 19:09:47 +000096 --volume manicache:/ccache \
Nico Huberbfe64842022-12-10 23:54:24 +010097 --network=manibuilder \
Nico Huberc0b52db2022-12-15 12:42:32 +000098 mani/$* $(patsubst %,"%",$(SHELL_ARG)); \
99 fi
100
101.PHONY: $(foreach s,-build -check-build -shell, $(addsuffix $(s),$(ALL_TAGS)))
102
103register:
104 docker build . \
105 -f Dockerfile.qemu-user-static \
Nico Huber93bffcd2023-03-03 17:15:40 +0000106 -t mani/qemu-user-static
107 docker run --rm --privileged mani/qemu-user-static --reset -p yes
Nico Huberc0b52db2022-12-15 12:42:32 +0000108
Nico Huberbfe64842022-12-10 23:54:24 +0100109mani-net:
110 $(QUIET_SETUP)\
111 if [ -z "$$(docker network ls -qf name=manibuilder)" ]; then \
112 docker network create manibuilder \
113 $(if $(QUIET_SETUP),>/dev/null); \
114 fi
115
Nico Huberfb9c18a2022-12-10 23:59:19 +0100116git-build: Dockerfile.git
117 $(QUIET_SETUP)docker build . -f $< -t mani/git
118
119local-git: TEST_LOCAL_GIT:=$(abspath $(wildcard \
120 $(TEST_LOCAL)$(if $(filter %.git,$(TEST_LOCAL)),,/.git)))
121local-git: git-check-build mani-net
122 $(QUIET_SETUP)\
123 if [ -z "$(TEST_LOCAL_GIT)" ]; then \
124 echo '$${TEST_LOCAL} should point to a Git repository.'; \
125 exit 1; \
126 fi; \
127 if [ -n "$$(docker container ls -qf name=mani-git)" ]; then \
128 if docker inspect -f '{{ .Mounts }}' mani-git | \
129 grep -q ' $(TEST_LOCAL_GIT) '; then \
130 exit 0; \
131 else \
132 docker stop mani-git >/dev/null; \
133 fi; \
134 fi; \
135 docker run --rm --detach \
136 --name mani-git \
137 --volume=$(TEST_LOCAL_GIT):/git/flashrom.git:ro \
138 --network=manibuilder \
139 mani/git $(if $(QUIET_SETUP),>/dev/null)
140
141.PHONY: register mani-net git-build local-git