xref: /freebsd/sys/contrib/libsodium/regen-msvc/regen-msvc.py (revision a7623790fb345e6dc986dfd31df0ace115e6f2e4)
1#! /usr/bin/env python3
2
3import fileinput
4import glob
5import os
6import uuid
7
8dirs = set()
9
10tlv1 = ""
11for file in glob.iglob("src/libsodium/**/*.c", recursive=True):
12    file = file.replace("/", "\\")
13    tlv1 = tlv1 + "    <ClCompile Include=\"{}\" />\r\n".format(file)
14
15tlv2 = ""
16for file in glob.iglob("src/libsodium/**/*.h", recursive=True):
17    file = file.replace("/", "\\")
18    tlv2 = tlv2 + "    <ClInclude Include=\"{}\" />\r\n".format(file)
19
20tlf1 = ""
21for file in glob.iglob("src/libsodium/**/*.c", recursive=True):
22    file = file.replace("/", "\\")
23    tlf1 = tlf1 + "    <ClCompile Include=\"{}\">\r\n".format(file)
24    tlf1 = tlf1 + "      <Filter>Source Files</Filter>\r\n"
25    tlf1 = tlf1 + "    </ClCompile>\r\n"
26
27tlf2 = ""
28for file in glob.iglob("src/libsodium/**/*.h", recursive=True):
29    file = file.replace("/", "\\")
30    tlf2 = tlf2 + "    <ClInclude Include=\"{}\">\r\n".format(file)
31    tlf2 = tlf2 + "      <Filter>Header Files</Filter>\r\n"
32    tlf2 = tlf2 + "    </ClInclude>\r\n"
33
34v1 = ""
35for file in glob.iglob("src/libsodium/**/*.c", recursive=True):
36    file = file.replace("/", "\\")
37    v1 = v1 + \
38        "    <ClCompile Include=\"..\\..\\..\\..\\{}\" />\r\n".format(file)
39
40v2 = ""
41for file in glob.iglob("src/libsodium/**/*.h", recursive=True):
42    file = file.replace("/", "\\")
43    v2 = v2 + \
44        "    <ClInclude Include=\"..\\..\\..\\..\\{}\" />\r\n".format(file)
45
46f1 = ""
47for file in glob.iglob("src/libsodium/**/*.c", recursive=True):
48    basedir = os.path.dirname(file).replace("src/libsodium/", "")
49    t = basedir
50    while t != '':
51        dirs.add(t)
52        t = os.path.dirname(t)
53    basedir = basedir.replace("/", "\\")
54    file = file.replace("/", "\\")
55    f1 = f1 + "    <ClCompile Include=\"..\\..\\..\\..\\{}\">\r\n".format(file)
56    f1 = f1 + "      <Filter>{}</Filter>\r\n".format(basedir)
57    f1 = f1 + "    </ClCompile>\r\n"
58
59f2 = ""
60for file in glob.iglob("src/libsodium/**/*.h", recursive=True):
61    basedir = os.path.dirname(file).replace("src/libsodium/", "")
62    t = basedir
63    while t != '':
64        dirs.add(t)
65        t = os.path.dirname(t)
66    basedir = basedir.replace("/", "\\")
67    file = file.replace("/", "\\")
68    f2 = f2 + "    <ClInclude Include=\"..\\..\\..\\..\\{}\">\r\n".format(file)
69    f2 = f2 + "      <Filter>{}</Filter>\r\n".format(basedir)
70    f2 = f2 + "    </ClInclude>\r\n"
71
72fd = ""
73dirs = list(dirs)
74dirs.sort()
75for dir in dirs:
76    dir = dir.replace("/", "\\")
77    uid = uuid.uuid3(uuid.UUID(bytes=b'LibSodiumMSVCUID'), dir)
78    fd = fd + "    <Filter Include=\"{}\">\r\n".format(dir)
79    fd = fd + \
80        "      <UniqueIdentifier>{{{}}}</UniqueIdentifier>\r\n".format(uid)
81    fd = fd + "    </Filter>\r\n"
82
83
84def apply_template(tplfile, outfile, sbox):
85    tpl = ""
86    with open(tplfile, 'rb') as fd:
87        tpl = fd.read()
88    for s in sbox.keys():
89        tpl = tpl.replace(str.encode(
90            "{{" + s + "}}", "utf8"), str.encode(str.strip(sbox[s]), "utf8"))
91
92    with open(outfile, 'wb') as fd:
93        fd.write(tpl)
94
95sbox = {"tlv1": tlv1, "tlv2": tlv2, "tlf1": tlf1, "tlf2": tlf2, "v1": v1,
96        "v2": v2, "f1": f1, "f2": f2, "fd": fd}
97
98sd = os.path.dirname(os.path.realpath(__file__))
99
100apply_template(sd + "/tl_libsodium.vcxproj.filters.tpl",
101               "libsodium.vcxproj.filters", sbox)
102
103sbox.update({"platform": "v140"})
104apply_template(sd + "/tl_libsodium.vcxproj.tpl",
105               "libsodium.vcxproj", sbox)
106
107apply_template(sd + "/libsodium.vcxproj.filters.tpl",
108               "builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters", sbox)
109apply_template(sd + "/libsodium.vcxproj.filters.tpl",
110               "builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters", sbox)
111apply_template(sd + "/libsodium.vcxproj.filters.tpl",
112               "builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters", sbox)
113apply_template(sd + "/libsodium.vcxproj.filters.tpl",
114               "builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters", sbox)
115apply_template(sd + "/libsodium.vcxproj.filters.tpl",
116               "builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters", sbox)
117
118sbox.update({"platform": "v141"})
119apply_template(sd + "/libsodium.vcxproj.tpl",
120               "builds/msvc/vs2017/libsodium/libsodium.vcxproj", sbox)
121
122sbox.update({"platform": "v140"})
123apply_template(sd + "/libsodium.vcxproj.tpl",
124               "builds/msvc/vs2015/libsodium/libsodium.vcxproj", sbox)
125
126sbox.update({"platform": "v120"})
127apply_template(sd + "/libsodium.vcxproj.tpl",
128               "builds/msvc/vs2013/libsodium/libsodium.vcxproj", sbox)
129
130sbox.update({"platform": "v110"})
131apply_template(sd + "/libsodium.vcxproj.tpl",
132               "builds/msvc/vs2012/libsodium/libsodium.vcxproj", sbox)
133
134sbox.update({"platform": "v100"})
135apply_template(sd + "/libsodium.vcxproj.tpl",
136               "builds/msvc/vs2010/libsodium/libsodium.vcxproj", sbox)
137