Browse Source

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 16 years ago
parent
commit
51690b9e45
2 changed files with 25 additions and 2 deletions
  1. 24 1
      Makefile
  2. 1 1
      Makefile.targets

+ 24 - 1
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
 

+ 1 - 1
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\