OpenWrt Forum Archive

Topic: [HowTo] Building OpenWRT 12.09 on OS X 10.9 (Mavericks)

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

Hi all, here's a quick howto for building OpenWRT on OS X 10.9 (Mavericks) using MacPorts.  I'm not sure when, but Apple dropped GCC support completely (I jumped from Lion to Mavericks without going to ML).  Now, gcc is just a stub for the clang compiler -- which sucks for anyone who must use gcc to compile their programs.  Fortunately, we can install the old llvm-gcc42 compiler and gcc47 from MacPorts to get a clean build.

NOTE: This howto is for 12.09 attitude_adjustment.  I have no idea if this will work for trunk.

Here's what I've found so far:

  • Apple's clang-500.2.79 doesn't build anything.

  • llvm-gcc42 builds the tools, but not the toolchain.

  • gcc47 builds the toolchain and firmware, but has problems building tools/e2fsprogs (see https://dev.openwrt.org/ticket/12441 for details).

  • gcc48 has the same issue with e2fsprogs and fails to build the toolchain.

I'm assuming everyone knows how to set up the OpenWRT build environment for OS X.  There are several howtos in the forum and the wiki.  This is simply help for getting things set up in Mavericks.

First, Xcode does not install the command line tools by default and it's no longer an option in the preferences.  It needs to be set up from the command line now.  This document has everything you need to get MacPorts running properly in Mavericks: http://trac.macports.org/wiki/MavericksProblems.

At this point you should have installed MacPorts and all the build prerequisites (including llvm-gcc42 and gcc47), and prepared the .config file using 'make menuconfig'.  Now, here's what I did to get a successful build:

$ sudo port select --set gcc mp-llvm-gcc42
Selecting 'mp-llvm-gcc42' for 'gcc' succeeded. 'mp-llvm-gcc42' is now active.

$ hash -r

$ gcc --version
i686-apple-darwin13-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11) (MacPorts llvm-gcc42 2336.11_1)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ export PATH=/opt/local/libexec/gnubin:/opt/local/bin:${PATH}

$ make dirclean && make tools/install
 make[1] clean
 make[2] target/linux/clean
 make[3] -C target/linux clean
 make[1] dirclean
 make[2] target/linux/clean
 make[3] -C target/linux clean
Collecting package info: done
Collecting target info: done
Checking 'working-make'... ok.
Checking 'case-sensitive-fs'... ok.
Checking 'getopt'... ok.
Checking 'fileutils'... ok.
Checking 'working-gcc'... ok.
Checking 'working-g++'... ok.
Checking 'ncurses'... ok.
Checking 'zlib'... ok.
Checking 'gawk'... ok.
Checking 'unzip'... ok.
Checking 'bzip2'... ok.
Checking 'patch'... ok.
Checking 'perl'... ok.
Checking 'python'... ok.
Checking 'wget'... ok.
Checking 'git'... ok.
Checking 'gnutar'... ok.
Checking 'svn'... ok.
Checking 'gnu-find'... ok.
Checking 'getopt-extended'... ok.
Checking 'non-root'... ok.
 make[1] tools/install
 make[2] -C tools/m4 compile
 make[2] -C tools/m4 install
 make[2] -C tools/sed compile
 make[2] -C tools/sed install
 make[2] -C tools/libtool compile
 make[2] -C tools/libtool install
 make[2] -C tools/autoconf compile
 make[2] -C tools/autoconf install
 make[2] -C tools/pkg-config compile
 make[2] -C tools/pkg-config install
 make[2] -C tools/xz compile
 make[2] -C tools/xz install
 make[2] -C tools/automake compile
 make[2] -C tools/automake install
 make[2] -C tools/gmp compile
 make[2] -C tools/gmp install
 make[2] -C tools/mpfr compile
 make[2] -C tools/mpfr install
 make[2] -C tools/mpc compile
 make[2] -C tools/mpc install
 make[2] -C tools/libelf compile
 make[2] -C tools/libelf install
 make[2] -C tools/flex compile
 make[2] -C tools/flex install
 make[2] -C tools/bison compile
 make[2] -C tools/bison install
 make[2] -C tools/mklibs compile
 make[2] -C tools/mklibs install
 make[2] -C tools/sstrip compile
 make[2] -C tools/sstrip install
 make[2] -C tools/ipkg-utils compile
 make[2] -C tools/ipkg-utils install
 make[2] -C tools/genext2fs compile
 make[2] -C tools/genext2fs install
 make[2] -C tools/e2fsprogs compile
 make[2] -C tools/e2fsprogs install
 make[2] -C tools/mtd-utils compile
 make[2] -C tools/mtd-utils install
 make[2] -C tools/mkimage compile
 make[2] -C tools/mkimage install
 make[2] -C tools/firmware-utils compile
 make[2] -C tools/firmware-utils install
 make[2] -C tools/patch-cmdline compile
 make[2] -C tools/patch-cmdline install
 make[2] -C tools/quilt compile
 make[2] -C tools/quilt install
 make[2] -C tools/yaffs2 compile
 make[2] -C tools/yaffs2 install
 make[2] -C tools/flock compile
 make[2] -C tools/flock install
 make[2] -C tools/padjffs2 compile
 make[2] -C tools/padjffs2 install
 make[2] -C tools/mm-macros compile
 make[2] -C tools/mm-macros install
 make[2] -C tools/xorg-macros compile
 make[2] -C tools/xorg-macros install
 make[2] -C tools/xfce-macros compile
 make[2] -C tools/xfce-macros install
 make[2] -C tools/missing-macros compile
 make[2] -C tools/missing-macros install
 make[2] -C tools/cmake compile
 make[2] -C tools/cmake install
 make[2] -C tools/scons compile
 make[2] -C tools/scons install
 make[2] -C tools/lzma compile
 make[2] -C tools/lzma install
 make[2] -C tools/squashfs4 compile
 make[2] -C tools/squashfs4 install
 make[2] -C tools/b43-tools compile
 make[2] -C tools/b43-tools install

