build: Set macOS minimum version to Qt min version
[quassel.git] / scripts / build / macosx_makebundle.py
1 #!/usr/bin/python
2 # -*- coding: iso-8859-1 -*-
3
4 ################################################################################
5 #                                                                              #
6 # 2008 June 27th by Marcus 'EgS' Eggenberger <egs@quassel-irc.org>             #
7 #                                                                              #
8 # The author disclaims copyright to this source code.                          #
9 # This Python Script is in the PUBLIC DOMAIN.                                  #
10 #                                                                              #
11 ################################################################################
12
13 # ==============================
14 #  Imports
15 # ==============================
16 import os
17 import os.path
18 import sys
19 import commands
20
21 # Handling Qt properties
22 import macosx_qt
23
24 # ==============================
25 #  Constants
26 # ==============================
27 if len(sys.argv) < 2:
28     sys.exit(1)
29
30 SOURCE_DIR = sys.argv[1]
31
32 if len(sys.argv) < 4:
33     BUNDLE_NAME = "Quassel Client"
34     EXE_NAME = "quasselclient"
35 else:
36     EXE_NAME = sys.argv[3]
37     BUNDLE_NAME = sys.argv[2]
38
39 # make the dir of the exe the target dir
40 if(os.path.dirname(EXE_NAME)):
41     CONTENTS_DIR = os.path.dirname(EXE_NAME) + "/"
42 CONTENTS_DIR += BUNDLE_NAME + ".app/Contents/"
43
44 BUNDLE_VERSION = commands.getoutput("git --git-dir=" + SOURCE_DIR + "/.git/ describe")
45 ICONSET_FOLDER = "pics/iconset/"
46
47
48 def createBundle():
49     try:
50         os.makedirs(CONTENTS_DIR + "MacOS")
51         os.makedirs(CONTENTS_DIR + "Resources")
52     except:
53         pass
54
55
56 def copyFiles(exeFile, iconset):
57     os.system("cp %s %sMacOs/%s" % (exeFile, CONTENTS_DIR.replace(' ', '\ '), BUNDLE_NAME.replace(' ', '\ ')))
58     os.system("cp -r %s/%s %s/Resources/quassel.iconset/" % (SOURCE_DIR, iconset, CONTENTS_DIR.replace(' ', '\ ')))
59
60
61 def createPlist(bundleName, bundleVersion):
62     templateFile = file(SOURCE_DIR + "/scripts/build/Info.plist", 'r')
63     template = templateFile.read()
64     templateFile.close()
65
66     # Get the minimum macOS deployment version
67     QT_MACOSX_DEPLOYMENT_TARGET = macosx_qt.qtMakespec('QMAKE_MACOSX_DEPLOYMENT_TARGET')
68     # Keep in sync with QMAKE_MACOSX_DEPLOYMENT_TARGET
69     # See https://doc.qt.io/qt-5/macos.html
70     if QT_MACOSX_DEPLOYMENT_TARGET is None:
71         # Something went wrong
72         sys.exit("Could not determine 'QMAKE_MACOSX_DEPLOYMENT_TARGET', check build scripts")
73     print("Qt macOS deployment target (minimum version): %s" % QT_MACOSX_DEPLOYMENT_TARGET)
74
75     plistFile = file(CONTENTS_DIR + "Info.plist", 'w')
76     plistFile.write(template % {"BUNDLE_NAME": bundleName,
77                                 "ICON_FILE": "quassel.icns",
78                                 "BUNDLE_VERSION": bundleVersion,
79                                 "QT_MACOSX_DEPLOYMENT_TARGET": QT_MACOSX_DEPLOYMENT_TARGET})
80     plistFile.close()
81
82 def convertIconset():
83     os.system("iconutil -c icns %s/Resources/quassel.iconset" % CONTENTS_DIR.replace(' ', '\ '))
84     os.system("rm -R %s/Resources/quassel.iconset" % CONTENTS_DIR.replace(' ', '\ '))
85
86 if __name__ == "__main__":
87     createBundle()
88     createPlist(BUNDLE_NAME, BUNDLE_VERSION)
89     copyFiles(EXE_NAME, ICONSET_FOLDER)
90     convertIconset()