OpenWrt Forum Archive

Topic: [HOWTO] Build OpenWRT Trunk on Mac OS X 10.7 Lion - 10.8 Mountain Lion

The content of this topic has been archived on 2 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Up to date guide on my blog: http://thismachinechills.blogspot.com/2 … enwrt.html
I've also written a script to accomplish the below. It has up to date fixes and corrections outlined on the in the above link.
http://pastebin.com/WgbT8Xf2

Still requires you to have an idea of what commands to issue and in what sequence, but will make deployment a bit easier if you know what you're doing.

./buildOpenWRT.sh macFixes {fixMakefile,copyLibraries,meurig}

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

 sed -i.bak 's/\(^tools.*\)e2fsprogs/\1/;/\/e2fsprogs/s/^/#/' /Volumes/OpenWRT/tools/Makefile

The below is outdated and incorrect. The above accomplishes all of Step 4
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.

edit:

(Last edited by consonants on 14 Feb 2013, 21:37)

Orca wrote:

I added a link to your Howto for "Lion" into OpenWrt Buildroot – Installation.

If you check OpenWrt Buildroot – About, you will see, that anything not MacOS specific is already documented ;-)

Thanks, I've updated the OP and inserted Mac OS X specific directions in the wiki.

edit: I might try to get qemu to compile; there is a patch for 64-bit Lion in the qemu-devel mailing list.  I'll edit it in if I'm successful.

(Last edited by consonants on 15 Feb 2012, 21:58)

Hi,

this setup (unless I have forgotten any step) is not working for me, compilation continues to fail when cmake is being built for the host system, in particular the compiler is not able to find stdio.h (where stdio.h is under /usr/include). Any idea why?

I've followed your instructions (by the way, I think you have a typo: osso-uuid instead of ossp-uuid) and am getting this error:


make[3]: Leaving directory `/Volumes/CarambolaBuildImage/carambola/tools/genext2fs'
make[2]: *** No rule to make target `tools/e2fsprogs/install', needed by `tools/mtd-utils/compile'.  Stop.
make[2]: Leaving directory `/Volumes/CarambolaBuildImage/carambola'
make[1]: *** [/Volumes/CarambolaBuildImage/carambola/staging_dir/target-mipsel_r2_uClibc-0.9.32/stamp/.tools_install_nnynn] Error 2
make[1]: Leaving directory `/Volumes/CarambolaBuildImage/carambola'
make: *** [world] Error 2

Note that I'm building the source from https://github.com/8devices/carambola, which is a fork of https://github.com/mirrors/openwrt

Thanks for any advice you can give me.

Tom

I've decided to just build in a VM using Ubuntu, which is working fine.

Tom

Hi,

thanks for this How To. For me: with step 4 I´ve got an error executing "make V=99" - But after changing the modification in step 4 back everything works.

heinb

Thank you so much to consonants for this thread, I truly could not have compiled OpenWRT without it.

Just a few tips for anyone else going through this process:

As of Revision: 31697 (2012-05-13), the line numbers in the tools Makefile that need commenting out have changed. It's now lines 54, 56 & 62 which should look like:

$(curdir)/mtd-utils/compile := $(curdir)/e2fsprogs/install $(curdir)/xz/install
$(curdir)/qemu/compile := $(curdir)/e2fsprogs/install
$(curdir)/e2fsprogs/compile := $(curdir)/automake/install

tgdavies is right about the typo, step five should read:

sudo port install e2fsprogs ossp-uuid

there's also a mkdir missing in step five as follows:

mkdir -p staging_dir/host/lib

Finally, I spent ages trying to get around the following problem:

