Browse code

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.

Andrei Pelinescu-Onciul authored on 24/06/2009 19:11:24
Showing 2 changed files
... ...
@@ -77,7 +77,7 @@ endif
77 77
 
78 78
 
79 79
 auto_gen=lex.yy.c cfg.tab.c #lexx, yacc etc
80
-auto_gen_others=cfg.tab.h  # auto generated, non-c
80
+auto_gen_others=cfg.tab.h autover.h  # auto generated, non-c
81 81
 
82 82
 COREPATH=.
83 83
 #include  source related defs
... ...
@@ -394,8 +394,13 @@ modules_search_path=$(subst $(space),:,$(strip\
394 394
 						$(foreach m,$(modules_dirs),$($(m)_target))))
395 395
 		#				$(addprefix $(modules_target),$(modules_dirs))))
396 396
 
397
+# special depends for main.o
398
+main.o: autover.h
397 399
 main.o: DEFS+=-DMODS_DIR='"$(modules_search_path)"'
398 400
 
401
+#special depends for core_cmd.o
402
+core_cmd.o: autover.h
403
+
399 404
 include Makefile.shared
400 405
 
401 406
 ifeq ($(config_mak),1)
... ...
@@ -445,6 +450,24 @@ modules-cfg modules-list modules-lst:
445 445
 	rm -f modules.lst
446 446
 	$(MAKE) modules.lst
447 447
 
448
+ifneq ($(wildcard .git),)
449
+# if .git/ exists
450
+repo_ver=$(shell git rev-parse --short=6 HEAD 2>/dev/null || echo "unknown" )
451
+autover_h_dep=.git
452
+else
453
+# else if .git/ does not exist
454
+repo_ver="unknown"
455
+autover_h_dep=
456
+endif
457
+
458
+autover.h: $(autover_h_dep)
459
+	@echo  "generating autover.h ($(autover_h_dep)) ..."
460
+	@echo "/* this file is autogenerated by make autover.h" >$@
461
+	@echo " * DO NOT EDIT IT" >>$@
462
+	@echo " */" >>$@
463
+	@echo "" >>$@
464
+	@echo "#define REPO_VER \"$(repo_ver)\"" >>$@
465
+
448 466
 .PHONY: all
449 467
 all: $(NAME) every-module
450 468
 
... ...
@@ -35,7 +35,7 @@ doc_targets:=	README man install-doc install-man install-ser-man \
35 35
 # auxiliary: maintance, debugging, etc. (don't affect code/objects)
36 36
 aux_targets:=	TAGS tar dist cfg-defs cfg config config.mak print-modules \
37 37
 		dbg dbinstall librpath.lst makecfg.lst modules.lst modules-cfg \
38
-		modules-list modules-lst mk-install_dirs
38
+		modules-list modules-lst mk-install_dirs autover.h
39 39
 # other targets that don't produce code in the current directory ("external")
40 40
 ext_targets:=	every-module $(modules_dirs) libs utils \
41 41
 		install-cfg install-utils  install-modules-all install-every-module\