$ sudo port select --set gcc mp-gcc47
Selecting 'mp-gcc47' for 'gcc' succeeded. 'mp-gcc47' is now active.

$ hash -r

$ gcc --version
gcc (MacPorts gcc47 4.7.3_3) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ make
 make[1] world
 make[2] toolchain/install
 make[3] -C toolchain/gdb prepare
 make[3] -C toolchain/gdb compile
 make[3] -C toolchain/gdb install
 make[3] -C toolchain/binutils prepare
 make[3] -C toolchain/binutils compile
 make[3] -C toolchain/binutils install
 make[3] -C toolchain/gcc/minimal prepare
 make[3] -C toolchain/gcc/minimal compile
 make[3] -C toolchain/gcc/minimal install
 make[3] -C toolchain/kernel-headers prepare
 make[3] -C toolchain/kernel-headers compile
 make[3] -C toolchain/kernel-headers install
 make[3] -C toolchain/uClibc/headers prepare
 make[3] -C toolchain/uClibc/headers compile
 make[3] -C toolchain/uClibc/headers install
 make[3] -C toolchain/gcc/initial prepare
 make[3] -C toolchain/gcc/initial compile
 make[3] -C toolchain/gcc/initial install
 make[3] -C toolchain/uClibc prepare
 make[3] -C toolchain/uClibc compile
 make[3] -C toolchain/uClibc install
 make[3] -C toolchain/gcc/final prepare
 make[3] -C toolchain/gcc/final compile
 make[3] -C toolchain/gcc/final install
 make[3] -C toolchain/uClibc/utils prepare
 make[3] -C toolchain/uClibc/utils compile
 make[3] -C toolchain/uClibc/utils install
 make[2] target/compile
 make[3] -C target/linux compile
 make[2] package/cleanup
 make[2] package/compile
 make[3] -C package/toolchain compile
 make[3] -C package/apex compile
 make[3] -C package/libnl-tiny compile
 make[3] -C package/libjson-c compile
 make[3] -C package/lua compile
 make[3] -C package/libubox compile
 make[3] -C package/ubus compile
 make[3] -C package/uci compile
 make[3] -C package/netifd compile
 make[3] -C package/opkg host-compile
 make[3] -C package/base-files compile
 make[3] -C package/ncurses compile
 make[3] -C package/util-linux compile
 make[3] -C package/block-mount compile
 make[3] -C package/busybox compile
 make[3] -C package/dnsmasq compile
 make[3] -C package/dropbear compile
 make[3] -C package/e2fsprogs compile
 make[3] -C package/fconfig compile
 make[3] -C feeds/luci/freifunk-common compile
 make[3] -C feeds/luci/community-profiles compile
 make[3] -C feeds/routing/olsrd compile
 make[3] -C package/iptables compile
 make[3] -C package/firewall compile
 make[3] -C package/iproute2 compile
 make[3] -C feeds/luci/freifunk-gwcheck compile
 make[3] -C feeds/luci/freifunk-mapupdate compile
 make[3] -C package/iwinfo compile
 make[3] -C package/lua host-compile
 make[3] -C package/px5g compile
 make[3] -C package/uhttpd compile
 make[3] -C feeds/luci/luci compile
 make[3] -C package/hostapd compile
 make[3] -C package/hotplug2 compile
 make[3] -C package/iw compile
 make[3] -C package/ixp4xx-microcode compile
 make[3] -C package/kernel compile
 make[3] -C package/mac80211 compile
 make[3] -C package/mtd compile
 make[3] -C package/opkg compile
 make[3] -C package/libpcap compile
 make[3] -C package/linux-atm compile
 make[3] -C package/resolveip compile
 make[3] -C package/ppp compile
 make[2] package/install
 make[3] -C package/apex install
 make[3] -C package/block-mount install
 make[3] -C package/busybox install
 make[3] -C package/dnsmasq install
 make[3] -C package/dropbear install
 make[3] -C package/e2fsprogs install
 make[3] -C package/fconfig install
 make[3] -C feeds/luci/luci install
 make[3] -C package/firewall install
 make[3] -C package/hostapd install
 make[3] -C package/hotplug2 install
 make[3] -C package/iptables install
 make[3] -C package/iw install
 make[3] -C package/iwinfo install
 make[3] -C package/ixp4xx-microcode install
 make[3] -C package/kernel install
 make[3] -C package/libjson-c install
 make[3] -C package/libnl-tiny install
 make[3] -C package/libubox install
 make[3] -C package/lua install
 make[3] -C package/mac80211 install
 make[3] -C package/mtd install
 make[3] -C package/netifd install
 make[3] -C package/opkg install
 make[3] -C package/ppp install
 make[3] -C package/toolchain install
 make[3] -C package/ubus install
 make[3] -C package/uci install
 make[3] -C package/uhttpd install
 make[3] -C package/util-linux install
 make[3] -C package/base-files install
 make[2] package/rootfs-prepare
 make[3] package/preconfig
 make[2] target/install
 make[3] -C target/linux install
 make[2] package/index

Now, I need to flash the firmware and see if this thing actually works. wink

Good luck!

The discussion might have continued from here.