diff --git a/Makefile.in b/Makefile.in index 7a94b158..6c83c72d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -82,7 +82,7 @@ $(MDPCLIENTOBJS): $(HDRS) servald: $(OBJS) @echo LINK $@ - @$(CC) $(CFLAGS) -Wall -o $@ $(OBJS) $(LDFLAGS) + @v=`./version_string.sh` && $(CC) $(CFLAGS) -Wall -o $@ -DSERVALD_VERSION="\"$$v\"" version_servald.c $(OBJS) $(LDFLAGS) directory_service: $(MDPCLIENTOBJS) directory_service.o @echo LINK $@ diff --git a/commandline.c b/commandline.c index 4f5d6260..b0be726f 100644 --- a/commandline.c +++ b/commandline.c @@ -49,7 +49,7 @@ extern struct cli_schema command_line_options[]; int commandline_usage(const struct cli_parsed *parsed, void *context) { - printf("Serval Mesh version .\n"); + printf("Serval DNA version %s\n", version_servald); return cli_usage(command_line_options); } diff --git a/serval.h b/serval.h index ac676b76..7589f7c5 100644 --- a/serval.h +++ b/serval.h @@ -141,6 +141,9 @@ struct in_addr { /* Limit packet payloads to minimise packet loss of big packets in mesh networks */ #define MAX_DATA_BYTES 256 + +extern const char version_servald[]; + /* * INSTANCE_PATH can be set via the ./configure option --enable-instance-path= */ diff --git a/version_servald.c b/version_servald.c new file mode 100644 index 00000000..32028fd5 --- /dev/null +++ b/version_servald.c @@ -0,0 +1,5 @@ +#ifndef SERVALD_VERSION +#error "SERVALD_VERSION is not defined" +#endif + +const char version_servald[] = SERVALD_VERSION; diff --git a/version_string.sh b/version_string.sh new file mode 100755 index 00000000..4e862f2a --- /dev/null +++ b/version_string.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# Serval Project Serval DNA version string generator +# Copyright 2013 Serval Project, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +set -e + +get_author_label() { + # See git-commit-tree(1) for the semantics of working out the author's email + # address when committing. + local email + email="${GIT_AUTHOR_EMAIL:-${GIT_COMMITTER_EMAIL:-${EMAIL:-$(git config --get user.email)}}}" + # Serval Project email addresses get special treatment, to reduce day-to-day + # version string verbosity. + case "$email" in + *@servalproject.org) author_label="${email%@*}";; + *) author_label="$email";; + esac +} + +dirty= +dirtyfiles=$(git status --short --untracked-files=no) +if [ -n "$dirtyfiles" ]; then + get_author_label + dirty="+$author_label-$(date '+%Y%m%d%H%M%S')" +fi + +if ! git describe "${dirty:+--dirty=$dirty}" 2>/dev/null; then + original_commit=$(git rev-list --reverse --max-parents=0 --abbrev-commit HEAD 2>/dev/null | head -n 1) + if [ -n "$original_commit" ]; then + original_commit=$(git rev-list --reverse --abbrev-commit HEAD | head -n 1) + fi + if [ -z "$original_commit" ]; then + echo "$0: original commit unknown" >&2 + exit 1 + fi + existing_start_tag="$(git tag --points-at $original_commit --list START)" + if [ -n "$(git tag --list START)" -a -z "$existing_start_tag" ]; then + echo "$0: tag 'START' is already in use" >&2 + exit 1 + fi + if [ -z "$existing_start_tag" ]; then + git tag START $original_commit + fi + git describe --dirty="$dirty" --tags + if [ -z "$existing_start_tag" ]; then + git tag -d START >/dev/null + fi +fi