how do I write a homebrew recipe?
This Homebrew README gives these steps (with links to more information):


  Contributing
  
  In short:
  
  
  Fork Homebrew.
  brew create http://example.com/foo-0.1.tar.gz
  git checkout -b foo
  git commit Library/Formula/foo.rb &amp;&amp; git push
  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)