summaryrefslogtreecommitdiff
path: root/Mk
diff options
context:
space:
mode:
authorDaniel Roethlisberger <[email protected]>2018-03-10 19:52:21 +0100
committerDaniel Roethlisberger <[email protected]>2018-03-10 19:52:21 +0100
commitfa9c2a1dfca5b54f8705ae01ee2aa174ea0f4d93 (patch)
tree5e38853a5bd6f46b3f9a0c6b89fe9da64a931196 /Mk
parentba7a3200445fdfd026d300752747ffd95a4b7e78 (diff)
Refactor version handling into Mk/buildinfo.mk
Diffstat (limited to 'Mk')
-rwxr-xr-xMk/bin/copyright.py67
-rw-r--r--Mk/buildinfo.mk47
2 files changed, 114 insertions, 0 deletions
diff --git a/Mk/bin/copyright.py b/Mk/bin/copyright.py
new file mode 100755
index 0000000..ab51290
--- /dev/null
+++ b/Mk/bin/copyright.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+# vim: set ft=python list et ts=8 sts=4 sw=4:
+
+import sys
+import os
+
+def commentline(prefix, line):
+ if len(line) > 0:
+ return prefix + ' ' + line + '\n'
+ return prefix + '\n'
+
+def license(outfile, filetype):
+ with open('LICENSE', 'r') as f:
+ # skip title
+ f.readline()
+ f.readline()
+ text = f.read()
+ text = ('SSLsplit - transparent SSL/TLS interception\n'
+ 'https://www.roe.ch/SSLsplit\n\n') + text.replace(
+ 'and contributors', '<[email protected]>')
+ lines = text.splitlines()
+ if filetype == 'c':
+ outfile.write('/*-\n')
+ for line in lines:
+ outfile.write(commentline(' *', line))
+ elif filetype == 'script':
+ outfile.write('#-\n')
+ for line in lines:
+ outfile.write(commentline('#', line))
+ elif filetype == 'man':
+ outfile.write('.\\"-\n')
+ for line in lines:
+ outfile.write(commentline('.\\"', line))
+ else:
+ raise RuntimeError()
+
+def mangle(outfile, infile):
+ have_first = False
+ have_header = False
+ for line in infile:
+ if have_header:
+ outfile.write(line)
+ elif have_first:
+ if (filetype == 'c' and line.startswith(' */')) or \
+ (filetype == 'script' and not line.startswith('#')) or \
+ (filetype == 'man' and not line.startswith('.\\"')):
+ outfile.write(line)
+ have_header = True
+ else:
+ if line.startswith('/*-'):
+ filetype = 'c'
+ elif line.startswith('#-'):
+ filetype = 'script'
+ elif line.startswith('.\\"-'):
+ filetype = 'man'
+ else:
+ outfile.write(line)
+ continue
+ license(outfile, filetype)
+ have_first = True
+
+for fn in sys.argv[1:]:
+ with open(fn, 'r') as infile:
+ with open(fn + '~', 'w') as outfile:
+ mangle(outfile, infile)
+ os.rename(fn + '~', fn)
+
diff --git a/Mk/buildinfo.mk b/Mk/buildinfo.mk
new file mode 100644
index 0000000..962baef
--- /dev/null
+++ b/Mk/buildinfo.mk
@@ -0,0 +1,47 @@
+# in: PKGNAME
+# in: BUILD_INFO (optional)
+
+ifndef PKGNAME
+$(error PKGNAME not defined)
+endif
+
+BASENAME?= basename
+CUT?= cut
+GIT?= git
+GREP?= grep
+OPENSSL?= openssl
+SED?= sed
+
+GITDIR:= $(wildcard .git)
+VERSION_FILE:= $(wildcard VERSION)
+NEWS_FILE:= $(firstword $(wildcard NEWS*))
+
+ifdef GITDIR
+BUILD_VERSION:= $(shell $(GIT) describe --tags --dirty --always)
+BUILD_INFO+= V:GIT
+GITDIR:=
+else
+ifdef VERSION_FILE
+BUILD_VERSION:= $(shell $(CAT) VERSION)
+BUILD_INFO+= V:FILE
+else
+BUILD_VERSION:= $(shell $(BASENAME) $(PWD)|\
+ $(GREP) $(PKGNAME)-|\
+ $(SED) 's/.*$(PKGNAME)-\(.*\)/\1/g')
+BUILD_INFO+= V:DIR
+endif
+ifdef NEWS_FILE
+NEWSSHA:= $(shell $(OPENSSL) dgst -sha1 -r $(NEWS_FILE) |\
+ $(CUT) -c -7)
+BUILD_INFO+= N:$(NEWSSHA)
+NEWSSHA:=
+endif
+endif # GITDIR
+
+BUILD_DATE:= $(shell date +%Y-%m-%d)
+
+# out: NEWS_FILE
+# out: VERSION_FILE
+# out: BUILD_DATE
+# out: BUILD_VERSION
+# out: BUILD_INFO