diff mbox series

Notes on building OpenWrt on FreeBSD

Message ID 20200812214353.GC98606@freefall.freebsd.org
State Not Applicable
Headers show
Series Notes on building OpenWrt on FreeBSD | expand

Commit Message

Piotr P. Stefaniak Aug. 12, 2020, 9:43 p.m. UTC
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
diff mbox series

Patch

From 1356eb1a6fe7ace19904e544abfdea265f244ebd Mon Sep 17 00:00:00 2001
From: Piotr Stefaniak <pstef@freebsd.org>
Date: Tue, 11 Aug 2020 00:02:39 +0200
Subject: [PATCH 6/6] work-around problems linking liblzma for cmake (headers
 problem more likely)

---
 tools/cmake/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/cmake/Makefile b/tools/cmake/Makefile
index ab3d225..154a96e 100644
--- a/tools/cmake/Makefile
+++ b/tools/cmake/Makefile
@@ -40,7 +40,8 @@  HOST_CONFIGURE_VARS += \
 
 HOST_CONFIGURE_ARGS := \
 	$(if $(MAKE_JOBSERVER),--parallel="$(MAKE_JOBSERVER)") \
-	--prefix=$(STAGING_DIR_HOST)
+	--prefix=$(STAGING_DIR_HOST) \
+	--system-liblzma
 
 ifneq ($(findstring c,$(OPENWRT_VERBOSE)),)
   HOST_MAKE_FLAGS += VERBOSE=1
-- 
2.26.2