add support for reentrant giflib>=5.0 (#4646)

closes #4646