Toolchain for building OpenWrt (FreeBSD)

Is there currently an uptodate list of toolchain requirements, including versions for building OpenWrt?

I remember seeing one on previous occasions, but can't seem to find it now.

3 Likes

@RuralRoots beat me to it.

But, for completeness, here is the index of all build related documentation

3 Likes

If I think have the required toolchain installed, will the scripts flag anything missing?

Build process has a prerequisite test, which should tell you early if you are missing something.

1 Like

I developed an OpenWrt build system on FreeBSD some years ago, because some old docs said it could be done. Last time I tried, I need to patch two files, include/prereq-build.mk and scripts/mkhash.c.
I notice that the latter has been changed and does include a couple of instances

#ifndef FreeBSD

That's nice.

The other patch is simply the addition of a directory in the search path for getopt.

Is it possible to contact someone to ask for a one line amendment in the build system?

Sure it is.
Just author the needed change in your own local source repo (fork of OpenWrt GitHub repo), commit it there, and propose its inclusion via a pull request.

https://github.com/openwrt/openwrt/pulls

2 Likes

Support for building OpenWrt on a FreeBSD host isn't missing because someone doesn't want it to be there, but because there aren't enough users caring about it and regularly using/ testing it, to provide the necessary changes (95% or which are already there 'by accident', as there are quite a few active contributors on MacOS). There wouldn't be any reason to reject these patches (if they're remotely sane) and as long as there is some expectation for FreeBSD users to continue caring about this. So if you got it working, please do submit your patches - while we rarely get requests about this, they are still being raised from time to time and it would be nice to have it on a best effort basis.

3 Likes

Having made the minor adjustment to include/prereq-build.mk, the system satisfies all the checks for the required tools but ends up with an error:

make -s -C scriots/config mconf: build failed

I'm supposed to re-run make with -j1 V=s or V=sc.

What is the easiest way of doing that? Editing the makefile, setting an environment variable, or something else?

that is the small menuconfig app/helper, which is an exception and

  • has local sources in scripts/config
  • is compiled with the host gcc, not the OpenWrt toolchain

You could likely move directly to that dir, and try compiling manually there. The scripts/config/mconf is pretty directly from upstream Linux, so there may be compatibility patches for FreeBSD somewhere.

Seems to be kernel 5.14 based.

Just adding my 5 cents. For building my custom images, I am using this tool

Very easy, fast and reliable.

The error I have encountered involves ncurses.h...

make: Fatal errors encountered -- cannot continue
make: stopped in /usr/jail/openwrt/root/OpenWrt-BuildSystem/openwrt/scripts/config
root@X1:/usr/jail/openwrt/root/OpenWrt-BuildSystem/openwrt # gmake -C scripts/config/ mconf
root@X1:/usr/jail/openwrt/root/OpenWrt-BuildSystem/openwrt # gmake -C scripts/config/ mconf
gmake: Entering directory '/usr/jail/openwrt/root/OpenWrt-BuildSystem/openwrt/scripts/config'
*

  • Unable to find the ncurses package.
  • Install ncurses (ncurses-devel or libncurses-dev
  • depending on your distribution).
  • You may also need to install pkg-config to find the
  • ncurses installed in a non-default location.

gmake: *** [Makefile:108: mconf-cfg] Error 1

Here is the code for finding ncurses.h:

# Check the default paths in case pkg-config is not installed.                                                                                                                 
# (Even if it is installed, some distributions such as openSUSE cannot                                                                                                         
# find ncurses by pkg-config.)                                                                                                                                                 
if [ -f /usr/include/ncursesw/ncurses.h ]; then                                                                                                                                
        echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\"                                                                                                                  
        echo libs=\"-lncursesw\"                                                                                                                                               
        exit 0                                                                                                                                                                 
fi                                                                                                                                                                             
                                                                                                                                                                               
if [ -f /usr/include/ncurses/ncurses.h ]; then                                                                                                                                 
        echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncurses\"                                                                                                                   
        echo libs=\"-lncurses\"                                                                                                                                                
        exit 0                                                                                                                                                                 
fi                                                                                                                                                                             
                                                                                                                                                                               
# As a final fallback before giving up, check if $HOSTCC knows of a default                                                                                                    
# ncurses installation (e.g. from a vendor-specific sysroot).                                                                                                                  
if echo '#include <ncurses.h>' | ${HOSTCC} -E - >/dev/null 2>&1; then                                                                                                          
        echo cflags=\"-D_GNU_SOURCE\"                                                                                                                                          
        echo libs=\"-lncurses\"                                                                                                                                                
        exit 0                                                                                                                                                                 
fi                                                                                                                                                                             
                                                                                                                                                                               
echo >&2 "*"                                                                                                                                                                   
echo >&2 "* Unable to find the ncurses package."                                                                                                                               
echo >&2 "* Install ncurses (ncurses-devel or libncurses-dev"                                                                                                                  
echo >&2 "* depending on your distribution)."                                                                                                                                  
echo >&2 "*"                                                                                                                                                                   
echo >&2 "* You may also need to install pkg-config to find the"                                                                                                               
echo >&2 "* ncurses installed in a non-default location."                                                                                                                      
echo >&2 "*"                                                                                                                                                                   
exit 1     

I have a /usr/include/ncurses.h so am not sure why it isn't found.

Can someone tell me why not?

Pure guess:

You have some jail logic there?
Is the build process allowed to step out of jail and find the files in /usr/include ?

You might need to debug the mconf compilation with strace, or something similar, in order to figure out what actually fails.

1 Like

I have created a FreeBSD jail to provide an isolated environment for building OpenWrt so that I don't interfere with my normal environment.
The required toolchain is installed in that jail.

My toolchain consists of:-

git
rsync
bash
gmake
gtar
gcc
gawk
ncurses
findutils
diffutils
patch
wget
getopt
coreutils

Sounds like you are adding complexity. But that is your own choice (and challenge)...

Actually, the inverse. I'm using a pristine environment which can be recreated easily at any moment where I can isolate errors. At the moment, I'm trying to discover why the build process can't locate ncurses.h.

The problem may well be related to a lack of pkg-config, which I have now installed, although I don't know if I need to configure it. Merely installing it didn't show any differences.

After running this snippet:-

mkdir -p /usr/include/ncursesw
cd /usr/include/ncursesw
ln -s ../ncurses*.h ./

I was able to successfully open the OpenWrt configuration menu as shown here:-

The jail has a copy of the OS including /usr/include.

I finally managed to sort out the problem by running

pkg-conf=ncurses

after looking through scripts/config/mconf-cfg.sh

!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only

PKG="ncursesw"
PKG2="ncurses"

if [ -n "$(command -v pkg-config)" ]; then
        if pkg-config --exists $PKG; then
                echo cflags=\"$(pkg-config --cflags $PKG)\"
                echo libs=\"$(pkg-config --libs $PKG)\"
                exit 0
        fi

        if pkg-config --exists $PKG2; then
                echo cflags=\"$(pkg-config --cflags $PKG2)\"
                echo libs=\"$(pkg-config --libs $PKG2)\"
                exit 0
        fi
fi