What is procedure for installing c++ libraries on OSX Mountain Lion required by NPM Module Canvas?

I am trying to install the canvas npm module, a known trouble maker! It requires three libraries: gif, jpeg, and cairo. This is basically a fresh machine. What is the best way to get these libraries available for use by npm?

$ npm install canvas
npm http GET https://registry.npmjs.org/canvas
npm http 304 https://registry.npmjs.org/canvas

> canvas@0.12.1 preinstall node_modules/canvas
> node-waf configure build

    Checking for program g++ or c++          : /usr/bin/g++ 
    Checking for program cpp                 : /usr/bin/cpp 
    Checking for program ar                  : /usr/bin/ar 
    Checking for program ranlib              : /usr/bin/ranlib 
    Checking for g++                         : ok  
    Checking for node path                   : ok /usr/local/lib/node 
    Checking for node prefix                 : ok /usr/local 
    Checking for library gif                 : not found 
    Checking for library jpeg                : not found 
    Checking for cairo                       : not found 
    node_modules/canvas/wscript:30: error: the configuration failed (see 'node_modules/canvas/build/config.log')

Mac homebrew can get you at least part of the way towards installing those libraries. I know that it can install cairo for you. You might have to adjust some of your library flags when you try to compile canvas, but it might just work out of the box.

Macports did the trick fairly painlessly