Module: sip-router
Branch: master
Commit: 51690b9e45be569ca87e6d0af9e288a3656249f3
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=51690b9…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Wed Jun 24 21:11:24 2009 +0200
makefile: auto-generate autover.h based on the git sha
Automatically re-generate autover.h each time some change in the
repository happens. The file will contain a macro (REPO_VER) set
to the first 6 letters of the git sha. This allows unique
identification for the git branch and commits from which the code
was generated.
If the code is not compiled from a git repository, use "unknown"
for the REPO_VER.
---
Makefile | 25 ++++++++++++++++++++++++-
Makefile.targets | 2 +-
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 2dc955b..68eff8c 100644
--- a/Makefile
+++ b/Makefile
@@ -77,7 +77,7 @@ endif
auto_gen=lex.yy.c cfg.tab.c #lexx, yacc etc
-auto_gen_others=cfg.tab.h # auto generated, non-c
+auto_gen_others=cfg.tab.h autover.h # auto generated, non-c
COREPATH=.
#include source related defs
@@ -394,8 +394,13 @@ modules_search_path=$(subst $(space),:,$(strip\
$(foreach m,$(modules_dirs),$($(m)_target))))
# $(addprefix $(modules_target),$(modules_dirs))))
+# special depends for main.o
+main.o: autover.h
main.o: DEFS+=-DMODS_DIR='"$(modules_search_path)"'
+#special depends for core_cmd.o
+core_cmd.o: autover.h
+
include Makefile.shared
ifeq ($(config_mak),1)
@@ -445,6 +450,24 @@ modules-cfg modules-list modules-lst:
rm -f modules.lst
$(MAKE) modules.lst
+ifneq ($(wildcard .git),)
+# if .git/ exists
+repo_ver=$(shell git rev-parse --short=6 HEAD 2>/dev/null || echo "unknown"
)
+autover_h_dep=.git
+else
+# else if .git/ does not exist
+repo_ver="unknown"
+autover_h_dep=
+endif
+
+autover.h: $(autover_h_dep)
+ @echo "generating autover.h ($(autover_h_dep)) ..."
+ @echo "/* this file is autogenerated by make autover.h" >$@
+ @echo " * DO NOT EDIT IT" >>$@
+ @echo " */" >>$@
+ @echo "" >>$@
+ @echo "#define REPO_VER \"$(repo_ver)\"" >>$@
+
.PHONY: all
all: $(NAME) every-module
diff --git a/Makefile.targets b/Makefile.targets
index 0416b80..9ba0ef8 100644
--- a/Makefile.targets
+++ b/Makefile.targets
@@ -35,7 +35,7 @@ doc_targets:= README man install-doc install-man install-ser-man \
# auxiliary: maintance, debugging, etc. (don't affect code/objects)
aux_targets:= TAGS tar dist cfg-defs cfg config config.mak print-modules \
dbg dbinstall librpath.lst makecfg.lst modules.lst modules-cfg \
- modules-list modules-lst mk-install_dirs
+ modules-list modules-lst mk-install_dirs autover.h
# other targets that don't produce code in the current directory
("external")
ext_targets:= every-module $(modules_dirs) libs utils \
install-cfg install-utils install-modules-all install-every-module\