#!/bin/sh

# This script generates rust compatible makefiles from libuv. When upgrading
# libuv, do:
#
# cd $LIBUV_DIR
# git archive --prefix libuv/ $REVISION > libuv.tar.gz
# cd $RUST_DIR/src/rt
# rm -r libuv
# tar -xvf $LIBUV_DIR/libuv.tar.gz
# mkdir -p libuv/build
# svn co http://gyp.googlecode.com/svn build/gyp
# cd ../..
# ./etc/src/gyp_uv

set -e

cd `dirname $0`
cd ../..

args="--depth . -Dlibrary=static_library -Dtarget_arch=ia32"

./src/rt/libuv/build/gyp/gyp src/rt/libuv/uv.gyp $args \
  -f make-mac \
  --generator-output mk/libuv/mac \
  -DOS=mac

./src/rt/libuv/build/gyp/gyp src/rt/libuv/uv.gyp $args \
  -f make-linux \
  --generator-output mk/libuv/unix \
  -DOS=linux

./src/rt/libuv/build/gyp/gyp src/rt/libuv/uv.gyp $args \
  -f make-linux \
  --generator-output mk/libuv/win \
  -DOS=win

# Comment out the gyp auto regeneration
for os in mac unix win; do
  sed -i ".save" \
    -e 's/^\(Makefile: $(srcdir)\/src\/rt\/libuv\/uv\.gyp\)/#\1/' \
    mk/libuv/$os/Makefile

  sed -i ".save" \
    -e 's/^\(	$(call do_cmd,regen_makefile)\)/#\1/' \
    mk/libuv/$os/Makefile

  rm mk/libuv/$os/Makefile.save
done
