From c44e3e15c56ff4f1fa0eb6a160fb083c92d8afe5 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 28 Feb 2021 00:00:31 -0800 Subject: [PATCH] Pass version in from build --- Makefile | 4 ++-- main.c | 5 ++--- src/lib.rs | 9 ++++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 8c67d43..fea8bc7 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CC ?= gcc VERSION = $(shell git describe --tags --abbrev=0) GITCOUNT = $(shell git rev-list HEAD --count) UNAME = $(shell uname) - +VERSION_STR = '$(VERSION).$(GITCOUNT)' OBJS = main.o util.o radio.o dfu-libusb.o uv380.o md380.o rd5r.o \ gd77.o hid.o serial.o d868uv.o dm1801.o CFLAGS ?= -g -O -Wall -Werror @@ -61,7 +61,7 @@ install: dmrconfig .PHONY: $(RUST_RELEASE) target/release/libdmrconfig.a: - cargo build --verbose --release + VERSION=$(VERSION_STR) cargo build --verbose --release ### d868uv.o: d868uv.c radio.h util.h d868uv-map.h diff --git a/main.c b/main.c index 23ea098..6388b14 100644 --- a/main.c +++ b/main.c @@ -37,14 +37,13 @@ extern char *optarg; extern int optind; extern void print_message_from_rust(); -extern void print_usage(const char* version); -extern void print_usage(const char* version); +extern void print_usage(); extern int rust_main(int argc, char** argv); int trace_flag = 0; void usage() { - print_usage((const char*)version); + print_usage(); } int main(int argc, char **argv) { diff --git a/src/lib.rs b/src/lib.rs index b7e7511..7f4ec9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -use std::ffi::CStr; use libc::{c_int, c_char}; use getopts::Options; use std::process::exit; @@ -6,14 +5,15 @@ use std::process::exit; mod radio; const COPYRIGHT: &'static str = "Copyright (C) 2018 Serge Vakulenko KK6ABQ"; +const VERSION: Option<&'static str> = option_env!("VERSION"); extern { fn old_c_main(argc: c_int, argv: *const *const c_char) -> c_int; } #[no_mangle] -pub extern "C" fn print_usage(version_ptr: *const c_char) { - let version: String = unsafe { CStr::from_ptr(version_ptr) }.to_string_lossy().to_string(); +pub extern "C" fn print_usage() { + let version = VERSION.unwrap_or("-----"); print!("DMR Config, Version {}, {}", version, COPYRIGHT); @@ -85,8 +85,7 @@ pub extern "C" fn rust_main(argc: c_int, argv: *const *const c_char) -> c_int { if [read_flag, write_flag, config_flag, csv_flag, verify_flag].iter().filter(|x| **x).count() > 1 { eprintln!("Only one of -r, -w, -c, -v or -u options is allowed."); - exit(-1); - //print_usage(); + print_usage(); } unsafe {