[HOWTO] Build OpenWRT Trunk from svn on Mac OS X

I recommend followin.

I recommend following these steps
1) Install XCode & Macports
2) Getting a build environment ready
3) Grabbing sources
4) Modifying Makefiles (e2fsprogs really doesn’t like 64-bit Lion, and qemu refuses to compile)
5) Installing the missing dependancies
6) Building OpenWRT (from Updating Feeds on)

 

1. XCode & Macports
a. You will need to install Xcode 4.0 from the Apple developers’ webpage, which will redirect you to the App Store entry for Xcode where you will follow the instructions on that page to install.

b. Then,  grab the latest MacPorts .pkg installer for Lion.
Mount the disk image and install MacPorts with the .pkg file. Open the Terminal.app from /Applications/Utilities

sudo port -v selfupdate && sudo port install subversion

Follow these directions if the above command does not work after mounting the dmg and installing.

Then:

port select –list gcc

Should give you an output similar to

air:~ alex$ port select –list gcc

Available versions for gcc:

apple-gcc42

gcc42

llvm-gcc42

mp-gcc44 (active)

none

I do not believe the version of gcc matters, but if it does, here’s how to replicate my set up:

sudo port install gcc44 && sudo port select –set gcc mp-gcc44

Don’t follow the above step unless you run into trouble later in the HOWTO when we try to compile OpenWRT.  The above command will build gcc-4.4 from scratch and that takes time. A lot of time.

 

2. Set up the build environment
a. Now install the packages needed to manipulate the OpenWRT source (horizontal scroll to see entire command, its long):

sudo port install coreutils asciidoc binutils bzip2 fastjar flex getopt gtk2 intltool jikes zlib openssl p5-extutils-makemaker python26 rsync ruby sdcc unzip gettext libxslt bison gawk autoconf wget gmake ncurses

While this is compiling the packages for your system, continue on to 2b and 3a since they don’t depend on any of the above packages.

b. The OpenWRT source is case-sensitive, unfortunately HFS+ drives formatted by Apple are not set to be case-sensitive; so we’re going to create a .sparseimage workspace by opening Disk Utility in the /Applications/Utilities directory.

Click File -> New -> Blank Disk Image…
On the top of the dialog that just came up fill in “OpenWRT” without the quotes in the Save As: field and in the lower Name: field.

Choose a size larger than 3GB. My disk image is ~8G and will reach it’s limit after compiling the packages and firmware images more than a few times.
IMPORTANT: In the Format: drop down, select  Mac OS Extended (case-sensitive

In the Image Format: drop down select “sparse disk image“. Then click Create. The newly created disk image will be on the left panel of the Disk Utility, double clicking it will mount it on /Volumes/OpenWRT

3.Grabbing the source tree
a. Open the Terminal and type:

cd /Volumes/OpenWRT && svn co svn://svn.openwrt.org/openwrt/trunk/

Give it a few minutes while it pulls the source from the repository.

4. Modifying Makefiles
Open TextEdit.app and open /Volume/OpenWRT/trunk/tools/Makefile

cd /Volume/OpenWRT/trunk && open tools/Makefile

On line 17 erase the “e2fsprogs entry so it should look like this:

tools-y += sstrip ipkg-utils genext2fs  mtd-utils mkimage

Comment out line 22 like so:

#tools-$(CONFIG_TARGET_x86) += qemu

Then go on to comment out line 50, line 52, line 58; they are the build dependencies for mtd-utils (dep: e2fsprogs), qemu (dep: e2fsprogs), and e2fsprogs respectively.

5. Installing the missing dependencies
Now let’s install and copy MacPort’s e2fsprogs and osso-uuid’s libraries and headers so we can build tools/mtd-utils correctly

sudo port install e2fsprogs osso-uuid

Followed by:

cd /Volumes/OpenWRT/trunk;

mkdir -p staging_dir/host/include/e2fsprogs;

cp -R /opt/local/include/ossp staging_dir/host/include/e2fsprogs/;

cp /opt/local/lib/libuuid* staging_dir/host/lib

Then follow this manual on how to build OpenWRT now that you have successfully built the necessary tools to compile OpenWRT images on Mac OS X 10.7 Lion.

Start from the section titled “Updating Feeds” and follow the wiki in it’s entirety. Do not select any ‘qemu’ entries when you reach the make menuconfig step; qemu will not build on 64-bit Lion.