#!/bin/bash

REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
source $REPO_DIR/script/bootstrap

if [ -d $KEXT_PATH ] && [ ! -w $KEXT_PATH ]; then
  echo "softu2f.kext owned by root. Removing before build."
  sudo rm -rf $KEXT_PATH
fi

echo "Building softu2f.kext"
if ! xcodebuild -scheme SoftU2FDriver SYMROOT=$BUILD_DIR &> /dev/null; then
  echo "Error building softu2f.kext"
  exit 1
fi
echo "Built softu2f.kext"

echo "Building SoftU2F.app"
if ! xcodebuild -scheme SoftU2F -project SoftU2F.xcodeproj SYMROOT=$BUILD_DIR &> /dev/null; then
  echo "Error building SoftU2F.app"
  exit 1
fi
echo "Built SoftU2F.app"
