Browse code

core: move version strings to a separate file

- moved version strings to variables (instead of macros) and in a
separate file (ver.c). This will require re-compiling only one
small file and re-linking on version or repository changes (e.g.
new commit or local uncommitted changes), instead of recompiling
main.c and core_cmd.c.
- more detailed info about the repository state is now available via
repo_hash (hash of the top commit) and repo_state (dirty or "").
- the core.version rpc reports now directly the version number
(complete with repository hash and state), without prefixing it
with "Server:", e.g.:
ser 3.0.99-dev1 (i386/linux) dd9681-dirty
instead of
Server: ser (3.0.99-dev1 (i386/freebsd)) d89437-dirty

Andrei Pelinescu-Onciul authored on 13/07/2010 17:59:26
Showing 8 changed files
... ...
@@ -491,12 +491,11 @@ modules_search_path=$(subst $(space),:,$(strip\
491 491
 		#				$(addprefix $(modules_target),$(modules_dirs))))
492 492
 
493 493
 # special depends for main.o
494
-main.d main.o: autover.h
495 494
 main.o: DEFS+=-DMODS_DIR='"$(modules_search_path)"'
496 495
 
497 496
 
498
-#special depends for core_cmd.o
499
-core_cmd.d core_cmd.o: autover.h
497
+#special depends for ver.c
498
+ver.d ver.o: autover.h
500 499
 
501 500
 include Makefile.shared
502 501
 
... ...
@@ -564,10 +563,14 @@ repo_ver=$(shell  RV=`git rev-parse --verify --short=6 HEAD 2>/dev/null`;\
564 564
 							; git diff-index --name-only HEAD 2>/dev/null | \
565 565
 								grep -v Makefile`" &&\
566 566
 						RV="$$RV"-dirty; echo "$$RV")
567
+repo_hash=$(subst -dirty,,$(repo_ver))
568
+repo_state=$(patsubst %-dirty,dirty,$(repo_ver))
567 569
 autover_h_dep=.git $(filter-out $(auto_gen), $(sources)) cfg.y cfg.lex
568 570
 else
569 571
 # else if .git/ does not exist
570 572
 repo_ver=
573
+repo_hash="unknown"
574
+repo_state=
571 575
 autover_h_dep=
572 576
 endif
573 577
 
... ...
@@ -579,6 +582,8 @@ autover.h: $(autover_h_dep)
579 579
 	@echo " */" >>$@
580 580
 	@echo "" >>$@
581 581
 	@echo "#define REPO_VER \"$(repo_ver)\"" >>$@
582
+	@echo "#define REPO_HASH \"$(repo_hash)\"" >>$@
583
+	@echo "#define REPO_STATE \"$(repo_state)\"" >>$@
582 584
 
583 585
 .PHONY: all
584 586
 all: $(NAME) every-module
... ...
@@ -20,18 +20,16 @@
20 20
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 21
  */
22 22
 
23
-/*!
24
- * \file
25
- * \brief SIP-router core :: 
26
- * \ingroup core
27
- * Module: \ref core
23
+/** core rpcs.
24
+ * @file core_cmd.c
25
+ * @ingroup core
28 26
  */
29 27
 
30 28
 
31 29
 #include <time.h>
32 30
 #include <sys/types.h>
33 31
 #include <signal.h>
34
-#include "autover.h"
32
+#include "ver.h"
35 33
 #include "mem/mem.h"
36 34
 #include "mem/shm_mem.h"
37 35
 #include "sr_module.h"
... ...
@@ -336,7 +334,7 @@ static const char* core_version_doc[] = {
336 336
 
337 337
 static void core_version(rpc_t* rpc, void* c)
338 338
 {
339
-	rpc->add(c, "s", SERVER_HDR " " REPO_VER );
339
+	rpc->add(c, "s", full_version);
340 340
 }
341 341
 
342 342
 
... ...
@@ -73,23 +73,20 @@
73 73
  * 2008-08-08  sctp support (andrei)
74 74
  * 2008-08-19  -l support for mmultihomed addresses/addresses lists
75 75
  *                (e.g. -l (eth0, 1.2.3.4, foo.bar) ) (andrei)
76
- *  2010-04-19 added daemon_status_fd pipe to communicate the parent process with
77
-               the main process in daemonize mode, so the parent process can return
78
-               the proper exit status code (ibc)
76
+ *  2010-04-19 added daemon_status_fd pipe to communicate the parent process
77
+ *             with the main process in daemonize mode, so the parent process
78
+ *             can return the proper exit status code (ibc)
79 79
  */
80 80
 
81
-/*!
82
- * \file
83
- * \brief SIP-router core :: 
84
- * \ingroup core
85
- * Module: \ref core
81
+/** main file (init, daemonize, startup) 
82
+ * @file main.c
83
+ * @ingroup core
84
+ * Module: core
86 85
  */
87 86
 
88
-/*! \defgroup core SIP-router core
89
- *
90
- * This modules implements a SIP server with a module interface
91
- * for extendability.
87
+/*! @defgroup core SIP-router core
92 88
  *
89
+ * sip router core part.
93 90
  */
94 91
 
95 92
 #include <stdio.h>
... ...
@@ -190,8 +187,7 @@
190 190
 #ifdef DEBUG_DMALLOC
191 191
 #include <dmalloc.h>
192 192
 #endif
193
-#include "autover.h"
194
-#include "version.h"
193
+#include "ver.h"
195 194
 
196 195
 /* define SIG_DEBUG by default */
197 196
 #ifdef NO_SIG_DEBUG
... ...
@@ -200,10 +196,6 @@
200 200
 #define SIG_DEBUG
201 201
 #endif
202 202
 
203
-static char id[]="@(#) $Id$";
204
-static char* version=SER_FULL_VERSION " " REPO_VER;
205
-static char* flags=SER_COMPILE_FLAGS;
206
-char compiled[]= __TIME__ " " __DATE__ ;
207 203
 
208 204
 
209 205
 static char help_msg[]= "\
... ...
@@ -1688,7 +1680,7 @@ int main(int argc, char** argv)
1688 1688
 	opterr = 0;
1689 1689
 	while((c=getopt(argc,argv,options))!=-1) {
1690 1690
 		if (c == 'h' || (optarg && strcmp(optarg, "-h") == 0)) {
1691
-			printf("version: %s\n", version);
1691
+			printf("version: %s\n", full_version);
1692 1692
 			printf("%s",help_msg);
1693 1693
 			exit(0);
1694 1694
 			break;
... ...
@@ -1724,8 +1716,8 @@ int main(int argc, char** argv)
1724 1724
 					default_core_cfg.debug++;
1725 1725
 					break;
1726 1726
 			case 'V':
1727
-					printf("version: %s\n", version);
1728
-					printf("flags: %s\n", flags );
1727
+					printf("version: %s\n", full_version);
1728
+					printf("flags: %s\n", ver_flags );
1729 1729
 					print_ct_constants();
1730 1730
 #ifdef USE_SCTP
1731 1731
 					tmp=malloc(256);
... ...
@@ -1733,9 +1725,9 @@ int main(int argc, char** argv)
1733 1733
 						printf("sctp unsupported socket options: %s\n", tmp);
1734 1734
 					if (tmp) free(tmp);
1735 1735
 #endif
1736
-					printf("%s\n",id);
1737
-					printf("%s compiled on %s with %s\n", __FILE__,
1738
-							compiled, COMPILER );
1736
+					printf("id: %s\n", ver_id);
1737
+					printf("compiled on %s with %s\n",
1738
+							ver_compiled_time, ver_compiler );
1739 1739
 
1740 1740
 					exit(0);
1741 1741
 					break;
... ...
@@ -47,7 +47,7 @@
47 47
 #include "../../pt.h"
48 48
 #include "../../mem/mem.h"
49 49
 #include "../../lib/kmi/mi.h"
50
-#include "../../version.h"
50
+#include "../../ver.h"
51 51
 #include "../../cfg/cfg.h"
52 52
 #include "../../cfg/cfg_ctx.h"
53 53
 
... ...
@@ -139,12 +139,8 @@ static struct mi_root *mi_version(struct mi_root *cmd, void *param)
139 139
 	if (node==0) 
140 140
 		goto error;
141 141
 
142
-#ifndef KAMAILIO_COMPILE_FLAGS
143
-#define KAMAILIO_COMPILE_FLAGS SER_COMPILE_FLAGS
144
-#endif
145
-
146
-	node = add_mi_node_child( rpl, 0, MI_SSTR("Flags"), KAMAILIO_COMPILE_FLAGS,
147
-			sizeof(KAMAILIO_COMPILE_FLAGS)-1);
142
+	node = add_mi_node_child( rpl, 0, MI_SSTR("Flags"), (char*)ver_flags,
143
+				strlen(ver_flags));
148 144
 	if (node==0) 
149 145
 		goto error;	
150 146
 	
... ...
@@ -61,7 +61,7 @@
61 61
 #include <dlfcn.h>
62 62
 
63 63
 #include "parser/msg_parser.h" /* for sip_msg */
64
-#include "version.h"
64
+#include "ver_defs.h"
65 65
 #include "rpc.h"
66 66
 #include "route_struct.h"
67 67
 #include "route.h"
68 68
new file mode 100644
... ...
@@ -0,0 +1,46 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2010 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/** version strings.
18
+ * @file ver.c
19
+ * @ingroup: core
20
+ */
21
+/*
22
+ * History:
23
+ * --------
24
+ *  2010-07-13  initial version (andrei)
25
+*/
26
+
27
+#include "ver_defs.h"
28
+#include "autover.h" /* REPO_VER, REPO_STATE */
29
+
30
+
31
+const char full_version[] = SER_FULL_VERSION " " REPO_VER;
32
+const char ver_id[] = REPO_HASH " " REPO_STATE;
33
+const char ver_compiled_time[] =  __TIME__ " " __DATE__ ;
34
+const char ver_compiler[] = COMPILER;
35
+
36
+const char ver_flags[] = SER_COMPILE_FLAGS;
37
+
38
+/** hash-state. */
39
+const char repo_ver[] = REPO_VER;
40
+/** git hash. */
41
+const char repo_hash[] = REPO_HASH;
42
+/** state of the repository: dirty (uncommited changes) or "" */
43
+const char repo_state[] = REPO_STATE;
44
+
45
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
0 46
new file mode 100644
... ...
@@ -0,0 +1,43 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2010 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/** version strings.
18
+ * @file ver.h
19
+ * @ingroup: core
20
+ */
21
+/*
22
+ * History:
23
+ * --------
24
+ *  2010-07-13  initial version (andrei)
25
+*/
26
+
27
+#ifndef __ver_h
28
+#define __ver_h
29
+
30
+extern const char full_version[];
31
+extern const char ver_id[];
32
+extern const char ver_compiled_time[];
33
+extern const char ver_compiler[];
34
+extern const char ver_flags[];
35
+extern const char repo_ver[];
36
+extern const char repo_hash[];
37
+extern const char repo_state[];
38
+
39
+
40
+#endif /*__ver_h*/
41
+
42
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
0 43
similarity index 98%
1 44
rename from version.h
2 45
rename to ver_defs.h
... ...
@@ -23,12 +23,9 @@
23 23
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24 24
  */
25 25
 
26
-/*!
27
- * \file
28
- * \brief SIP-router core :: version and compile flag macros
29
- * \ingroup core
30
- *
31
- * Module: \ref core
26
+/** compile flags and other version related defines.
27
+ * @file ver_defs.h
28
+ * @ingroup core
32 29
  */
33 30
 
34 31
 #ifndef version_h