3 # Copyright (C) 2020 Red Hat, Inc.
5 # SPDX-License-Identifier: GPL-2.0-or-later
16 cmd
= os
.environ
.get("SIGNCODE")
19 subprocess
.run([cmd
, path
])
21 def find_deps(exe_or_dll
, search_path
, analyzed_deps
):
23 output
= subprocess
.check_output(["objdump", "-p", exe_or_dll
], text
=True)
24 output
= output
.split("\n")
26 if not line
.startswith("\tDLL Name: "):
29 dep
= line
.split("DLL Name: ")[1].strip()
30 if dep
in analyzed_deps
:
33 dll
= os
.path
.join(search_path
, dep
)
34 if not os
.path
.exists(dll
):
35 # assume it's a Windows provided dll, skip it
38 analyzed_deps
.add(dep
)
39 # locate the dll dependencies recursively
40 rdeps
= find_deps(dll
, search_path
, analyzed_deps
)
46 parser
= argparse
.ArgumentParser(description
="QEMU NSIS build helper.")
47 parser
.add_argument("outfile")
48 parser
.add_argument("prefix")
49 parser
.add_argument("srcdir")
50 parser
.add_argument("dlldir")
51 parser
.add_argument("cpu")
52 parser
.add_argument("nsisargs", nargs
="*")
53 args
= parser
.parse_args()
55 # canonicalize the Windows native prefix path
56 prefix
= os
.path
.splitdrive(args
.prefix
)[1]
57 destdir
= tempfile
.mkdtemp()
59 subprocess
.run(["make", "install", "DESTDIR=" + destdir
])
61 os
.path
.join(destdir
+ prefix
, "system-emulations.nsh"), "w"
63 os
.path
.join(destdir
+ prefix
, "system-mui-text.nsh"), "w"
65 for exe
in sorted(glob
.glob(
66 os
.path
.join(destdir
+ prefix
, "qemu-system-*.exe")
68 exe
= os
.path
.basename(exe
)
72 Section "{0}" Section_{0}
74 File "${{BINDIR}}\\{1}"
80 if arch
.endswith('w'):
81 desc
= arch
[:-1] + " emulation (GUI)."
83 desc
= arch
+ " emulation."
87 !insertmacro MUI_DESCRIPTION_TEXT ${{Section_{0}}} "{1}"
88 """.format(arch
, desc
))
90 search_path
= args
.dlldir
91 print("Searching '%s' for the dependent dlls ..." % search_path
)
92 dlldir
= os
.path
.join(destdir
+ prefix
, "dll")
95 for exe
in glob
.glob(os
.path
.join(destdir
+ prefix
, "*.exe")):
98 # find all dll dependencies
99 deps
= set(find_deps(exe
, search_path
, set()))
102 # copy all dlls to the DLLDIR
104 dllfile
= os
.path
.join(dlldir
, os
.path
.basename(dep
))
105 if (os
.path
.exists(dllfile
)):
107 print("Copying '%s' to '%s'" % (dep
, dllfile
))
108 shutil
.copy(dep
, dllfile
)
114 "-DSRCDIR=" + args
.srcdir
,
115 "-DBINDIR=" + destdir
+ prefix
,
117 if args
.cpu
== "x86_64":
118 makensis
+= ["-DW64"]
119 makensis
+= ["-DDLLDIR=" + dlldir
]
121 makensis
+= ["-DOUTFILE=" + args
.outfile
] + args
.nsisargs
122 subprocess
.run(makensis
)
123 signcode(args
.outfile
)
125 shutil
.rmtree(destdir
)
128 if __name__
== "__main__":