# This Makefile builds all files needed buy the cividesk packages scripts:
# Manifest.csv (format: version,type,vendor/name,location)
# download     (all other artifacts, copied to https://packages.cividesk.com/download)

VERSIONS ?= 6.5 6.16
COMMIT_ID := $(shell git rev-parse --verify --short HEAD)

TEST_DIR ?= ./test
TMP_DIR ?= .

# Variables used by the cividesk packages script as well
export DOWNLOAD_DIR ?= .
export DOWNLOAD_URL ?= .

# Note: do NOT include version OR reference
# as the download location is not persisted on packages
export ARCHIVE ?= platform.zip


all: packages zipfiles
	@echo "Done, do a 'make clean' to tidy things up."

.PHONY: packages patchfiles zipfiles

.SILENT: packages
packages:
	mkdir -p $(DOWNLOAD_DIR)
	echo "Generating packages.json ..."
	( \
	  for version in $(VERSIONS); do \
	    php package.php "platform" "$$version" $(COMMIT_ID); \
	  done \
	) | jq -s 'sort_by(.name, .version)' > $(DOWNLOAD_DIR)/packages.json


.SILENT: zipfiles
zipfiles:
	echo "Zipping extension files ..."
	mkdir -p $(DOWNLOAD_DIR)/packages
	zip -qr $(DOWNLOAD_DIR)/packages/$(ARCHIVE) . -x ".git/*" "$(DOWNLOAD_DIR)/packages*" "$(TEST_DIR)/*"

clean:
	rm -Rf $(DOWNLOAD_DIR)/packages.json $(DOWNLOAD_DIR)/packages/