make[2]: Entering directory `/Volumes/OpenWRT/trunk/scripts/config'
Undefined symbols for architecture x86_64:
  "_kconf_id_lookup", referenced from:
      _zconflex in zconf.tab.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I tried a few different things, including installing the full xcode (I was justing using the command line tools previously) and the macports version of gcc (mp-gcc44 as recommended above).

It turned out to be an issue with the apple version of cc. I'm not sure which of the following variables fixed it in the end:

export cc=/opt/local/bin/gcc
export CC=/opt/local/bin/gcc

Thanks again,
Meurig

Building on meurig's post, I also needed

sudo port install findutils

I also got the same error meurig saw:

Undefined symbols for architecture x86_64:
  "_kconf_id_lookup", referenced from:
      _zconflex in zconf.tab.o
ld: symbol(s) not found for architecture x86_64

The problem didn't seem to be llvm-gcc42 so much as some incompatible object files. I deleted scripts/config/zconf.tab.o and it was fine. I'm not sure where the .o came from, a failed earlier attempt or something I guess?

sudo port select --set gcc llvm-gcc42

works just fine for me to go make menuconfig

I'm also setting up the build system for a carambola board so I potentially have slightly different errors than master openwrt. Sorry for polluting the board if this is the case.

Andrew

edit: after this make menuconfig and make kernel_menuconfig worked fine. During 'make' however I got errors about liblzma not being available.

sudo port install lzma liblzma
cp /opt/local//lib/liblzma.a staging_dir/host/lib/

fixed that though

edit2: I also had problems with gmp not configuring, failing with the error:

checking compiler gcc -O2  "has sizeof(long)==4... no"

it's related to x64 compiling, I ended up cd'ing to its directory and after checking config.log to find the configure line used, I appended -m32 to CC, configure ran fine so I then touched .configured to flag this

compiling still didn't work though. I've read the gmp doesn't support x64 yet so it all needs to be compiled as 32 bit, but I can't seem to make openwrt do that. I changed my /usr/bin/gcc symlink into a script with gcc -m32 $@ in it, and tries setting -arch i386 but I can see during make that some things are still being compiled as x86_64, I'm not sure how to fix it.
I bit the bullet too and made myself an ubuntu vm, it's all compiling great there.

Andrew

(Last edited by coronafire on 24 Jun 2012, 12:37)

I have been receiving this error when compiling backfire:

LZMA 4.65 : Igor Pavlov : Public domain : 2009-02-03
if [ `stat -c%s "/Volumes/OpenWRT/backfire/build_dir/linux-ar71xx/vmlinux-wzr-hp-g300nh.bin.lzma"` -gt 1048576 ]; then echo "Warning: /Volumes/OpenWRT/backfire/build_dir/linux-ar71xx/vmlinux-wzr-hp-g300nh.bin.lzma is too big"; else if [ `stat -c%s /Volumes/OpenWRT/backfire/build_dir/linux-ar71xx/root.squashfs` -gt 31850496 ]; then echo "Warning: /Volumes/OpenWRT/backfire/build_dir/linux-ar71xx/root.squashfs is too big"; else mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e 0x80060000 -n 'MIPS OpenWrt Linux-2.6.32.27' -d /Volumes/OpenWRT/backfire/build_dir/linux-ar71xx/vmlinux-wzr-hp-g300nh.bin.lzma /Volumes/OpenWRT/backfire/build_dir/linux-ar71xx/vmlinux-wzr-hp-g300nh.uImage; ( dd if=/Volumes/OpenWRT/backfire/build_dir/linux-ar71xx/vmlinux-wzr-hp-g300nh.uImage bs=1024k conv=sync; dd if=/Volumes/OpenWRT/backfire/build_dir/linux-ar71xx/root.squashfs bs=128k conv=sync; ) > /Volumes/OpenWRT/backfire/bin/ar71xx/openwrt-ar71xx-wzr-hp-g300nh-squashfs-sysupgrade.bin; ( echo -n -e "# Airstation Public Fmt1\x00\x00\x00\x00\x00\x00\x00\x00"; dd if=/Volumes/OpenWRT/backfire/bin/ar71xx/openwrt-ar71xx-wzr-hp-g300nh-squashfs-sysupgrade.bin; ) > /Volumes/OpenWRT/backfire/bin/ar71xx/openwrt-ar71xx-wzr-hp-g300nh-squashfs-tftp.bin; fi; fi
Image Name:   MIPS OpenWrt Linux-2.6.32.27
Created:      Thu Dec  6 14:14:02 2012
Image Type:   MIPS Linux Kernel Image (lzma compressed)
Data Size:    870006 Bytes = 849.62 kB = 0.83 MB
Load Address: 80060000
Entry Point:  80060000
0+1 records in
1+0 records out
1048576 bytes transferred in 0.003235 secs (324124586 bytes/sec)
13+1 records in
14+0 records out
1835008 bytes transferred in 0.002174 secs (844015944 bytes/sec)
5632+0 records in
5632+0 records out
2883584 bytes transferred in 0.036859 secs (78233264 bytes/sec)
( cd /Volumes/OpenWRT/backfire/bin/ar71xx ; /opt/local/bin/gfind -maxdepth 1 -type f \! -name 'md5sums'  -printf "%P\n" | sort | xargs md5sum --binary > md5sums )
md5sum: illegal option -- -
usage: md5sum [-bv] [-c [file]] | [file...]
Generates or checks MD5 Message Digests
    -c  check message digests (default is generate)
    -v  verbose, print file names when checking
    -b  read files in binary mode
The input for -c should be the list of message digests and file names
that is printed on stdout by this program when it generates digests.
make[5]: *** [install] Error 1
make[5]: Leaving directory `/Volumes/OpenWRT/backfire/target/linux/ar71xx/image'
make[4]: *** [install] Error 2
make[4]: Leaving directory `/Volumes/OpenWRT/backfire/target/linux/ar71xx'
make[3]: *** [install] Error 2
make[3]: Leaving directory `/Volumes/OpenWRT/backfire/target/linux'
make[2]: *** [target/linux/install] Error 2
make[2]: Leaving directory `/Volumes/OpenWRT/backfire'
make[1]: *** [/Volumes/OpenWRT/backfire/staging_dir/target-mips_r2_uClibc-0.9.30.1/stamp/.target_install] Error 2
make[1]: Leaving directory `/Volumes/OpenWRT/backfire'
make: *** [world] Error 2



I was able to solve this issue by replacing the commands "md5sum --binary" with "md5sum -b" from : /backfire/include/image.mk

(Last edited by anasb on 6 Dec 2012, 15:35)

Hey guys, I'm compiling my guide with your suggestions into a series of blog posts for posterity. I hope to be able to write a small shell script that will accomplish what we're trying to do here without pulling out our collective hair.

I'm glad that someone found this helpful, and appreciate your input. This is a work in progress but has updated information that someone might find pertinent:

http://thismachinechills.blogspot.com/2 … enwrt.html

The discussion might have continued from here.