diff --git a/Makefile.am b/Makefile.am index 1aa424f754..1a0759b166 100644 --- a/Makefile.am +++ b/Makefile.am @@ -422,7 +422,10 @@ src/include/switch_version.h: src/include/switch_version.h.in Makefile build/pri @cat $< > $@; \ if [ -d .git ] && [ -n "$$(which git)" ]; then \ xver="$$(./build/print_git_revision)"; \ - sed -e "/#define *SWITCH_VERSION_REVISION/{s/\"\([^\"]*\)\"/\"\1$$xver\"/;}" \ + xhver="$$(./build/print_git_revision -h)"; \ + sed \ + -e "/#define *SWITCH_VERSION_REVISION\W/{s/\"\([^\"]*\)\"/\"\1$$xver\"/;}" \ + -e "/#define *SWITCH_VERSION_REVISION_HUMAN\W/{s/\"\([^\"]*\)\"/\"\1$$xhver\"/;}" \ $< > $@; \ fi; diff --git a/build/print_git_revision.c b/build/print_git_revision.c index 7358003832..0f8e680b37 100644 --- a/build/print_git_revision.c +++ b/build/print_git_revision.c @@ -42,7 +42,7 @@ static int sys1(char *buf, int buflen, char *cmd) { return 0; } -int main(int argc, char **argv) { +static int print_version(void) { char xver[256], xdate[256], xfdate[256], xcommit[256]; time_t xdate_t; struct tm *xdate_tm; if ((sys1(xdate,sizeof(xdate),"git log -n1 --format='%ct' HEAD"))) return 1; @@ -63,3 +63,31 @@ int main(int argc, char **argv) { return 0; } +static int print_human_version(void) { + char xver[256], xdate[256], xfdate[256], xcommit[256]; + time_t xdate_t; struct tm *xdate_tm; + if ((sys1(xdate,sizeof(xdate),"git log -n1 --format='%ct' HEAD"))) return 1; + xdate_t=(time_t)atoi(xdate); + if (!(xdate_tm=gmtime(&xdate_t))) return 1; + strftime(xfdate,sizeof(xfdate),"%a, %d %b %Y %H:%M:%S Z",xdate_tm); + if ((sys1(xcommit,sizeof(xcommit),"git rev-list -n1 --abbrev=10 --abbrev-commit HEAD"))) + return 1; + snprintf(xver,sizeof(xver),"; git at commit %s on %s",xcommit,xfdate); + if (show_unclean && (sys(NULL,0,"git diff-index --quiet HEAD"))) { + char buf[256], now[256]; time_t now_t=time(NULL); struct tm *now_tm; + if (!(now_tm=gmtime(&now_t))) return 1; + strftime(now,sizeof(now),"%a, %d %b %Y %H:%M:%S Z",now_tm); + snprintf(buf,sizeof(buf),"%s; unclean git build on %s",xver,now); + strncpy(xver,buf,sizeof(xver)); + } + printf("%s\n",xver); + return 0; +} + +int main(int argc, char **argv) { + if (argc > 1 && !strcasecmp(argv[1],"-h")) + return print_human_version(); + else + return print_version(); +} + diff --git a/configure.in b/configure.in index 514a9151e4..899b0b83c2 100644 --- a/configure.in +++ b/configure.in @@ -8,6 +8,7 @@ AC_SUBST(SWITCH_VERSION_MAJOR, [1]) AC_SUBST(SWITCH_VERSION_MINOR, [2]) AC_SUBST(SWITCH_VERSION_MICRO, [0]) AC_SUBST(SWITCH_VERSION_REVISION, [-rc2]) +AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, [-rc2]) AC_CONFIG_FILES([src/include/switch_version.h.in:src/include/switch_version.h.template]) diff --git a/scripts/ci/common.sh b/scripts/ci/common.sh index 3aa6bb3441..059def200e 100755 --- a/scripts/ci/common.sh +++ b/scripts/ci/common.sh @@ -98,15 +98,18 @@ parse_version () { } set_fs_ver () { - local ver="$1" major="$2" minor="$3" micro="$4" rev="$5" + local ver="$1" major="$2" minor="$3" micro="$4" rev="$5" hrev="$6" sed -e "s|\(AC_SUBST(SWITCH_VERSION_MAJOR, \[\).*\(\])\)|\1$major\2|" \ -e "s|\(AC_SUBST(SWITCH_VERSION_MINOR, \[\).*\(\])\)|\1$minor\2|" \ -e "s|\(AC_SUBST(SWITCH_VERSION_MICRO, \[\).*\(\])\)|\1$micro\2|" \ -e "s|\(AC_INIT(\[freeswitch\], \[\).*\(\], BUG-REPORT-ADDRESS)\)|\1$ver\2|" \ -i configure.in if [ -n "$rev" ]; then + [ -n "$hrev" ] || hrev="$rev" sed -e "s|\(AC_SUBST(SWITCH_VERSION_REVISION, \[\).*\(\])\)|\1$rev\2|" \ + -e "s|\(AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, \[\).*\(\])\)|\1$hrev\2|" \ -e "s|#\(AC_SUBST(SWITCH_VERSION_REVISION\)|\1|" \ + -e "s|#\(AC_SUBST(SWITCH_VERSION_REVISION_HUMAN\)|\1|" \ -i configure.in fi } diff --git a/scripts/dailys.sh b/scripts/dailys.sh index 9d0e639cf5..430de62d22 100755 --- a/scripts/dailys.sh +++ b/scripts/dailys.sh @@ -44,7 +44,9 @@ sed -e "s|\(AC_SUBST(SWITCH_VERSION_MAJOR, \[\).*\(\])\)|\1$major\2|" \ if [ -n "$rev" ]; then sed -e "s|\(AC_SUBST(SWITCH_VERSION_REVISION, \[\).*\(\])\)|\1$rev\2|" \ + -e "s|\(AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, \[\).*\(\])\)|\1$rev\2|" \ -e "s|#\(AC_SUBST(SWITCH_VERSION_REVISION\)|\1|" \ + -e "s|#\(AC_SUBST(SWITCH_VERSION_REVISION_HUMAN\)|\1|" \ -i configure.in fi diff --git a/src/include/switch_version.h.cmake b/src/include/switch_version.h.cmake index 7cec6489b3..c722c2221d 100644 --- a/src/include/switch_version.h.cmake +++ b/src/include/switch_version.h.cmake @@ -41,7 +41,9 @@ extern "C" { #define SWITCH_VERSION_MINOR "@freeswitch_MINOR_VERSION@" #define SWITCH_VERSION_MICRO "@freeswitch_PATCH_LEVEL@" #define SWITCH_VERSION_REVISION "@Project_WC_REVISION@" +#define SWITCH_VERSION_REVISION_HUMAN "@Project_WC_REVISION@" #define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO SWITCH_VERSION_REVISION +#define SWITCH_VERSION_FULL_HUMAN SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO SWITCH_VERSION_REVISION_HUMAN #ifdef __cplusplus } diff --git a/src/include/switch_version.h.template b/src/include/switch_version.h.template index e0c13811d8..dfec6e091e 100644 --- a/src/include/switch_version.h.template +++ b/src/include/switch_version.h.template @@ -41,7 +41,9 @@ extern "C" { #define SWITCH_VERSION_MINOR "@SWITCH_VERSION_MINOR@" #define SWITCH_VERSION_MICRO "@SWITCH_VERSION_MICRO@" #define SWITCH_VERSION_REVISION "@SWITCH_VERSION_REVISION@" +#define SWITCH_VERSION_REVISION_HUMAN "@SWITCH_VERSION_REVISION_HUMAN@" #define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO SWITCH_VERSION_REVISION +#define SWITCH_VERSION_FULL_HUMAN SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO SWITCH_VERSION_REVISION_HUMAN #ifdef __cplusplus } diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 21a1cb3138..1cde9b30ce 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -285,7 +285,7 @@ SWITCH_STANDARD_API(shutdown_function) SWITCH_STANDARD_API(version_function) { - stream->write_function(stream, "FreeSWITCH Version %s\n", SWITCH_VERSION_FULL); + stream->write_function(stream, "FreeSWITCH Version %s (%s)\n", SWITCH_VERSION_FULL, SWITCH_VERSION_FULL_HUMAN); return SWITCH_STATUS_SUCCESS; } diff --git a/src/switch.c b/src/switch.c index 4f25701671..e1b602356e 100644 --- a/src/switch.c +++ b/src/switch.c @@ -577,7 +577,7 @@ int main(int argc, char *argv[]) } else if (!strcmp(local_argv[x], "-version")) { - fprintf(stdout, "FreeSWITCH version: %s\n", SWITCH_VERSION_FULL); + fprintf(stdout, "FreeSWITCH version: %s (%s)\n", SWITCH_VERSION_FULL, SWITCH_VERSION_FULL_HUMAN); exit(EXIT_SUCCESS); } #endif diff --git a/src/switch_core.c b/src/switch_core.c index 789b2d2c12..c00f13ab78 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1959,7 +1959,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(switch_core_flag_t switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, - "\nFreeSWITCH Version %s Started.\nMax Sessions[%u]\nSession Rate[%d]\nSQL [%s]\n", SWITCH_VERSION_FULL, + "\nFreeSWITCH Version %s (%s) Started.\nMax Sessions[%u]\nSession Rate[%d]\nSQL [%s]\n", + SWITCH_VERSION_FULL, SWITCH_VERSION_FULL_HUMAN, switch_core_session_limit(0), switch_core_sessions_per_second(0), switch_test_flag((&runtime), SCF_USE_SQL) ? "Enabled" : "Disabled");