To start, let's download the OpenWRT trunk via subversion. Open a terminal window and enter to your build path. If you have no idea what I'm talking about, please follow the instructions on this page to prepare your target disk. You will not be able to build OpenWRT on a standard Mac OS X installation otherwise.

Once you are sure your disk is set up and mounted, type:
cd /Volumes/OpenWRT && svn co svn://svn.openwrt.org/openwrt/trunk/;
cd trunk; scripts/feeds update -a
 
You can continue now continue on to compile the project:
make prereq; make defconfig; make menuconfig
 If you'd like to customize your build now is the time to do so, otherwise save and exit the menu configuration and continue with:
make V=s #Setting V=s will output helpful debug info
If you get an error, run the above command again at least twice before adjusting the system or source files.

While make -j3 V=s should theoretically be faster, parallel compiling the OpenWRT trunk is headache-inducing since packages have components that are build-order dependent. You will end up proceeding with a single make job to build through what the parallel operation couldn't handle. Multiple jobs also make parsing the console output difficult. 


On my Mac OS X 10.8 Mountain Lion system with Xcode 4.6, Macports 2.13, and gcc-4.7; and as of r33531 of OpenWRT without any packages from the feeds installed, the images build flawlessly. 

In the past, however, I ran into trouble building on 10.6 (64-bit) and 10.7; while the development branch of OpenWRT was still 'Attitude Adjustment'. e2fsprogs refused to build on the Mac even when attempting to install through the port file provided by Macports. I believe mtd-utils depended on e2fsprogs, so that proved to be a problem as well.

This can be prevented by running the following with Mac OS X's sed:
sed -i.bak 's/\(^tools.*\)e2fsprogs/\1/;/\/e2fsprogs/s/^/#/' \ /Volumes/OpenWRT/trunk/tools/Makefile
The packages dependencies have been commented out, and everything will compile smoothly once we substitute with Macports' e2fsprogs and ossp-uuid:
cd /Volumes/OpenWRT/trunk/;
mkdir -p staging_dir/host/{lib,include}/e2fsprogs;
cp -R /opt/local/include/ossp staging_dir/host/include/e2fsprogs/;
cp /opt/local/lib/libuuid* staging_dir/host/lib
Then again run:
make V=s
If all goes well there should be router images ready to be flashed in the bin/ directory.
Now that you know your system can compile OpenWRT images sufficiently, you can install packages from the feeds repositories
./scripts/feeds install <package-name>
 I've written a small shell script, for personal use, that will compile the packages that are currently installed on your router and bake in your router running configuration. Save it as a file and run from a shell. You may need to install GNU sed, this is used on an Ubuntu machine.


#!/bin/bash 
DIR=/Volumes/OpenWRT/trunk
IP=192.168.1.1 PRT=22 USR=root 
mkdir -p $DIR/trunk/files
scp -rP$PRT $USR@$IP:/etc $DIR/files
ssh -p$PRT $USR@$IP opkg list-installed | sed 's/^\(.*\) - [0-9a-z].*$/\1/;' | tr '\n' ' ' | xargs $DIR/scripts/feeds install 
 echo -n "Proceed with 'make V=s'"


That's it.