Notes on building OpenWrt on FreeBSD

Piotr P. Stefaniak pstef at freebsd.org
Wed Aug 12 17:43:53 EDT 2020


Hello, OpenWrt community!

I happen to own multiple devices which run OpenWrt images configured and
built by myself. The size of the build directory was getting significant
for my Linux-running laptop so I wanted to move that to my NAS running
FreeBSD stable/12 with ZFS. That's why I looked into restoring OpenWrt's
ability to build on that system.

The sources needed a few patches, you can see them here:
https://github.com/pstef/openwrt/commits/freebsd
as well as in the attached files. Feel free to cherry-pick any of them,
although I assume that the cmake issue deserves a better solution than
my workaround.

With those patches, my build recipe boils down to these steps:

pkg install bash coreutils diffutils findutils gawk gcc getopt \
git-lite gmake gsed gtar patch perl5 python rsync wget

git clone --shallow-since=2016-03-01 \
'https://github.com/pstef/openwrt' --branch=freebsd && cd openwrt

mkdir -p staging_dir/host/bin && cd staging_dir/host/bin
ln -s /usr/local/bin/getopt
ln -s /usr/local/bin/gmake make
ln -s /usr/local/bin/gcc
ln -s /usr/local/bin/g++
cd ../../..

./scripts/feeds update -a
./scripts/feeds install -a

gmake menuconfig
gmake -sj4

A few comments on some of the steps:

I usually git clone using --depth=1 to not waste space, but the
scripts/feeds update step requires the availability of a commit that was
done some short time after 2016-03-01 -- hence the shallow copy of
commits only after that date.

The GNU getopt port for FreeBSD is unfortunately named like the
system-provided binary, so there's no easy way to pick one over the
other, like there is for gawk, gsed, gmake, and so on.

The symbolic link to gmake is almost unnecessary, because I think all
but one tool seem to be prepared to use gmake and not depend on make
being GNU make. I don't remember what needs the make->gmake link,
though.

Similarly, it is possible to build the vast majority of tools with the
system compiler cc (clang), except for the cross-compiling gcc which has
to be compiled with gcc -- otherwise it goes into a nasty endless loop
during the configuration step.

I hope that helps. Feel free to ask questions or to give advice!
Piotr Stefaniak
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-adjust-mkhash.c-to-FreeBSD.patch
Type: text/x-diff
Size: 895 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20200812/bc58c07c/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-fix-e2fsprogs-build-on-FreeBSD.patch
Type: text/x-diff
Size: 1443 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20200812/bc58c07c/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-fix-mtd-utils-build-on-FreeBSD.patch
Type: text/x-diff
Size: 2355 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20200812/bc58c07c/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-fix-firmware-utils-build-on-FreeBSD.patch
Type: text/x-diff
Size: 1536 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20200812/bc58c07c/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-fix-dosfstools-build-on-FreeBSD.patch
Type: text/x-diff
Size: 1187 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20200812/bc58c07c/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-work-around-problems-linking-liblzma-for-cmake-heade.patch
Type: text/x-diff
Size: 780 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20200812/bc58c07c/attachment-0005.bin>


More information about the openwrt-devel mailing list