#!/bin/sh
#
# Build a Zenodo-ready distribution archive for Lingenic-Text.
#
# Output: release-zenodo/lingenic-text-VERSION.tar.gz
#
# Usage:  scripts/make-release.sh          (from project root)

set -e

VERSION=$(cat VERSION)
ARCHIVE="lingenic-text-${VERSION}.tar.gz"
OUTDIR="release-zenodo"
ROOT=$(pwd)
PARENT=$(dirname "$ROOT")
DIRNAME=$(basename "$ROOT")

mkdir -p "$OUTDIR"

tar czf "${ROOT}/${OUTDIR}/${ARCHIVE}" \
  -s ",^${DIRNAME},lingenic-text-${VERSION}," \
  --exclude='obj' \
  --exclude='obj-c' \
  --exclude='lib' \
  --exclude='lib-c' \
  --exclude='tests/obj' \
  --exclude='.claude' \
  --exclude='.DS_Store' \
  --exclude='.git' \
  --exclude='.gitignore' \
  --exclude='alire' \
  --exclude='do-not-distribute.txt' \
  --exclude='do-not-keep.txt' \
  --exclude='keep-config.txt' \
  --exclude='release-zenodo' \
  --exclude='docs-writeup/lingenic-text-*' \
  --exclude='tests/c/smoke_test' \
  --exclude='*.aux' \
  --exclude='*.log' \
  --exclude='*.out' \
  --exclude='*.synctex.gz' \
  -C "$PARENT" \
  "$DIRNAME"

SIZE=$(ls -lh "${OUTDIR}/${ARCHIVE}" | awk '{print $5}')
COUNT=$(tar tzf "${OUTDIR}/${ARCHIVE}" | wc -l | tr -d ' ')

echo ""
echo "Created ${OUTDIR}/${ARCHIVE}"
echo "  Size:    ${SIZE}"
echo "  Entries: ${COUNT}"
echo ""
echo "Verify contents:"
echo "  tar tzf ${OUTDIR}/${ARCHIVE} | head -20"
echo "  tar tzf ${OUTDIR}/${ARCHIVE} | grep -v '/$' | wc -l"
