This post contains Q&A-style notes on compiling software for OpenWrt or compiling OpenWrt itself.
- SDK or Source code?
If you want to cross-compile software to run on an OpenWrt device or rebuild/patch existing OpenWrt packages, the SDK suffices.
The SDK can be found under the
<target>/<device>folders on downloads.openwrt.org, note that the snapshots are rebuilt frequently and not a stable target to build for. The source is at https://github.com/openwrt/openwrt, make sure to check out a branch/tag if you don't want the development branch.
- Ok, now how do I set it up?
Build tools (tested on Ubuntu 22.04):
Don't forget to do this as an unprivileged user (even if you have a container), build tools don't like being run as a root.
- [Source] Target and package selection
make menuconfig. The first three option select the device to target. Most of the rest are for packages,
< >means a package will not be built,
<*>will build it into the final firmware image (preinstalled),
<M>will build it as an installable package file.
/will open up search.
Configuring is annoying so you can keep the
.configfile for next time. Copy it back and run
yes "" | make oldconfigif you don't like answering questions.
- [Source] Building everything
nice make -j$(nproc).
The firmware and sysupgrade images will end up in
bin/targets/, packages also under
- How do I build a single package?
make packages/NAMEHERE/compile, that's it.
- [SDK] How do I build software that's not in OpenWrt?
Haven't had to do that yet, the answer is probably here.
- [SDK] I don't care about packaging, where's the cross-compiler?
./staging_dir/toolchain-<whatever>/bin/<arch>-openwrt-linux-gcc(This likely won't lead you to success unless all you need is a simple C program.)
- How do I apply patches to packages?
There's probably multiple ways but the most convenient is overriding the source tree.
You should have a git checkout with your modifications (commit them!) somewhere. Then:
- [Source] Which kernel version will I get?
KERNEL_TESTING_PATCHVERis defined too you can switch to the newer kernel by enabling "Global build settings > Use the testing kernel version".
Note that OpenWrt kernels are heavily patched so you can't really use a version other than the predefined one even if you wanted to.
- [Source] Ricing your build flags
If you've ever used Gentoo you will find this fun. 
Under "Advanced configuration options" you can configure global compiler flags (
TARGET_OPTIMIZATION) and the ones used by the kernel (
- Tell me more!