vfo-sync

Bidirectional VFO synchronization for IC-7300 and SDR++
git clone https://git.bradleygannon.com/vfo-sync.git
Log | Files | Refs

Makefile (3348B)


      1 # Builds the civ_sync SDR++ module (Rust staticlib + C++ shim) and installs the
      2 # resulting .so into a local SDR++ config root for GUI loading.
      3 #
      4 # The SDR++ source location is configurable via the SDRPP_DIR environment
      5 # variable or `make SDRPP_DIR=...`; it defaults to $(HOME)/SDRPlusPlus.
      6 #
      7 # If a prebuilt core is available (e.g. the nixpkgs `sdrpp` output, or an
      8 # installed SDR++), point SDRPP_CORE_LIB at it to skip building the core from
      9 # source. Leave it unset to build libsdrpp_core.so from SDRPP_DIR.
     10 #
     11 # Run inside `nix develop` so cargo, cmake, g++, and the SDR++ deps are present.
     12 
     13 SHELL := bash
     14 
     15 ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
     16 
     17 SDRPP_DIR      ?= $(HOME)/SDRPlusPlus
     18 SDRPP_CORE_LIB ?=
     19 CORE_LIB       := $(if $(SDRPP_CORE_LIB),$(SDRPP_CORE_LIB),$(SDRPP_DIR)/build/core/libsdrpp_core.so)
     20 
     21 MOD_BUILD    := $(ROOT)/build
     22 MODULE_SO    := $(MOD_BUILD)/civ_sync.so
     23 
     24 DIST_ROOT    ?= $(ROOT)/dist/root
     25 MODULES_DIR  ?= $(DIST_ROOT)/modules
     26 INSTALLED_SO := $(MODULES_DIR)/civ_sync.so
     27 
     28 NPROC ?= $(shell nproc 2>/dev/null || echo 4)
     29 
     30 .PHONY: all module rust core install clean help
     31 
     32 all: module install
     33 
     34 module: rust $(CORE_LIB)
     35 	@test -d "$(SDRPP_DIR)" || { \
     36 		echo "Error: SDRPP_DIR '$(SDRPP_DIR)' does not exist."; \
     37 		echo "  Set it to your SDR++ source tree:"; \
     38 		echo "    make SDRPP_DIR=/path/to/SDRPlusPlus"; \
     39 		echo "  (or set SDRPP_CORE_LIB to a prebuilt libsdrpp_core.so and SDRPP_DIR to its source)."; \
     40 		exit 1; \
     41 	}
     42 	@echo "==> Configuring civ_sync module"
     43 	cmake -S "$(ROOT)/shim" -B "$(MOD_BUILD)" \
     44 	    -DCMAKE_BUILD_TYPE=Release \
     45 	    -DSDRPP_DIR="$(SDRPP_DIR)" \
     46 	    -DSDRPP_CORE_LIB="$(CORE_LIB)"
     47 	@echo "==> Building civ_sync module"
     48 	cmake --build "$(MOD_BUILD)" -j$(NPROC)
     49 
     50 rust:
     51 	@echo "==> Building Rust staticlib"
     52 	cargo build --release
     53 
     54 $(CORE_LIB):
     55 	@test -d "$(SDRPP_DIR)" || { \
     56 		echo "Error: SDRPP_DIR '$(SDRPP_DIR)' does not exist."; \
     57 		echo "  Clone SDR++ (https://github.com/AlexandreRouma/SDRPlusPlus) and set:"; \
     58 		echo "    make SDRPP_DIR=/path/to/SDRPlusPlus"; \
     59 		exit 1; \
     60 	}
     61 	@echo "==> Configuring SDR++ (core only)"
     62 	@opts=""; for opt in $$(grep -oE 'option\(OPT_BUILD_[A-Z0-9_]+' "$(SDRPP_DIR)/CMakeLists.txt" | sed 's/option(//' | sort -u); do opts="$${opts} -D$${opt}=OFF"; done; \
     63 	cmake -S "$(SDRPP_DIR)" -B "$(SDRPP_DIR)/build" -DCMAKE_BUILD_TYPE=Release $${opts}
     64 	@echo "==> Building sdrpp_core"
     65 	cmake --build "$(SDRPP_DIR)/build" --target sdrpp_core -j$(NPROC)
     66 
     67 core: $(CORE_LIB)
     68 
     69 install: module
     70 	@echo "==> Installing module to $(MODULES_DIR)"
     71 	mkdir -p "$(MODULES_DIR)"
     72 	cp -f "$(MODULE_SO)" "$(INSTALLED_SO)"
     73 
     74 clean:
     75 	rm -rf "$(MOD_BUILD)" "$(DIST_ROOT)"
     76 
     77 help:
     78 	@printf '%s\n' \
     79 	  'Targets:' \
     80 	  '  all      build module + install into $(MODULES_DIR) (default)' \
     81 	  '  module   build $(MODULE_SO)' \
     82 	  '  rust     build the Rust staticlib' \
     83 	  '  core     build the SDR++ core library only' \
     84 	  '  install  copy $(MODULE_SO) into $(MODULES_DIR)' \
     85 	  '  clean    remove module build dir and installed output' \
     86 	  '' \
     87 	  'Variables (env or `make VAR=...`):' \
     88 	  '  SDRPP_DIR        SDR++ source root    [default: $(SDRPP_DIR)]' \
     89 	  '  SDRPP_CORE_LIB   prebuilt core .so    [default: built from SDRPP_DIR]' \
     90 	  '  MODULES_DIR      module install dir   [default: $(MODULES_DIR)]' \
     91 	  '  NPROC            parallel jobs        [default: $(NPROC)]'