#!/bin/bash
# Remove generated build/install artifacts without touching vendored sources.
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
case "$ROOT" in
  ""|/) printf 'refusing unsafe project root: %s\n' "$ROOT" >&2; exit 1 ;;
esac

for path in "$ROOT/build" "$ROOT"/build-*; do
  [ -e "$path" ] || continue
  printf 'remove %s\n' "$path"
  rm -rf -- "$path"
done

for path in \
  "$ROOT/third_party/build" \
  "$ROOT/third_party/install" \
  "$ROOT"/third_party/install-*; do
  [ -e "$path" ] || continue
  printf 'remove %s\n' "$path"
  rm -rf -- "$path"
done

for path in \
  "$ROOT/webrtcpush_deploy.tar" \
  "$ROOT/webrtcpush_deploy.tar.gz"; do
  [ -e "$path" ] || continue
  printf 'remove %s\n' "$path"
  rm -f -- "$path"
done

printf 'clean complete; third_party/src was preserved\n'
