#!/bin/sh
set -e

for waf in $(find . -type f -name waf); do
   if grep -q '^#==>$' "${waf}"
   then
      pushd "${waf%/*}"
      python3 ./waf --help > /dev/null
      if [ -e .waf* ]
      then
         mv .waf*/* .
         sed -i '/^#==>$/,$d' waf
         rmdir .waf*
      fi
      find waflib -name "*.pyc" -o -name "__pycache__" | xargs rm -rf
      popd
   fi
done

echo "All waf scripts extracted successfully."
