Marc-André Lureau | 8adfeba | 2020-08-26 15:04:19 +0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2020 Red Hat, Inc. |
| 4 | # |
| 5 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 6 | |
| 7 | import argparse |
| 8 | import glob |
| 9 | import os |
| 10 | import shutil |
| 11 | import subprocess |
| 12 | import tempfile |
| 13 | |
| 14 | |
| 15 | def signcode(path): |
| 16 | cmd = os.environ.get("SIGNCODE") |
| 17 | if not cmd: |
| 18 | return |
| 19 | subprocess.run([cmd, path]) |
| 20 | |
| 21 | |
| 22 | def main(): |
| 23 | parser = argparse.ArgumentParser(description="QEMU NSIS build helper.") |
| 24 | parser.add_argument("outfile") |
| 25 | parser.add_argument("prefix") |
| 26 | parser.add_argument("srcdir") |
| 27 | parser.add_argument("cpu") |
| 28 | parser.add_argument("nsisargs", nargs="*") |
| 29 | args = parser.parse_args() |
| 30 | |
| 31 | destdir = tempfile.mkdtemp() |
| 32 | try: |
| 33 | subprocess.run(["make", "install", "DESTDIR=" + destdir + os.path.sep]) |
| 34 | with open( |
| 35 | os.path.join(destdir + args.prefix, "system-emulations.nsh"), "w" |
Peter Maydell | c087963 | 2022-03-05 10:57:43 +0000 | [diff] [blame] | 36 | ) as nsh, open( |
| 37 | os.path.join(destdir + args.prefix, "system-mui-text.nsh"), "w" |
| 38 | ) as muinsh: |
Peter Maydell | e422d92 | 2022-03-05 10:57:41 +0000 | [diff] [blame] | 39 | for exe in sorted(glob.glob( |
Marc-André Lureau | 8adfeba | 2020-08-26 15:04:19 +0400 | [diff] [blame] | 40 | os.path.join(destdir + args.prefix, "qemu-system-*.exe") |
Peter Maydell | e422d92 | 2022-03-05 10:57:41 +0000 | [diff] [blame] | 41 | )): |
Marc-André Lureau | 8adfeba | 2020-08-26 15:04:19 +0400 | [diff] [blame] | 42 | exe = os.path.basename(exe) |
| 43 | arch = exe[12:-4] |
| 44 | nsh.write( |
| 45 | """ |
| 46 | Section "{0}" Section_{0} |
| 47 | SetOutPath "$INSTDIR" |
| 48 | File "${{BINDIR}}\\{1}" |
| 49 | SectionEnd |
| 50 | """.format( |
| 51 | arch, exe |
| 52 | ) |
| 53 | ) |
Peter Maydell | c087963 | 2022-03-05 10:57:43 +0000 | [diff] [blame] | 54 | if arch.endswith('w'): |
| 55 | desc = arch[:-1] + " emulation (GUI)." |
| 56 | else: |
| 57 | desc = arch + " emulation." |
| 58 | |
| 59 | muinsh.write( |
| 60 | """ |
| 61 | !insertmacro MUI_DESCRIPTION_TEXT ${{Section_{0}}} "{1}" |
| 62 | """.format(arch, desc)) |
Marc-André Lureau | 8adfeba | 2020-08-26 15:04:19 +0400 | [diff] [blame] | 63 | |
| 64 | for exe in glob.glob(os.path.join(destdir + args.prefix, "*.exe")): |
| 65 | signcode(exe) |
| 66 | |
| 67 | makensis = [ |
| 68 | "makensis", |
| 69 | "-V2", |
| 70 | "-NOCD", |
| 71 | "-DSRCDIR=" + args.srcdir, |
| 72 | "-DBINDIR=" + destdir + args.prefix, |
| 73 | ] |
| 74 | dlldir = "w32" |
| 75 | if args.cpu == "x86_64": |
| 76 | dlldir = "w64" |
| 77 | makensis += ["-DW64"] |
| 78 | if os.path.exists(os.path.join(args.srcdir, "dll")): |
Stefan Weil | 933c8fe | 2020-11-17 20:06:40 +0100 | [diff] [blame] | 79 | makensis += ["-DDLLDIR={0}/dll/{1}".format(args.srcdir, dlldir)] |
Marc-André Lureau | 8adfeba | 2020-08-26 15:04:19 +0400 | [diff] [blame] | 80 | |
| 81 | makensis += ["-DOUTFILE=" + args.outfile] + args.nsisargs |
| 82 | subprocess.run(makensis) |
| 83 | signcode(args.outfile) |
| 84 | finally: |
| 85 | shutil.rmtree(destdir) |
| 86 | |
| 87 | |
| 88 | if __name__ == "__main__": |
| 89 | main() |