ANITA_TAGS := \
	anita\:10.1-sparc64 anita\:10.0-amd64 anita\:10.0-i386 \
	anita\:9.3-amd64 anita\:9.3-i386 \

MULTIARCH_TAGS := \
	$(foreach a,x86_64 aarch64 ppc64le s390x, \
	  $(foreach v,34 33, \
	    fedora\:$(v)-$(a))) \
	$(foreach a,armhf amd64 i386, \
	  debian-debootstrap\:$(a)-bullseye) \
	$(foreach a,ppc64el arm64 armhf amd64, \
	  $(foreach v,jammy focal, \
	    ubuntu-debootstrap\:$(a)-$(v))) \
	$(foreach a,aarch64 armhf amd64 i386, \
	  $(foreach v,v3.14 v3.13 v3.12, \
	    alpine\:$(a)-$(v))) \

ALMALINUX_TAGS := \
	$(foreach a,amd64 arm64v8 ppc64le s390x, \
	  $(foreach v,8 9 10-kitten, \
	    $(a)/almalinux\:$(v)))

OFFICIAL_TAGS := \
	$(ALMALINUX_TAGS) \
	$(foreach a,ppc64le s390x arm64v8 amd64, \
	  $(foreach v,44 43 42 41 40 39 38 37 36 35, \
	    $(a)/fedora\:$(v))) \
	$(foreach a,ppc64le mips64le s390x arm64v8 arm32v7 arm32v5 amd64 i386, \
	  $(a)/debian\:bookworm) \
	$(foreach a,ppc64le riscv64 s390x arm64v8 arm32v7 arm32v5 amd64 i386, \
	  $(a)/debian\:trixie) \
	$(foreach a,amd64 arm32v7 arm64v8 ppc64le s390x, \
	  $(a)/ubuntu\:noble) \
	$(foreach a,amd64 arm32v7 arm64v8 ppc64le riscv64 s390x, \
	  $(a)/ubuntu\:resolute) \
	$(foreach a,ppc64le s390x arm64v8 arm32v7 arm32v6 amd64 i386, \
	  $(foreach v,3.22 3.21 3.20 3.19 3.18 3.17 3.16 3.15, \
	    $(a)/alpine\:$(v))) \

OTHER_TAGS := djgpp\:12.2.0

NONCROSS_TAGS := $(ANITA_TAGS) $(OFFICIAL_TAGS) $(MULTIARCH_TAGS) $(OTHER_TAGS)


ANDROID_TAGS := \
	$(foreach v,23 35, \
	  $(foreach p,armv7a-linux-androideabi \
			$(foreach a,aarch64 i686 x86_64,$(a)-linux-android), \
	    cross-$(p)$(v)-clang))

CROSS_TAGS := $(ANDROID_TAGS)


ALL_TAGS := $(NONCROSS_TAGS) $(CROSS_TAGS)

BROKEN_TAGS := arm64v8/fedora\:35 arm32v6/alpine\:3.15 alpine\:armhf-v3.14

WORKING_TAGS := $(filter-out $(BROKEN_TAGS),$(ALL_TAGS))

arch_filter = $(sort \
	$(foreach arch,$(1), \
	  $(filter-out $(subst $(arch),,$(ALL_TAGS)), $(ALL_TAGS))))

machine_map = \
	$(if $(filter i386 i686 x86,$(1)),i386 x86, \
	$(if $(filter x86_64,$(1)),amd64 i386 x86, \
	$(if $(filter armv7l armv6l,$(1)),armhf, \
	$(if $(filter aarch64,$(1)),aarch64 arm64, \
	$(if $(filter ppc64le,$(1)),ppc64le ppc64el, \
	$(if $(filter ppc,$(1)),powerpc, \
	$(if $(filter mips,$(1)),mips mipsel, \
	$(1))))))))

NATIVE_TAGS := $(call arch_filter,$(call machine_map,$(shell uname -m)))

# for now, build all working targets by default,
# native targets last (faster, better for parallelization)
DEFAULT_TAGS := \
	$(filter-out $(NATIVE_TAGS),$(WORKING_TAGS)) \
	$(filter $(NATIVE_TAGS),$(WORKING_TAGS))

default: $(DEFAULT_TAGS)

native: $(NATIVE_TAGS)

working: $(WORKING_TAGS)

cross: $(CROSS_TAGS)

all: $(ALL_TAGS)

show-default:
	@printf "%s\n" $(DEFAULT_TAGS)

show-native:
	@printf "%s\n" $(NATIVE_TAGS)

show-working:
	@printf "%s\n" $(WORKING_TAGS)

show-cross:
	@printf "%s\n" $(CROSS_TAGS)

show-all:
	@printf "%s\n" $(ALL_TAGS)

.PHONY: default native all
.PHONY: show-default show-native show-all
.PHONY: $(ALL_TAGS)
