nsis.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (C) 2020 Red Hat, Inc.
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-or-later
  6. import argparse
  7. import glob
  8. import os
  9. import shutil
  10. import subprocess
  11. import tempfile
  12. def signcode(path):
  13. cmd = os.environ.get("SIGNCODE")
  14. if not cmd:
  15. return
  16. subprocess.run([cmd, path])
  17. def main():
  18. parser = argparse.ArgumentParser(description="QEMU NSIS build helper.")
  19. parser.add_argument("outfile")
  20. parser.add_argument("prefix")
  21. parser.add_argument("srcdir")
  22. parser.add_argument("cpu")
  23. parser.add_argument("nsisargs", nargs="*")
  24. args = parser.parse_args()
  25. destdir = tempfile.mkdtemp()
  26. try:
  27. subprocess.run(["make", "install", "DESTDIR=" + destdir + os.path.sep])
  28. with open(
  29. os.path.join(destdir + args.prefix, "system-emulations.nsh"), "w"
  30. ) as nsh:
  31. for exe in glob.glob(
  32. os.path.join(destdir + args.prefix, "qemu-system-*.exe")
  33. ):
  34. exe = os.path.basename(exe)
  35. arch = exe[12:-4]
  36. nsh.write(
  37. """
  38. Section "{0}" Section_{0}
  39. SetOutPath "$INSTDIR"
  40. File "${{BINDIR}}\\{1}"
  41. SectionEnd
  42. """.format(
  43. arch, exe
  44. )
  45. )
  46. for exe in glob.glob(os.path.join(destdir + args.prefix, "*.exe")):
  47. signcode(exe)
  48. makensis = [
  49. "makensis",
  50. "-V2",
  51. "-NOCD",
  52. "-DSRCDIR=" + args.srcdir,
  53. "-DBINDIR=" + destdir + args.prefix,
  54. ]
  55. dlldir = "w32"
  56. if args.cpu == "x86_64":
  57. dlldir = "w64"
  58. makensis += ["-DW64"]
  59. if os.path.exists(os.path.join(args.srcdir, "dll")):
  60. makensis += ["-DDLLDIR={0}/dll/{1}".format(args.srcdir, dlldir)]
  61. makensis += ["-DOUTFILE=" + args.outfile] + args.nsisargs
  62. subprocess.run(makensis)
  63. signcode(args.outfile)
  64. finally:
  65. shutil.rmtree(destdir)
  66. if __name__ == "__main__":
  67. main()