Skip to content

Commit

Permalink
add version function, wire it up from the makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
falconindy committed Apr 10, 2013
1 parent 230a127 commit 30cd588
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
10 changes: 8 additions & 2 deletions Makefile
@@ -1,6 +1,13 @@
V=1
VDEVEL=$(shell test -d .git && git describe 2>/dev/null)

ifneq "$(VDEVEL)" ""
V=$(VDEVEL)
endif

CXX := $(CXX) -std=c++11 CXX := $(CXX) -std=c++11


base_CXXFLAGS = -Wall -Wextra -pedantic -O2 -g base_CXXFLAGS = -Wall -Wextra -pedantic -O2 -g -DPONYMIX_VERSION=\"$(V)\"
base_LIBS = -lm base_LIBS = -lm


libpulse_CXXFLAGS = $(shell pkg-config --cflags libpulse) libpulse_CXXFLAGS = $(shell pkg-config --cflags libpulse)
Expand Down Expand Up @@ -35,6 +42,5 @@ install: ponymix
clean: clean:
$(RM) ponymix pulse.o $(RM) ponymix pulse.o


V=$(shell if test -d .git; then git describe; fi)
dist: dist:
git archive --format=tar --prefix=ponymix-$(V)/ HEAD | gzip -9 > ponymix-$(V).tar.gz git archive --format=tar --prefix=ponymix-$(V)/ HEAD | gzip -9 > ponymix-$(V).tar.gz
2 changes: 1 addition & 1 deletion bash-completion
Expand Up @@ -10,7 +10,7 @@ in_array() {
_ponymix() { _ponymix() {
local flags='-h --help -c --card -d --device -t --devtype local flags='-h --help -c --card -d --device -t --devtype
-N --notify --source --input --sink --output -N --notify --source --input --sink --output
--sink-input --source-output' --sink-input --source-output -V --version'
local types='sink sink-input source source-output' local types='sink sink-input source source-output'
local verbs=(help defaults set-default list list-short local verbs=(help defaults set-default list list-short
list-cards list-cards-short get-volume set-volume list-cards list-cards-short get-volume set-volume
Expand Down
14 changes: 12 additions & 2 deletions ponymix.cc
Expand Up @@ -473,10 +473,16 @@ static const std::pair<const string, const Command>& string_to_command(
return *match; return *match;
} }


static void version() {
fputs("ponymix v" PONYMIX_VERSION "\n", stdout);
exit(EXIT_SUCCESS);
}

static void usage() { static void usage() {
printf("usage: %s [options] <command>...\n", program_invocation_short_name); printf("usage: %s [options] <command>...\n", program_invocation_short_name);
fputs("\nOptions:\n" fputs("\nOptions:\n"
" -h, --help display this help and exit\n\n" " -h, --help display this help and exit\n"
" -V, --version display program version and exit\n\n"


" -c, --card CARD target card (index or name)\n" " -c, --card CARD target card (index or name)\n"
" -d, --device DEVICE target device (index or name)\n" " -d, --device DEVICE target device (index or name)\n"
Expand Down Expand Up @@ -559,6 +565,7 @@ bool parse_options(int argc, char** argv) {
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "notify", no_argument, 0, 'N' }, { "notify", no_argument, 0, 'N' },
{ "type", required_argument, 0, 't' }, { "type", required_argument, 0, 't' },
{ "version", no_argument, 0, 'V' },
{ "sink", no_argument, 0, 0x100 }, { "sink", no_argument, 0, 0x100 },
{ "output", no_argument, 0, 0x101 }, { "output", no_argument, 0, 0x101 },
{ "source", no_argument, 0, 0x102 }, { "source", no_argument, 0, 0x102 },
Expand All @@ -569,7 +576,7 @@ bool parse_options(int argc, char** argv) {
}; };


for (;;) { for (;;) {
int opt = getopt_long(argc, argv, "c:d:hNt:", opts, nullptr); int opt = getopt_long(argc, argv, "c:d:hNt:V", opts, nullptr);
if (opt == -1) if (opt == -1)
break; break;


Expand All @@ -590,6 +597,9 @@ bool parse_options(int argc, char** argv) {
opt_devtype = string_to_devtype_or_die(optarg); opt_devtype = string_to_devtype_or_die(optarg);
opt_listrestrict = true; opt_listrestrict = true;
break; break;
case 'V':
version();
break;
case 0x100: case 0x100:
case 0x101: case 0x101:
opt_devtype = DEVTYPE_SINK; opt_devtype = DEVTYPE_SINK;
Expand Down
2 changes: 2 additions & 0 deletions zsh-completion
Expand Up @@ -107,6 +107,8 @@ else
'(-c --card -d --device)'{-d,--device}'[Select Device]:devices:_devices' \ '(-c --card -d --device)'{-d,--device}'[Select Device]:devices:_devices' \
- '(help)' \ - '(help)' \
{-h,--help}'[display this help and exit]' \ {-h,--help}'[display this help and exit]' \
- '(version)' \
{-V,--version}'[display program version and exit]' \
- '(sink)' \ - '(sink)' \
'--sink[alias to type sink]' \ '--sink[alias to type sink]' \
'--output[alias to type sink]' \ '--output[alias to type sink]' \
Expand Down

0 comments on commit 30cd588

Please sign in to comment.