libubox: add a simple build script
authorÁlvaro Fernández Rojas <noltari@gmail.com>
Mon, 10 Nov 2025 21:45:20 +0000 (22:45 +0100)
committerÁlvaro Fernández Rojas <noltari@gmail.com>
Tue, 11 Nov 2025 13:28:47 +0000 (14:28 +0100)
Should make it a little bit easier for people who want to contribute to
libubox.

Link: https://github.com/openwrt/libubox/pull/26
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
.gitignore
scripts/devel-build.sh [new file with mode: 0755]

index 6f6c8a8266cbd6838e7983a49f536c4a21932079..641986f82972c73e2ee08ad994e7f35acbbb21b0 100644 (file)
@@ -5,6 +5,7 @@ CMakeFiles
 *.a
 *.so
 *.dylib
+build
 install_manifest.txt
 jshn
 *-example
diff --git a/scripts/devel-build.sh b/scripts/devel-build.sh
new file mode 100755 (executable)
index 0000000..0c58fcf
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+set -euxo pipefail
+cd "${0%/*}"
+cd ..
+
+# Sanity checks
+if [ ! -e "CMakeLists.txt" ] || [ ! -e "blob.c" ]; then
+       echo "libubox checkout not found" >&2
+       exit 1
+fi
+
+if [ $# -eq 0 ]; then
+       BUILD_ARGS="-DBUILD_LUA=ON -DBUILD_EXAMPLES=ON -DUNIT_TESTING=ON"
+else
+       BUILD_ARGS="$@"
+fi
+
+# Create build dirs
+LIBUBOXDIR="$(pwd)"
+BUILDDIR="${LIBUBOXDIR}/build"
+DEPSDIR="${BUILDDIR}/depends"
+[ -e "${BUILDDIR}" ] || mkdir "${BUILDDIR}"
+[ -e "${DEPSDIR}" ] || mkdir "${DEPSDIR}"
+
+# Download deps
+cd "${DEPSDIR}"
+[ -e "json-c" ] || git clone https://github.com/json-c/json-c.git
+if [ ! -e "lua" ]; then
+       mkdir -p lua
+       wget -qO- https://www.lua.org/ftp/lua-5.1.5.tar.gz | \
+               tar zxvf - -C lua --strip-components=1
+       sed -i '/#define LUA_USE_READLINE/d' ./lua/src/luaconf.h
+       sed -i 's/ -lreadline -lhistory -lncurses//g' ./lua/src/Makefile
+fi
+
+# Build lua
+cd "${DEPSDIR}/lua"
+make linux install \
+       INSTALL_TOP="${BUILDDIR}"
+
+# Build json-c
+cd "${DEPSDIR}/json-c"
+cmake                                                  \
+       -S .                                            \
+       -B .                                            \
+       -DCMAKE_PREFIX_PATH="${BUILDDIR}"               \
+       -DBUILD_SHARED_LIBS=OFF                         \
+       -DDISABLE_EXTRA_LIBS=ON                         \
+       --install-prefix "${BUILDDIR}"
+make
+make install
+
+# Build libubox
+cd "${LIBUBOXDIR}"
+cmake                                                  \
+       -S .                                            \
+       -B "${BUILDDIR}"                                \
+       -DCMAKE_PREFIX_PATH="${BUILDDIR}"               \
+       ${BUILD_ARGS}
+make -C "${BUILDDIR}" all test CTEST_OUTPUT_ON_FAILURE=1
+
+set +x
+echo "✅ Success - the libubox library is available at ${BUILDDIR}"
+echo "👷 You can rebuild libubox by running 'make -C build'"
+
+exit 0