From 54bc2c20b66d919f1df26faa637774ad40b343f1 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Sat, 5 Jan 2008 22:09:06 +0000 Subject: [PATCH] Now that the version.h file was getting properly regenerated every time the svn revision changed, every module that used the version was getting rebuilt after every svn update. This severly annoyed me pretty quickly, so I have improved the situation. Now, instead of generating version.h, main/version.c is generated. version.c includes the version information, as well as a couple of API calls for modules to retrieve the version. So now, only version.c will get rebuilt, and the main asterisk binary relinked, which is must faster than rebuilding http.c, manager.c, asterisk.c, relinking the asterisk binary, chan_sip.c, func_version.c, res_agi ... The only minor change in behavior here is that the version information reported by chan_sip, for example, is the version of the Asterisk core, and not necessarily the Asterisk version that the chan_sip module came from. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@96717 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- Makefile | 12 +++++------ build_tools/make_version_c | 33 ++++++++++++++++++++++++++++ build_tools/make_version_h | 17 --------------- channels/chan_sip.c | 4 ++-- funcs/func_version.c | 26 ++++++++++------------ include/asterisk/version.h | 44 ++++++++++++++++++++++++++++++++++++++ main/Makefile | 2 +- main/asterisk.c | 14 ++++++------ main/http.c | 4 ++-- main/manager.c | 2 +- res/res_agi.c | 2 +- 11 files changed, 108 insertions(+), 52 deletions(-) create mode 100755 build_tools/make_version_c delete mode 100755 build_tools/make_version_h create mode 100644 include/asterisk/version.h diff --git a/Makefile b/Makefile index 70aed6f495..6b7ea3326f 100644 --- a/Makefile +++ b/Makefile @@ -372,7 +372,7 @@ makeopts.embed_rules: menuselect.makeopts @$(MAKE) $(PRINT_DIR) $(MOD_SUBDIRS_EMBED_LDFLAGS) @$(MAKE) $(PRINT_DIR) $(MOD_SUBDIRS_EMBED_LIBS) -$(SUBDIRS): include/asterisk/version.h include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules +$(SUBDIRS): main/version.c include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules ifeq ($(findstring $(OSARCH), mingw32 cygwin ),) # Non-windows: @@ -403,8 +403,8 @@ defaults.h: makeopts @cmp -s $@.tmp $@ || mv $@.tmp $@ @rm -f $@.tmp -include/asterisk/version.h: - @build_tools/make_version_h > $@.tmp +main/version.c: + @build_tools/make_version_c > $@.tmp @cmp -s $@.tmp $@ || mv $@.tmp $@ @rm -f $@.tmp @@ -427,7 +427,7 @@ $(SUBDIRS_DIST_CLEAN): clean: $(SUBDIRS_CLEAN) rm -f defaults.h rm -f include/asterisk/build.h - rm -f include/asterisk/version.h + rm -f main/version.c @$(MAKE) -C menuselect clean cp -f .cleancount .lastclean @@ -695,7 +695,7 @@ spec: rpm: __rpm -__rpm: include/asterisk/version.h include/asterisk/buildopts.h spec +__rpm: main/version.c include/asterisk/buildopts.h spec rm -rf /tmp/asterisk ; \ mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \ $(MAKE) DESTDIR=/tmp/asterisk install ; \ @@ -820,4 +820,4 @@ pdf: asterisk.pdf asterisk.pdf: $(MAKE) -C doc/tex asterisk.pdf -.PHONY: menuselect main sounds clean dist-clean distclean all prereqs cleantest uninstall _uninstall uninstall-all pdf dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_DIST_CLEAN) $(SUBDIRS_CLEAN) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS) include/asterisk/version.h +.PHONY: menuselect main sounds clean dist-clean distclean all prereqs cleantest uninstall _uninstall uninstall-all pdf dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_DIST_CLEAN) $(SUBDIRS_CLEAN) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS) main/version.c diff --git a/build_tools/make_version_c b/build_tools/make_version_c new file mode 100755 index 0000000000..291290ddd8 --- /dev/null +++ b/build_tools/make_version_c @@ -0,0 +1,33 @@ +#!/bin/sh +if [ ! -f ../.flavor ]; then + EXTRA="" +else + aadkver=`cat ../.version` + aadkflavor=`cat ../.flavor` + EXTRA=" (${aadkflavor} ${aadkver})" +fi +cat << END +/* + * version.c + * Automatically generated + */ + +#include "asterisk.h" + +#include "asterisk/version.h" + +static const char asterisk_version[] = "${ASTERISKVERSION}${EXTRA}"; + +static const char asterisk_version_num[] = "${ASTERISKVERSIONNUM}"; + +const char *ast_get_version(void) +{ + return asterisk_version; +} + +const char *ast_get_version_num(void) +{ + return asterisk_version_num; +} + +END diff --git a/build_tools/make_version_h b/build_tools/make_version_h deleted file mode 100755 index 6d901c2fa8..0000000000 --- a/build_tools/make_version_h +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -if [ ! -f ../.flavor ]; then - EXTRA="" -else - aadkver=`cat ../.version` - aadkflavor=`cat ../.flavor` - EXTRA=" (${aadkflavor} ${aadkver})" -fi -cat << END -/* - * version.h - * Automatically generated - */ -#define ASTERISK_VERSION "${ASTERISKVERSION}${EXTRA}" -#define ASTERISK_VERSION_NUM ${ASTERISKVERSIONNUM} - -END diff --git a/channels/chan_sip.c b/channels/chan_sip.c index f5532ca2b2..b0daf5c532 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -18371,8 +18371,8 @@ static int reload_config(enum channelreloadreason reason) global_directrtpsetup = FALSE; /* Experimental feature, disabled by default */ global_alwaysauthreject = 0; global_allowsubscribe = FALSE; - snprintf(global_useragent, sizeof(global_useragent), "%s %s", DEFAULT_USERAGENT, ASTERISK_VERSION); - snprintf(global_sdpsession, sizeof(global_sdpsession), "%s %s", DEFAULT_SDPSESSION, ASTERISK_VERSION); + snprintf(global_useragent, sizeof(global_useragent), "%s %s", DEFAULT_USERAGENT, ast_get_version()); + snprintf(global_sdpsession, sizeof(global_sdpsession), "%s %s", DEFAULT_SDPSESSION, ast_get_version()); snprintf(global_sdpowner, sizeof(global_sdpowner), "%s", DEFAULT_SDPOWNER); ast_copy_string(default_notifymime, DEFAULT_NOTIFYMIME, sizeof(default_notifymime)); ast_copy_string(global_realm, S_OR(ast_config_AST_SYSTEM_NAME, DEFAULT_REALM), sizeof(global_realm)); diff --git a/funcs/func_version.c b/funcs/func_version.c index 6fed3bfa30..8d12503751 100644 --- a/funcs/func_version.c +++ b/funcs/func_version.c @@ -34,39 +34,35 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/version.h" #include "asterisk/build.h" -#define STRING_IT(vernum) STRING_IT2(vernum) -#define STRING_IT2(vernum) #vernum - static int acf_version_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen) { - char *response_char = ASTERISK_VERSION; + const char *response_char = ast_get_version(); AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(info); + AST_APP_ARG(info); ); AST_STANDARD_APP_ARGS(args, parse); if (!ast_strlen_zero(args.info) ) { - if (strcasecmp(args.info,"ASTERISK_VERSION_NUM") == 0) - response_char = STRING_IT(ASTERISK_VERSION_NUM); - else if (strcasecmp(args.info,"BUILD_USER") == 0) + if (!strcasecmp(args.info,"ASTERISK_VERSION_NUM")) + response_char = ast_get_version_num(); + else if (!strcasecmp(args.info,"BUILD_USER")) response_char = BUILD_USER; - else if (strcasecmp(args.info,"BUILD_HOSTNAME") == 0) + else if (!strcasecmp(args.info,"BUILD_HOSTNAME")) response_char = BUILD_HOSTNAME; - else if (strcasecmp(args.info,"BUILD_MACHINE") == 0) + else if (!strcasecmp(args.info,"BUILD_MACHINE")) response_char = BUILD_MACHINE; - else if (strcasecmp(args.info,"BUILD_KERNEL") == 0) + else if (!strcasecmp(args.info,"BUILD_KERNEL")) response_char = BUILD_KERNEL; - else if (strcasecmp(args.info,"BUILD_OS") == 0) + else if (!strcasecmp(args.info,"BUILD_OS")) response_char = BUILD_OS; - else if (strcasecmp(args.info,"BUILD_DATE") == 0) + else if (!strcasecmp(args.info,"BUILD_DATE")) response_char = BUILD_DATE; - } - ast_debug(1, "VERSION returns %s result, given %s argument\n", response_char, args.info); + snprintf(buffer, buflen, "%s", response_char); return 0; diff --git a/include/asterisk/version.h b/include/asterisk/version.h new file mode 100644 index 0000000000..51ff481022 --- /dev/null +++ b/include/asterisk/version.h @@ -0,0 +1,44 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2008, Digium, Inc. + * + * Russell Bryant + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! + * \file + * \brief Asterisk version information + * \author Russell Bryant + */ + +#ifndef __AST_VERSION_H +#define __AST_VERSION_H + +/*! + * \brief Retrieve the Asterisk version string. + */ +const char *ast_get_version(void); + +/*! + * \brief Retrieve the numeric Asterisk version + * + * Format ABBCC + * AABB - Major version (1.4 would be 104) + * CC - Minor version + * + * 1.4.17 would be 10417. + */ +const char *ast_get_version_num(void); + +#endif /* __AST_VERSION_H */ diff --git a/main/Makefile b/main/Makefile index 364cf3169b..93a306e8ed 100644 --- a/main/Makefile +++ b/main/Makefile @@ -29,7 +29,7 @@ OBJS= io.o sched.o logger.o frame.o loader.o config.o channel.o \ netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \ cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \ strcompat.o threadstorage.o dial.o event.o adsistub.o audiohook.o \ - astobj2.o hashtab.o global_datastores.o $(RESAMPLE_OBJS) + astobj2.o hashtab.o global_datastores.o $(RESAMPLE_OBJS) version.o # we need to link in the objects statically, not as a library, because # otherwise modules will not have them available if none of the static diff --git a/main/asterisk.c b/main/asterisk.c index 5d995c9a7e..e1b2f6acfd 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -135,7 +135,7 @@ int daemon(int, int); /* defined in libresolv of all places */ /*! \brief Welcome message when starting a CLI interface */ #define WELCOME_MESSAGE \ - ast_verbose("Asterisk " ASTERISK_VERSION ", Copyright (C) 1999 - 2007 Digium, Inc. and others.\n" \ + ast_verbose("Asterisk %s, Copyright (C) 1999 - 2007 Digium, Inc. and others.\n" \ "Created by Mark Spencer \n" \ "Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.\n" \ "This is free software, with components licensed under the GNU General Public\n" \ @@ -143,7 +143,7 @@ int daemon(int, int); /* defined in libresolv of all places */ "certain conditions. Type 'core show license' for details.\n" \ "=========================================================================\n" \ "NOTE: This is a development version of Asterisk, and should not be used in\n" \ - "production installations.\n"); + "production installations.\n", ast_get_version()); /*! \defgroup main_options Main Configuration Options * \brief Main configuration options from asterisk.conf or OS command line on starting Asterisk. @@ -394,7 +394,7 @@ static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_c ast_cli(a->fd, "\nPBX Core settings\n"); ast_cli(a->fd, "-----------------\n"); - ast_cli(a->fd, " Version: %s\n", "" ASTERISK_VERSION "" ); + ast_cli(a->fd, " Version: %s\n", ast_get_version()); if (option_maxcalls) ast_cli(a->fd, " Max. calls: %d (Current %d)\n", option_maxcalls, ast_active_channels()); else @@ -980,7 +980,7 @@ static void *netconsole(void *vconsole) if (gethostname(hostname, sizeof(hostname)-1)) ast_copy_string(hostname, "", sizeof(hostname)); - snprintf(tmp, sizeof(tmp), "%s/%ld/%s\n", hostname, (long)ast_mainpid, ASTERISK_VERSION); + snprintf(tmp, sizeof(tmp), "%s/%ld/%s\n", hostname, (long)ast_mainpid, ast_get_version()); fdprint(con->fd, tmp); for (;;) { fds[0].fd = con->fd; @@ -1515,7 +1515,7 @@ static char *handle_version(struct ast_cli_entry *e, int cmd, struct ast_cli_arg if (a->argc != 3) return CLI_SHOWUSAGE; ast_cli(a->fd, "Asterisk %s built by %s @ %s on a %s running %s on %s\n", - ASTERISK_VERSION, ast_build_user, ast_build_hostname, + ast_get_version(), ast_build_user, ast_build_hostname, ast_build_machine, ast_build_os, ast_build_date); return CLI_SUCCESS; } @@ -2387,12 +2387,12 @@ static void ast_remotecontrol(char * data) static int show_version(void) { - printf("Asterisk " ASTERISK_VERSION "\n"); + printf("Asterisk %s\n", ast_get_version()); return 0; } static int show_cli_help(void) { - printf("Asterisk " ASTERISK_VERSION ", Copyright (C) 1999 - 2007, Digium, Inc. and others.\n"); + printf("Asterisk %s, Copyright (C) 1999 - 2007, Digium, Inc. and others.\n", ast_get_version()); printf("Usage: asterisk [OPTIONS]\n"); printf("Valid Options:\n"); printf(" -V Display version number and exit\n"); diff --git a/main/http.c b/main/http.c index 485211192c..c7ea804fc5 100644 --- a/main/http.c +++ b/main/http.c @@ -186,7 +186,7 @@ static struct ast_str *static_callback(struct server_instance *ser, const char * "Cache-Control: no-cache, no-store\r\n" "Content-Length: %d\r\n" "Content-type: %s\r\n\r\n", - ASTERISK_VERSION, buf, (int) st.st_size, mtype); + ast_get_version(), buf, (int) st.st_size, mtype); while ((len = read(fd, buf, sizeof(buf))) > 0) fwrite(buf, 1, len, ser->f); @@ -847,7 +847,7 @@ static void *httpd_helper_thread(void *data) "Date: %s\r\n" "Connection: close\r\n" "%s", - status, title ? title : "OK", ASTERISK_VERSION, timebuf, + status, title ? title : "OK", ast_get_version(), timebuf, static_content ? "" : "Cache-Control: no-cache, no-store\r\n"); if (!contentlength) { /* opaque body ? just dump it hoping it is properly formatted */ fprintf(ser->f, "%s", out->str); diff --git a/main/manager.c b/main/manager.c index 30e5247d08..f57d35b680 100644 --- a/main/manager.c +++ b/main/manager.c @@ -2222,7 +2222,7 @@ static int action_coresettings(struct mansession *s, const struct message *m) , idText, AMI_VERSION, - ASTERISK_VERSION, + ast_get_version(), ast_config_AST_SYSTEM_NAME, option_maxcalls, option_maxload, diff --git a/res/res_agi.c b/res/res_agi.c index 9a637c46a2..0c352c8430 100644 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -744,7 +744,7 @@ static void setup_env(struct ast_channel *chan, char *request, int fd, int enhan ast_agi_fdprintf(chan, fd, "agi_language: %s\n", chan->language); ast_agi_fdprintf(chan, fd, "agi_type: %s\n", chan->tech->type); ast_agi_fdprintf(chan, fd, "agi_uniqueid: %s\n", chan->uniqueid); - ast_agi_fdprintf(chan, fd, "agi_version: %s\n", ASTERISK_VERSION); + ast_agi_fdprintf(chan, fd, "agi_version: %s\n", ast_get_version()); /* ANI/DNIS */ ast_agi_fdprintf(chan, fd, "agi_callerid: %s\n", S_OR(chan->cid.cid_num, "unknown"));