how do I write a homebrew recipe?

This Homebrew README gives these steps (with links to more information):

Contributing

In short:

  1. Fork Homebrew.
  2. brew create http://example.com/foo-0.1.tar.gz
  3. git checkout -b foo
  4. git commit Library/Formula/foo.rb && git push
  5. Pull Request.

In long:

  • Formula Cookbook
  • Acceptable Formulae

Homebrew formulas are written in Ruby (tested against Ruby 2.0.0). Knowledge of Ruby certainly helps, but you might be able to get a feel for how to do basic procedures like you outline above just by reading a few existing formulae.

Getting a formula accepted also requires a little knowledge of Git and GitHub pull requests, but is covered How to open a Homebrew pull request (and get it merged)