cmd: add and print --version
on startup
This commit is contained in:
parent
20ca08ffad
commit
65e3b17397
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ tmp/
|
||||
/test_*
|
||||
.vscode/
|
||||
/Procfile*
|
||||
/version.h
|
||||
|
18
Makefile
18
Makefile
@ -3,6 +3,9 @@ SRC := $(wildcard **/*.c **/*/*.c **/*.cc **/*/*.cc)
|
||||
HEADERS := $(wildcard **/*.h **/*/*.h **/*.hh **/*/*.hh)
|
||||
HTML := $(wildcard html/*.js html/*.html)
|
||||
|
||||
GIT_VERSION ?= $(shell git describe --tags)
|
||||
GIT_REVISION ?= $(shell git rev-parse --short HEAD)
|
||||
|
||||
CFLAGS := -Werror -Wall -g -I$(CURDIR) -D_GNU_SOURCE
|
||||
LDLIBS := -lpthread -lstdc++
|
||||
|
||||
@ -45,16 +48,25 @@ LDLIBS += -L$(LIBDATACHANNEL_PATH)/build/deps/usrsctp/usrsctplib -lusrsctp
|
||||
LDLIBS += -L$(LIBDATACHANNEL_PATH)/build/deps/libsrtp -lsrtp2
|
||||
LDLIBS += -L$(LIBDATACHANNEL_PATH)/build/deps/libjuice -ljuice-static
|
||||
LDLIBS += -lcrypto -lssl
|
||||
|
||||
camera-streamer: $(LIBDATACHANNEL_PATH)/build/libdatachannel-static.a
|
||||
endif
|
||||
|
||||
HTML_SRC = $(addsuffix .c,$(HTML))
|
||||
OBJS = $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(SRC) $(HTML_SRC)))
|
||||
|
||||
all: version
|
||||
+make $(TARGET)
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
all: $(TARGET)
|
||||
ifeq (1,$(USE_LIBDATACHANNEL))
|
||||
camera-streamer: $(LIBDATACHANNEL_PATH)/build/libdatachannel-static.a
|
||||
endif
|
||||
|
||||
.PHONY: version
|
||||
version:
|
||||
echo "#define GIT_VERSION \"$(GIT_VERSION)\"\n#define GIT_REVISION \"$(GIT_REVISION)\"" > version.h.tmp; \
|
||||
diff -u version.h version.h.tmp || mv version.h.tmp version.h; \
|
||||
rm -f version.h.tmp
|
||||
|
||||
%: cmd/% $(filter-out third_party/%, $(OBJS))
|
||||
$(CCACHE) $(CXX) $(CFLAGS) -o $@ $(filter-out cmd/%, $^) $(filter $</%, $^) $(LDLIBS)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "device/camera/camera.h"
|
||||
#include "output/rtsp/rtsp.h"
|
||||
#include "output/webrtc/webrtc.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
@ -56,6 +57,8 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("%s Version: %s (%s)\n", argv[0], GIT_VERSION, GIT_REVISION);
|
||||
|
||||
deprecations();
|
||||
inherit();
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "opts.h"
|
||||
#include "version.h"
|
||||
#include "util/opts/log.h"
|
||||
|
||||
#include <stddef.h>
|
||||
@ -7,6 +8,11 @@
|
||||
|
||||
#define OPT_LENGTH 30
|
||||
|
||||
static void print_version(const char *cmd)
|
||||
{
|
||||
printf("%s (%s)\n", GIT_VERSION, GIT_REVISION);
|
||||
}
|
||||
|
||||
static void print_help(option_t *options, const char *cmd)
|
||||
{
|
||||
printf("Usage:\n");
|
||||
@ -88,7 +94,7 @@ static void print_help(option_t *options, const char *cmd)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static int parse_opt(option_t *options, const char *key)
|
||||
static int parse_opt(option_t *options, const char *key, int dash)
|
||||
{
|
||||
option_t *option = NULL;
|
||||
const char *value = strchr(key, '=');
|
||||
@ -110,6 +116,12 @@ static int parse_opt(option_t *options, const char *key)
|
||||
}
|
||||
}
|
||||
|
||||
if (dash == 2 && strlen(key) == 1) {
|
||||
LOG_INFO(NULL, "Usage of '--%s' is deprecated change to '-%s'.", key, key);
|
||||
} else if (dash == 1 && strlen(key) > 1) {
|
||||
LOG_INFO(NULL, "Usage of '-%s' is deprecated change to '--%s'.", key, key);
|
||||
}
|
||||
|
||||
LOG_DEBUG(NULL, "Parsing '%s'. Got value='%s', and option='%s'", key, value, option ? option->name : NULL);
|
||||
|
||||
if (!option || !value) {
|
||||
@ -152,18 +164,26 @@ int parse_opts(option_t *options, int argc, char *argv[])
|
||||
|
||||
if (key[0] == '-') {
|
||||
key++;
|
||||
if (key[0] == '-')
|
||||
if (key[0] == '-') {
|
||||
key++;
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR(NULL, "The '%s' is not option (should start with - or --).", key);
|
||||
}
|
||||
|
||||
if (!strcmp(key, "help")) {
|
||||
print_help(options, argv[0]);
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = parse_opt(options, key);
|
||||
if (!strcmp(key, "version")) {
|
||||
print_version(argv[0]);
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = parse_opt(options, key, key - argv[arg]);
|
||||
if (ret <= 0) {
|
||||
LOG_ERROR(NULL, "Parsing '%s' returned '%d'.", argv[arg], ret);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user