]>
git.ipfire.org Git - thirdparty/openvpn.git/blob - contrib/cmake/parse-version.m4.py
3dfb31fbf8c3498f4315cd09331719f8dca74dcb
2 # OpenVPN -- An application to securely tunnel IP networks
3 # over a single UDP port, with support for SSL/TLS-based
4 # session authentication and key exchange,
5 # packet encryption, packet authentication, and
8 # Copyright (C) 2022-2023 OpenVPN Inc <sales@openvpn.net>
9 # Copyright (C) 2022-2022 Lev Stipakov <lev@lestisoftware.fi>
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License version 2
13 # as published by the Free Software Foundation.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 # Usage: ./parse-version.m4.py m4file [directory]
26 # Read <m4file>, extract all lines looking like M4 define(), and translate
27 # them into CMake style set(). Those are then written out to file
28 # <directory>/version.cmake.
29 # Intended to be used on top-level version.m4 file.
36 assert len(sys
.argv
) > 1
37 version_path
= sys
.argv
[1]
39 with
open(version_path
, 'r') as version_file
:
40 for line
in version_file
:
41 match
= re
.match(r
'[ \t]*define\(\[(.*)\],[ \t]*\[(.*)\]\)[ \t]*', line
)
43 output
.append(match
.expand(r
'set(\1 \2)'))
44 out_path
= os
.path
.join("%s" % (sys
.argv
[2] if len(sys
.argv
) > 2 else "."), "version.cmake")
48 with
open(out_path
, "r") as out_file
:
49 prev_content
= out_file
.read()
54 content
= "\n".join(output
) + "\n"
55 if prev_content
!= content
:
56 print("Writing %s" % out_path
)
57 with
open(out_path
, "w") as out_file
:
58 out_file
.write(content
)
60 print("Content of %s hasn't changed" % out_path
)
62 if __name__
== "__main__":