This is simply GregFrost's Parametric Involute Bevel and Spur Gears script https://www.thingiverse.com/thing:3575 tweaked to remove the 'deprecated' warnings in more recent OpenSCAD (I'm using 2015.03-2).
Also, I wrapped in the fix that's already published in the comments on that thing to remove the bug where teeth don't show on bevel gears in preview, but do show in render.
v5.1: I found another necessary fix that corrects a problem with non-bevel gears specified by circular pitch rather than diametral pitch.
In case you want to know what I've done, I've included the diff output, but just ignore that if it means nothing to you.
So this is just the same as that, but should show teeth on all gears in preview, and doesn't produce compiler warnings on 2015.03-2. In all other respects, and for all parameters and instructions, see https://www.thingiverse.com/thing:3575