pass along flags to libuv build + use linker optimizations in optimized builds

Closes #6142