Mr-Precise / rtl-sdr

RTL-SDR *very* experimental branch. Modded R820T and R820T2 driver. Nohw-mod
https://github.com/Mr-Precise/rtl-sdr
GNU General Public License v2.0
6 stars 0 forks source link

Building on Haiku (OS) #2

Open victroniko opened 1 year ago

victroniko commented 1 year ago

Hello there!

I'm on a quest for building and making rtl-sdr work on Haiku, AFAIK no one had tried it before. After fiddling a bit I've built and ran it (more or less) succesfully with autotool, from the original OSMOCOM repos. Sadly it doesn't build at all with cmake.

This fork looks really interesting and I want to port this one to Haiku, instead of the original... but it also fails to build with cmake, with the exact same error:

... [ 75%] Linking C executable rtl_test /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: cannot find -lrt collect2: error: ld returned 1 exit status src/CMakeFiles/rtl_test.dir/build.make:99: recipe for target 'src/rtl_test' failed

With autotool, the script checks if function _clockgettime is available and fails gracefully when it's not, which allows the build to continue. OTOH, cmake forces the -lrt flag always, and bails out when it finds librt (which provides _clockgettime) isn't available.

Thing is, in Haiku librt does not exist. _clockgettime equivalent functionality resides in libroot (/system/lib/libroot.so)

Is it possible to add a provision for checking the target platform, and if it's Haiku then use libroot instead of librt? Maybe it's trivial but I fear it's a bit out of my coding knowledge, as I looked and fiddled w/many files (ie. CMakeLists.txt) with no success.

Here's a pic of rtl_test running on Haiku, to demonstrate a working build:

rtlsdr_rtl-test

Mr-Precise commented 1 year ago

I have never used this OS I will try to install haiku os soon and I'll try to fix it

Mr-Precise commented 1 year ago

Build fixed. Can you check the build from devel branch (before I push this change to main)? git clone https://github.com/Mr-Precise/rtl-sdr/ -b devel

Mr-Precise commented 1 year ago

ohh I have the same problem on Windows bind ip broken in rtl_tcp afrer add IPv6 support rtl_tcp ...although it works fine on Linux & macOS

Mr-Precise commented 1 year ago

I created haiku branch based on main-win + CMake fix Or will have to use haiku branch or full remove IPv6 support from rtl_tcp and use old code https://github.com/Mr-Precise/rtl-sdr/commit/c1aed9f9ad5e49cd2f5a052c8aad4e1b3098f73b

old

victroniko commented 1 year ago

I can confirm haiku branch builds and works ok on Haiku x86_64.

Note that it fails at make install step: seems paths are hardcoded to install to /boot/system and this won't do, as Haiku sys-dirs are read only. (Packages are built in a simulated environment, and ideally scripts should use syscalls to find the various dirs like bin, lib etc.) However, this step isn't necessary because I'm using haikuporter to make a ready-to-use binary package. I can use the tool abstractions for the various install paths, like this:

screenshot2 build-ok

re: IPv6, at least for Haiku target I think it can be safely ignored/disabled for now.

Mr-Precise commented 1 year ago

I think I completely fixed the problem with binding to IP/IPv6 in Windows & Haiku OS. All changes moved to main. image Install path - In the process of testing. I will try to fix it

Mr-Precise commented 1 year ago

I still don't understand how to install without creating a package google knows little about cmake on haiku cmake .. -DCMAKE_INSTALL_PREFIX=/system/non-packaged works... what

victroniko commented 1 year ago

I asked Haiku devs, they say cmake scripts should follow GnuInstallDirs setup. This improves portability, and your fork will build not only on Haiku but also every OS that follows GNU standard install dirs.

edit. full dev answer here with tips on how to do a local install (which is more for testing, really not needed for packaging).

Begasus commented 1 year ago

Is there a way to disable the build/install for the static library? (couldn't find an option with cmake -L)

Mr-Precise commented 1 year ago

@Begasus I probably implemented what you wanted. Use -DINSTALL_STATIC_LIB=NO To do this, it is better to use a feature request.

Begasus commented 1 year ago

Thanks! That worked out ok :) didn't want to step in before @victroniko made a PR for this, already commented on the forum thread reported earlier here to fix the install paths. Can't check this in other OS's but I think it should be ok (if you got some time to look into that).

victroniko commented 1 year ago

