ifeq (@(TUP_ARCH),x86_64)
DEPOT_ARCH = x86_64
endif

ifeq ($(DEPOT_ARCH),)
	error unhandled TUP_ARCH @(TUP_ARCH)
endif

include_rules

: $(DEPOT_DIR)/<raw-archives> |> \
	awk -F '/' 'BEGIN { print "{=}"} {print "//{"$3"={version=\""$4"\",owner=\"@(PUBLIC_USER)\"}}" }' $f \
		<<< %<raw-archives> | dhall > %o\
|> raw.dhall {records}

: $(DEPOT_DIR)/<bin-archives> |> \
	awk -F '/' 'BEGIN { print "{=}"} {print "//{"$3"={version=\""$4"\",owner=\"@(PUBLIC_USER)\"}}" }' $f <<< %<bin-archives> \
		| dhall > %o\
|> bin.dhall {records}

SHORT_SUM = b2sum -l24

: $(DEPOT_DIR)/<pkg> |> \
	echo '{=}' > %o; \
	for d in `dirname %<pkg> | tr ' ' '\n' | sort -u`; do \
		echo $d/`cat $d/.ARCHIVES $d/runtime | $(SHORT_SUM)` | awk -F '/' \
			'{print "//{"$4"={version=\""substr($6,0,6)"\",owner=\"@(PUBLIC_USER)\"}}"}' >> %o; \
	done \
|> pkg.dhall {records}

: | {records} |> !dhall <<< '{bin = { $(DEPOT_ARCH) = ./bin.dhall }, pkg = ./pkg.dhall, raw = ./raw.dhall }' > %o |> $(DEPOT_MANIFEST) $(PUBLIC_DIR)/<manifest>
