# OpenWrt Build System



## balanga (Aug 4, 2018)

If anyone is aware of OpenWrt, you might know that it provides a build system for allowing users to build their own image. Apparently this build system could be installed on FreeBSD at one time, but is not currently available.... hopefully until now 

Here is my effort to create it:-

```
#  Install required pkgs

cat <<EOF | xargs pkg install -y
git
bash
gmake
gtar
gcc
gawk
ncurses
findutils
patch
wget
getopt
coreutils
EOF

# Build and install GNU time

wget https://ftp.gnu.org/gnu/time/time-1.9.tar.gz
tar zxf time-1.9.tar.gz
cd time-1.9
./configure
make
make install
mv /usr/local/bin/time /usr/local/bin/gtime

# Install OpenWrt Build System

mkdir ~/OpenWrt-BuildSystem
cd ~/OpenWrt-BuildSystem
git clone https://github.com/openwrt/openwrt.git
cd openwrt

# patch mkhash.c

wget 'https://bugs.openwrt.org/index.php?getfile=292' -O patchfile
patch scripts/mkhash.c -i patchfile -o scripts/mkhash.c

# Let's go!!!

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

make  menuconfig
```

I've only just managed to get this working, so would appreciate any feedback. The build system does get installed, but I haven't yet produced an image, just pleased to have got this far.


----------



## balanga (Aug 5, 2018)

The good folks at OpenWrt have just changed the Build System so that it no longer needs GNU time, after all my hard work getting it working . Now if they can just incorporate the patch into mkhash.c then it will just be a simple matter of using `git clone` to grab the system - after you have installed the required pkgs of course.


----------



## dawei (Jun 7, 2019)

balanga said:


> The good folks at OpenWrt have just changed the Build System so that it no longer needs GNU time, after all my hard work getting it working . Now if they can just incorporate the patch into mkhash.c then it will just be a simple matter of using `git clone` to grab the system - after you have installed the required pkgs of course.



I use the script you provided, got the following error, how to fix it:

```
gmake[8]: Entering directory '/usr/home/xiangsiwei/openwrt-v18.06.2/build_dir/host/xz-5.2.4/src/xzdec'
/usr/bin/env bash ../../libtool  --tag=CC   --mode=link gcc -D_THREAD_SAFE -pthread -fvisibility=hidden -Wall -Wextra -Wvla -Wformat=2 -Winit-self -Wmissing-include-dirs -Wstrict-aliasing -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn -Wredundant-decls -O2 -I/usr/home/xiangsiwei/openwrt-v18.06.2/staging_dir/host/include   -L/usr/home/xiangsiwei/openwrt-v18.06.2/staging_dir/host/lib  -o xzdec xzdec-xzdec.o xzdec-tuklib_progname.o xzdec-tuklib_exit.o  ../../src/liblzma/liblzma.la  -lintl
libtool: link: gcc -D_THREAD_SAFE -pthread -fvisibility=hidden -Wall -Wextra -Wvla -Wformat=2 -Winit-self -Wmissing-include-dirs -Wstrict-aliasing -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn -Wredundant-decls -O2 -I/usr/home/xiangsiwei/openwrt-v18.06.2/staging_dir/host/include -o xzdec xzdec-xzdec.o xzdec-tuklib_progname.o xzdec-tuklib_exit.o  -L/usr/home/xiangsiwei/openwrt-v18.06.2/staging_dir/host/lib ../../src/liblzma/.libs/liblzma.a -lintl -pthread
/usr/local/bin/ld: ../../src/liblzma/.libs/liblzma.a(liblzma_la-sha256.o): in function `transform':
sha256.c:(.text+0x68): undefined reference to `bswap32'
/usr/local/bin/ld: sha256.c:(.text+0x106): undefined reference to `bswap32'
/usr/local/bin/ld: sha256.c:(.text+0x183): undefined reference to `bswap32'
/usr/local/bin/ld: sha256.c:(.text+0x205): undefined reference to `bswap32'
/usr/local/bin/ld: sha256.c:(.text+0x27b): undefined reference to `bswap32'
/usr/local/bin/ld: ../../src/liblzma/.libs/liblzma.a(liblzma_la-sha256.o):sha256.c:(.text+0x2f5): more undefined references to `bswap32' follow                                                                                                                                 
/usr/local/bin/ld: ../../src/liblzma/.libs/liblzma.a(liblzma_la-sha256.o): in function `lzma_sha256_finish':
sha256.c:(.text+0x151f): undefined reference to `bswap64'
/usr/local/bin/ld: sha256.c:(.text+0x154a): undefined reference to `bswap32'
collect2: error: ld returned 1 exit status
gmake[8]: *** [Makefile:501: xzdec] Error 1
```


----------



## mark_j (Jun 8, 2019)

bswap32 and bswap64 are part of the libc library (-lc)


----------



## dawei (Jun 10, 2019)

mark_j said:


> bswap32 and bswap64 are part of the libc library (-lc)


can you create openwrt build in freebsd jail successfully?


----------



## mark_j (Jun 11, 2019)

If i get some time i will try - i don't use openwrt


----------



## mark_j (Jun 12, 2019)

dawei said:


> can you create openwrt build in freebsd jail successfully?


Can you tell me what you are attempting to build?
I have set up to the point of being at the menu.


