This is a public domain parametric OpenSCAD script for generating involute spur gears, helical gears, partial gears, and racks. The file defines the module gear(), which makes ordinary gears, helical gears (twisted like a screw), and partial gears (a wedge rather than a full disk). It also defines the module rack(), which creates a bar with teeth that will mesh with the gears, so you can generate a rack and pinion set.
The SCAD file also includes an example gear train. If you use the View/Animate command in OpenSCAD, you can see the gears and rack mesh and rotate together. If you change the number of teeth, the animation still rotates correctly.
This is not as powerful as other gears on Thingiverse, but it's public domain, so you don't have to worry about issues like GPL vs. LGPL. There are lots of missing features. Perhaps someone could build on this to create a public domain gear script with all the bells and whistles.
The given STL file is just an example. In practice, you would use the SCAD file in your own project.
Use the gear() or rack() module. Call the functions defined at the bottom of the file to find out the parameters of the generated gear. Two gears will mesh if they have the same mm_per_tooth and pressure_angle, and if their centers are separated by the sum of their pitch radii. You can find the pitch radius of a gear by calling pitch_radius(). Calling outer_radius() gives the radius of a circle that encloses the entire gear.