Browse code

msvc: always call git-version.py

There is no way to detect whether this information
is outdated in nmake itself. So leave it up to the
Python script to decide.

While here, change some leading whitespace to tabs as
expected in Makefile.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20221111121212.25167-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25508.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Frank Lichtenheld authored on 2022/11/11 21:12:12
Showing 2 changed files
... ...
@@ -51,10 +51,13 @@ $(OUTPUT_PLUGIN): $(INPUT_PLUGIN) $(OUTPUT_PLUGIN_CONFIG)
51 51
 	cscript //nologo msvc-generate.js --config="$(OUTPUT_PLUGIN_CONFIG)" --input="$(INPUT_PLUGIN)" --output="$(OUTPUT_PLUGIN)"
52 52
 
53 53
 $(OUTPUT_MAN): $(INPUT_MAN)
54
-    -FOR /F %i IN ('where rst2html.py') DO python %i "$(INPUT_MAN)" "$(OUTPUT_MAN)"
54
+	-FOR /F %i IN ('where rst2html.py') DO python %i "$(INPUT_MAN)" "$(OUTPUT_MAN)"
55 55
 
56
-$(OUTPUT_MSVC_GIT_CONFIG):
57
-    python git-version.py $(SOLUTIONDIR)
56
+# Force regeneration because we can't detect whether it is outdated
57
+$(OUTPUT_MSVC_GIT_CONFIG): FORCE
58
+	python git-version.py $(SOLUTIONDIR)
59
+
60
+FORCE:
58 61
 
59 62
 clean:
60 63
 	-del "$(OUTPUT_MSVC_VER)"
... ...
@@ -41,10 +41,25 @@ def main():
41 41
     except:
42 42
         branch, commit_id = "unknown", "unknown"
43 43
 
44
+    prev_content = ""
45
+
44 46
     name = os.path.join("%s" %  (sys.argv[1] if len(sys.argv) > 1 else "."), "config-version.h")
45
-    with open(name, "w") as f:
46
-        f.write("#define CONFIGURE_GIT_REVISION \"%s/%s\"\n" % (branch, commit_id))
47
-        f.write("#define CONFIGURE_GIT_FLAGS \"\"\n")
47
+    try:
48
+        with open(name, "r") as f:
49
+            prev_content = f.read()
50
+    except:
51
+        # file doesn't exist
52
+        pass
53
+
54
+    content = "#define CONFIGURE_GIT_REVISION \"%s/%s\"\n" % (branch, commit_id)
55
+    content += "#define CONFIGURE_GIT_FLAGS \"\"\n"
56
+
57
+    if prev_content != content:
58
+        print("Writing %s" % name)
59
+        with open(name, "w") as f:
60
+            f.write(content)
61
+    else:
62
+        print("Content of %s hasn't changed" % name)
48 63
 
49 64
 if __name__ == "__main__":
50 65
     main()