----------



## dawei (Jun 13, 2019)

mark_j said:


> Can you tell me what you are attempting to build?
> I have set up to the point of being at the menu.






MIPS->MT7621->Firely FireWRT
Can you show me the procedures how to get the point of being at the menu ?
The error I had shown occured at the point of building host tools xz and cmake


----------



## mark_j (Jun 13, 2019)

I built it following the instructions as posted by balanga; no more, no less.

Ok, let's rewind.
I'm happy to help, *BUT*, you need to provide logs and more than just sparse information. I don't have a great deal of time to allocate to this, so let's capitalize on what I can.

Start up a terminal session, invoke script and execute your build process. When it fails, exit script and post the log.

I know you mentioned running this in a jail. Is this jail some odd setup from just a standard install of FreeBSD?


----------



## dawei (Jun 14, 2019)

mark_j said:


> I built it following the instructions as posted by balanga; no more, no less.
> 
> Ok, let's rewind.
> I'm happy to help, *BUT*, you need to provide logs and more than just sparse information. I don't have a great deal of time to allocate to this, so let's capitalize on what I can.
> ...





mark_j said:


> I built it following the instructions as posted by balanga; no more, no less.
> 
> Ok, let's rewind.
> I'm happy to help, *BUT*, you need to provide logs and more than just sparse information. I don't have a great deal of time to allocate to this, so let's capitalize on what I can.
> ...



I'm sorry.  Thank you for taking the time to talk to me. I show the error as the following:
1. execute the script, on FreeBSD 12.0-RELEASE
2. make menuconfig, then choose Target System (MediaTek Ralink MIPS), Subtarget (MT7621 based boards), Target Profile (Firefly FireWRT), save it
3. execute make -j1 V=s
the error log is shown in the attached files


----------



## mark_j (Jun 14, 2019)

No apologies needed. It's just torturous doing 1 or 2 steps every few days.

Now, before I look at this, any other information on the jail or is it just a standard freebsd install?

What script are you referring to?
Do you mean both of these?

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


----------



## dawei (Jun 14, 2019)

mark_j said:


> No apologies needed. It's just torturous doing 1 or 2 steps every few days.
> 
> Now, before I look at this, any other information on the jail or is it just a standard freebsd install?
> 
> ...


1. FreeBSD is standard install.
2. the script provided by* balanga*

```
#  Install required pkgs

cat <<EOF | xargs pkg install -y
git
bash
gmake
gtar
gcc
gawk
ncurses
findutils
patch
wget
getopt
coreutils
EOF

# Build and install GNU time

wget https://ftp.gnu.org/gnu/time/time-1.9.tar.gz
tar zxf time-1.9.tar.gz
cd time-1.9
./configure
make
make install
mv /usr/local/bin/time /usr/local/bin/gtime

# Install OpenWrt Build System

mkdir ~/OpenWrt-BuildSystem
cd ~/OpenWrt-BuildSystem
git clone https://github.com/openwrt/openwrt.git
cd openwrt

# patch mkhash.c

wget 'https://bugs.openwrt.org/index.php?getfile=292' -O patchfile
patch scripts/mkhash.c -i patchfile -o scripts/mkhash.c

# Let's go!!!

./scripts/feeds update -a
./scripts/feeds install -a
```
3. the following code is executed:

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

execute make -j1 V=s, get the error. Did you get the same error?


----------



## mark_j (Jun 14, 2019)

After Step 3 I ran make menuconfig as per the instructions.
So I think I'm confused. I was under the impression you didn't get to that step:
You wrote: "Can you show me the procedures how to get the point of being at the menu ? "
But you are saying you've built the menu?

Ok, my confusion. So what did you select next after selecting the Target, sub Target and profile?


----------



## dawei (Jun 14, 2019)

mark_j said:


> After Step 3 I ran make menuconfig as per the instructions.
> So I think I'm confused. I was under the impression you didn't get to that step:
> You wrote: "Can you show me the procedures how to get the point of being at the menu ? "
> But you are saying you've built the menu?
> ...


Choose Target System (MediaTek Ralink MIPS), Subtarget (MT7621 based boards), Target Profile (Firefly FireWRT), save it, exit the config menu. Then just execute make   -j1 V=s, get the error! There's no error compiling the xz source code in host system, but get the error I have shown in the OpenWRT build system.


----------



## mark_j (Jun 15, 2019)

Ok, I can confirm, their build system on FreeBSD is not in working order.
There are macro conflicts that need to be resolved by a patch.
There is nothing wrong on your end, it's them. Perhaps post a bug report with the bswapNN errors to their forums? It does seem, however, that *BSD is supported in name only, as in "it should work".
Better to try Linux, I'm afraid. I successfully built it on Devuan Linux.


----------



## dawei (Jun 15, 2019)

mark_j said:


> Ok, I can confirm, their build system on FreeBSD is not in working order.
> There are macro conflicts that need to be resolved by a patch.
> There is nothing wrong on your end, it's them. Perhaps post a bug report with the bswapNN errors to their forums? It does seem, however, that *BSD is supported in name only, as in "it should work".
> Better to try Linux, I'm afraid. I successfully built it on Devuan Linux.


Thank you for your help, have a nice day! I'm a newbie to FreeBSD, switch from Debian.


----------

