I helped a friend get OpenWrt building under OS X, and I thought I'd share the process:
1) First of all, you can not build on an HFS partition - the Linux kernel will not build on a filesystem that is not case sensitive. Luckily, Disk Utility is here to save the day. Create a 2 GB disk image in disk utility, then in Terminal:
sudo diskutil eraseVolume "Case-sensitive HFS+" newvolname volume
where volume is the mounted disk image volume
2) Install Fink. This will give you wget and gettext.
3) Using FinkCommander (or via the cmdline), install the fileutils package. This gives you the versions of cp and install that you'll need.
4) Using FinkCommander install the findutils package. This gives you the version of xargs that you'll need.
5) Something in the build process wants true to be in /bin, so run
sudo ln -s /usr/bin/true /bin/true
6) Go ahead and fetch OpenWrt from CVS in the volume that you created in step 1.
7) msgfmt is in a different location than on a Linux box. Apply the following patch to binutils-uclibc.mk:
--- binutils-uclibc.mk.dist 2004-08-13 17:19:48.170000000 +0000
+++ binutils-uclibc.mk 2004-08-13 17:20:49.960000000 +0000
@@ -54,7 +54,7 @@
echo -e "nnYou must install 'flex' on your build machinen";
exit 1;
fi;
- @if [ ! -x /usr/bin/msgfmt ] ; then
+ @if [ ! -x /sw/bin/msgfmt ] ; then
echo -e "nnYou must install 'gettext' on your build machinen"
;
exit 1;
fi;
A better change would be to remove the absolute path from the .mk altogether, which would then work on both platforms...
[/b]
8) squashfs isn't set up to be built under OS X. The issue is with the code for endianness. Apply the following patch to squashfs.patch
--- squashfs.patch.dist 2004-08-13 17:27:03.950000000 +0000
+++ squashfs.patch 2004-08-13 17:37:40.840000000 +0000
@@ -4,6 +4,21 @@
--- squashfs1.3r3/squashfs-tools/mksquashfs.c-dist 2004-03-29 20:35:37.0000
00000 -0600
+++ squashfs1.3r3/squashfs-tools/mksquashfs.c 2004-03-29 22:28:51.000000000 -0
600
+@@ -33,7 +33,13 @@
+ #include <dirent.h>
+ #include <string.h>
+ #include <zlib.h>
+-#include <endian.h>
++#ifdef __APPLE__
++ #include <machine/endian.h>
++ #define __BYTE_ORDER BYTE_ORDER
++ #define __BIG_ENDIAN BIG_ENDIAN
++#else
++ #include <endian.h>
++#endif
+ #include <stdlib.h>
+ #include <signal.h>
+ #include <setjmp.h>
@@ -136,6 +136,8 @@
stotal_bytes, stotal_inode_bytes, stotal_directory_bytes, sinode_count,
sfile_count, ssym_count, sdev_count, sdir_count, sdup_files;
int restore = 0;
@@ -34,3 +49,20 @@
} else {
ERROR("%s: invalid optionnn", argv[0]);
printOptions:
+--- squashfs1.3r3/squashfs-tools/read_fs.c-dist 2004-01-18 20:35:37.0000
00000 -0600
++++ squashfs1.3r3/squashfs-tools/read_fs.c 2004-08-12 22:28:51.000000000 -0
600
+@@ -34,7 +34,13 @@
+ #include <zlib.h>
+ #include <sys/mman.h>
+
+-#include <endian.h>
++#ifdef __APPLE__
++ #include <machine/endian.h>
++ #define __BYTE_ORDER BYTE_ORDER
++ #define __BIG_ENDIAN BIG_ENDIAN
++#else
++ #include <endian.h>
++#endif
+ #include "read_fs.h"
+ #include <squashfs_fs.h>
+
9) At this point, it is necessary to get the build process started, so that some of the files can get downloaded. Go ahead and run "make" from buildroot. The build should fail while attempting to compile the kernel.
10) OS X does not have GNU expr (OS X's is POSIX compliant, just not GNU compatible). Grab the file linux-2.4-bsd-expr.patch from the crosstool project. Here it is for convenience
# http://in3www.epfl.ch/~schaffne/linux-2.4-bsd-expr.patch
The following makes it possible to compile linux 2.4.19 to 2.4.25 on Mac OS X,
where "expr" doesn't understand the "length" construct
(which it doesn't have to, according to SuSv3
(see http://www.opengroup.org/onlinepubs/007904975/utilities/expr.html)
See also http://sources.redhat.com/ml/crossgcc/2004-02/msg00131.html
Fixes error
expr: syntax error
KERNELRELEASE "2.4.21" exceeds 64 characters
make: *** [include/linux/version.h] Error 1
diff -ur linux-2.4.23-old/Makefile linux-2.4.23/Makefile
--- linux-2.4.23-old/Makefile 2003-12-09 14:27:56.000000000 +0100
+++ linux-2.4.23/Makefile 2003-12-09 14:28:37.000000000 +0100
@@ -353,7 +353,7 @@
@rm -f .ver1
include/linux/version.h: ./Makefile
- @expr length "$(KERNELRELEASE)" <= $(uts_len) > /dev/null ||
+ @expr "$(KERNELRELEASE)" : '.*' <= $(uts_len) > /dev/null ||
(echo KERNELRELEASE "$(KERNELRELEASE)" exceeds $(uts_len) characters >&2; false)
@echo #define UTS_RELEASE "$(KERNELRELEASE)" > .ver
@echo #define LINUX_VERSION_CODE `expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)` >> .ver
A sample command line to do the patch
cd build_mipsel/WRT54GS/release/src/linux/linux/
patch -p1 < linux-2.4-bsd-expr.patch
11) The final problem is that the executables for producing the final flash images are only provided to us from Linksys as i386 binaries. Luckily, enough work has been done to document their behavior to reproduce them. The source is attached (addpattern.c & trx.c). The source we produced is a bit crude, but gets the job done. Compile using
gcc addpattern.c -o addpattern
gcc trx.c -o trx
Replace the tools in /buildroot/build_mipsel/WRT54GS/release/tools/ with the OSX versions provided.
12) Go back to the buildroot directory and run "make" again. This time the build should run to completion, yielding the openwrt-g-code.bin and openwrt-gs-code.bin files. You will probably see some complaints about the package build process. As we weren't interested in producing any packages, we did not pursue this aspect of the build.
13) Upload your .bin file via tftp (also available via fink) or the web interface and enjoy!
-----------
Of the steps outlined above, I believe that steps 7, 8, 10, and 11 can actually be integrated into the OpenWrt CVS code, yielding a project that will build across i386 Linux, OS X, and PPC Linux. The code provided in step 11 will help eliminate another couple of closed-source parts of the WRT54G build process.
The only tricky parts of this whole process was figuring out step 1, and writing the code for step 11.
I don't have an OS X of my own anymore to pursue this aspect of OpenWrt much further, but I felt it was important to share this effort, and allow our OS X-based brethern to participate in the OpenWrt project too.
Enjoy!