I’m trying to cross-compile avrdude so I can flash an aTtiny from my Milkv duo. I can’t build avrdude in the buildroot that I have becuse it needs a glibc compiler and I only have access to musl for the Duo. I’ve been cross-compiling a lot of dependencies, and I’m getting pretty good with cmake and autotools but meson is really thowing me a curve. I’m trying to build hidapi but it seems stuck on needing libudev.
I would like to be able to build libudev without needing to build all of systemd. I’ve been trying to build in the src/libudev/ dir where the source files are. Meson seems to be configured by the systemd build and I’d rather not go down the rabbit hole of building systemd. I have set up my toolchain file and meson seems to know I’m cross-compilng and I’ve added a project line but it’s all the progress I’ve made. I can’t seem to find any guides of how to cross-compile just libudev and all the source isn’t packaged on it own. Meson is just giving me a headache at this point. Is there a way to cross-compile libudev without building all of systemd? Systemd doesn’t really support building with musl anyway.
Here is the meson.build file in the libudev src folder with an added project line.
# SPDX-License-Identifier: LGPL-2.1-or-later
project('libudev', 'cpp', 'c')
libudev_sources = files(
'libudev-device.c',
'libudev-enumerate.c',
'libudev-hwdb.c',
'libudev-list.c',
'libudev-monitor.c',
'libudev-queue.c',
'libudev-util.c',
'libudev.c',
)
############################################################
libudev_includes = [includes, include_directories('.')]
libudev_dir_path = meson.current_source_dir()
libudev_sym = files('libudev.sym')
libudev_sym_path = libudev_dir_path / 'libudev.sym'
install_headers('libudev.h')
libudev_h_path = libudev_dir_path / 'libudev.h'
libudev_basic = static_library(
'udev-basic',
libudev_sources,
include_directories : includes,
dependencies : userspace,
c_args : ['-fvisibility=default'],
build_by_default : false)
static_libudev = get_option('static-libudev')
static_libudev_pic = static_libudev == 'true' or static_libudev == 'pic'
libudev_pc = custom_target(
'libudev.pc',
input : 'libudev.pc.in',
output : 'libudev.pc',
command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'],
install : pkgconfiglibdir != 'no',
install_tag : 'devel',
install_dir : pkgconfiglibdir)
I’ve tried editing the meson.build file but it’s looking for userspace and I’m not sure what that is. I’ve been looking for any info about building libudev and everything says to install it from your package manager/distro, I don’t have either. I’m look for some help with the meson build. I’ve been cross compilng dependencies and installing into my $PREFIX dir. My build system is on debian x86_64 if that makes any difference.
This is the output of meson setup --cross-file riscv64-toolchain-file
The Meson build system
Version: 1.3.1
Source dir: /home/tmoney/Development/AtTiny/riscv-build/systemd/src/libudev
Build dir: /home/tmoney/Development/AtTiny/riscv-build/systemd/src/libudev/build
Build type: cross build
Project name: libudev
Project version: undefined
C compiler for the host machine: riscv64-unknown-linux-musl-gcc (gcc 10.2.0 "riscv64-unknown-linux-musl-gcc (Xuantie-900 linux-5.10.4 musl gcc Toolchain V2.6.1 B-20220906) 10.2.0")
C linker for the host machine: riscv64-unknown-linux-musl-gcc ld.bfd 2.35
C++ compiler for the host machine: riscv64-unknown-linux-musl-g++ (gcc 10.2.0 "riscv64-unknown-linux-musl-g++ (Xuantie-900 linux-5.10.4 musl gcc Toolchain V2.6.1 B-20220906) 10.2.0")
C++ linker for the host machine: riscv64-unknown-linux-musl-g++ ld.bfd 2.35
C compiler for the build machine: cc (gcc 13.2.0 "cc (Debian 13.2.0-13) 13.2.0")
C linker for the build machine: cc ld.bfd 2.42
C++ compiler for the build machine: c++ (gcc 13.2.0 "c++ (Debian 13.2.0-13) 13.2.0")
C++ linker for the build machine: c++ ld.bfd 2.42
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: riscv64
Host machine cpu: riscv64
Target machine cpu family: riscv64
Target machine cpu: riscv64
meson.build:16:20: ERROR: Unknown variable "includes".
as well as my toolchain file
[binaries]
c = 'riscv64-unknown-linux-musl-gcc'
cpp = 'riscv64-unknown-linux-musl-g++'
[properties]
root = '/home/tmoney/Development/Milk.V/Duo/duo-sdk/riscv64-linux-musl-x86_64/sysroot'
[host_machine]
system = 'linux'
cpu_family = 'riscv64'
cpu= 'riscv64'
endian= 'little'
type here
2
Answers
There is no libudev as a standalone library anymore; it uses bits and pieces from various sd-* libraries (such as sd-device, which is functionally "libudev next generation" – the current version of libudev is merely a wrapper around sd-device).
Do the
meson setup
at project root, as one normally would, then runninja libudev
inside your build directory. This will build the library along with the smallest amount of dependencies.Please check https://github.com/illiliti/libudev-zero
I am working with SDL2 without X11 on small systems, and it works fine as a replacement. I have cross-compiled to aarch64 on Ubuntu 24.04 x86_64, but haven’t tested on ARM yet, only on a qemu VM (x86_64).
In SDL2 you can specify
--enable-libudev
, but then the mouse stops working, so libudev is needed and libudev-zero works as a replacement, both on build and execution.