@Begasus I'll be a bit low on time next week, if you want/can do a PR then please go ahead, no worries :)

@Mr-Precise ATM dev branch builds ok (inside haikuporter) with this: cmake -DCMAKE_BUILD_TYPE=Release -DINSTALL_STATIC_LIB=NO -Bbuild $cmakeDirArgs

$cmakeDirArgs is just something we use for building w/haikuporter, don't worry about it.

edit. If dev branch builds OK on other platforms too, then we're all set.

Begasus commented 1 year ago

@victroniko main branch builds fine here, posted a reply in the forum with the recipe I tested just a few minutes ago :)

Mr-Precise commented 1 year ago

Can you check for compatibility after recent changes?

victroniko commented 1 year ago

One last push: GNUInstallDirs setup needs to live before install options, otherwise CMake won't pick it up.

--- CMakeLists.txt      2023-02-14 14:56:24.043515904 -0300
+++ CMakeLists.txt.diff 2023-02-21 23:46:52.618397696 -0300
@@ -42,6 +42,12 @@
 include(GenerateExportHeader)
 include(CMakePackageConfigHelpers)

+# Set paths early according to GNUInstallDirs (fixes Haiku build)
+set(prefix "${CMAKE_INSTALL_PREFIX}")
+set(exec_prefix \${prefix})
+set(includedir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR})
+set(libdir \${exec_prefix}/${CMAKE_INSTALL_LIBDIR})
+
 # Set the version information here
 set(VERSION_INFO_MAJOR_VERSION 2023) # increment major on api compatibility changes
 set(VERSION_INFO_MINOR_VERSION 2) # increment minor on feature-level changes
@@ -198,11 +204,6 @@
     UNSET(RTLSDR_PC_LIBS)
 ENDIF(CMAKE_CROSSCOMPILING)

-set(prefix "${CMAKE_INSTALL_PREFIX}")
-set(exec_prefix \${prefix})
-set(includedir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR})
-set(libdir \${exec_prefix}/${CMAKE_INSTALL_LIBDIR})
-
 CONFIGURE_FILE(
     ${CMAKE_CURRENT_SOURCE_DIR}/librtlsdr.pc.in
     ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc

With this, main branch builds perfect in Haiku :D

Mr-Precise commented 1 year ago

It seems to work well through Virtualbox... vboxhaiku

victroniko commented 1 year ago

Main branch now builds OK on Haiku x86_64, confirmed!


OTOH, on x86_32... it doesn't find libusb, but it is clearly installed:

Captura

Pointing pkg_search_modules() to _libusbx86 doesn't seem to work. @Begasus can you lend us a hand? I'm a bit lost how to pass _x86 Haiku libs to Cmake...

Begasus commented 1 year ago

You probably have to switch compiler (don't have Haiku running atm) for 32bit, in Terminal type: setarch x86 (this will switch compiler from gcc2. to gcc11.), then try again. :) (exit will get you back to gcc2 (you can also check with gcc -v in Terminal which one is being used))

victroniko commented 1 year ago

Switched architecture, no luck... I'll ask on Haiku forums and report back here.

btw. Falkon browser is very unstable - use Web (ex Ephiphany) instead.

Begasus commented 1 year ago

Just checked out the latest commit on main and it's still building OK with haikuports here: https://github.com/Begasus/haikuports/commit/59bba256de23eb5508f6801febf9a49d650623ba

EDIT building from Terminal works fine too:

rtl-sdr

victroniko commented 1 year ago

On x86_64 it builds fine, both w/ haikuporter and from terminal.

Building on x86_gcc11 is what doesn't work for me. As it appears to be something on Haiku side, i'll better ask in the forum :)

Mr-Precise commented 1 year ago

I will install the 32 bit version of haiku soon and try to check and fix Just a little later, I'm sick

Mr-Precise commented 1 year ago

Screenshot_20230225_165744 🙂

Mr-Precise commented 1 year ago

I released version 2023.8.25. Change log rtl-sdr/releases/v2023.8.25 I think this is enough to update in haikuports.

Begasus commented 1 year ago

Did a quick check, still builds and package fine on 64bit, can't check it myself as I don't have any supported devices though. Will do an update tomorrow for this @victroniko if you can could you check it out and report back?

EDIT: pushed the changes, will check in the morning if both arches were build fine on our buildmasters. Updated PR's https://github.com/haikuports/haikuports/pull/9505