Pass version in from build

This commit is contained in:
Greg Shuflin 2021-02-28 00:00:31 -08:00
parent d41d257650
commit c44e3e15c5
3 changed files with 8 additions and 10 deletions

View File

@ -3,7 +3,7 @@ CC ?= gcc
VERSION = $(shell git describe --tags --abbrev=0) VERSION = $(shell git describe --tags --abbrev=0)
GITCOUNT = $(shell git rev-list HEAD --count) GITCOUNT = $(shell git rev-list HEAD --count)
UNAME = $(shell uname) UNAME = $(shell uname)
VERSION_STR = '$(VERSION).$(GITCOUNT)'
OBJS = main.o util.o radio.o dfu-libusb.o uv380.o md380.o rd5r.o \ 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 gd77.o hid.o serial.o d868uv.o dm1801.o
CFLAGS ?= -g -O -Wall -Werror CFLAGS ?= -g -O -Wall -Werror
@ -61,7 +61,7 @@ install: dmrconfig
.PHONY: $(RUST_RELEASE) .PHONY: $(RUST_RELEASE)
target/release/libdmrconfig.a: 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 d868uv.o: d868uv.c radio.h util.h d868uv-map.h

5
main.c
View File

@ -37,14 +37,13 @@ extern char *optarg;
extern int optind; extern int optind;
extern void print_message_from_rust(); extern void print_message_from_rust();
extern void print_usage(const char* version); extern void print_usage();
extern void print_usage(const char* version);
extern int rust_main(int argc, char** argv); extern int rust_main(int argc, char** argv);
int trace_flag = 0; int trace_flag = 0;
void usage() { void usage() {
print_usage((const char*)version); print_usage();
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {

View File

@ -1,4 +1,3 @@
use std::ffi::CStr;
use libc::{c_int, c_char}; use libc::{c_int, c_char};
use getopts::Options; use getopts::Options;
use std::process::exit; use std::process::exit;
@ -6,14 +5,15 @@ use std::process::exit;
mod radio; mod radio;
const COPYRIGHT: &'static str = "Copyright (C) 2018 Serge Vakulenko KK6ABQ"; const COPYRIGHT: &'static str = "Copyright (C) 2018 Serge Vakulenko KK6ABQ";
const VERSION: Option<&'static str> = option_env!("VERSION");
extern { extern {
fn old_c_main(argc: c_int, argv: *const *const c_char) -> c_int; fn old_c_main(argc: c_int, argv: *const *const c_char) -> c_int;
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn print_usage(version_ptr: *const c_char) { pub extern "C" fn print_usage() {
let version: String = unsafe { CStr::from_ptr(version_ptr) }.to_string_lossy().to_string(); let version = VERSION.unwrap_or("-----");
print!("DMR Config, Version {}, {}", version, COPYRIGHT); 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 { 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."); eprintln!("Only one of -r, -w, -c, -v or -u options is allowed.");
exit(-1); print_usage();
//print_usage();
} }
unsafe { unsafe {