Major redesign of the build system. Also allow icons to be installed optionally:
[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 sys
18
19 # ==============================
20 #  Constants
21 # ==============================
22 if len(sys.argv) < 2:
23     sys.exit(1)
24
25 SOURCE_DIR = sys.argv[1]
26
27 if len(sys.argv) < 4:
28     BUNDLE_NAME= "Quassel Client"
29     EXE_NAME = "quasselclient"
30 else:
31     BUNDLE_NAME = sys.argv[2]
32     EXE_NAME = sys.argv[3]
33 CONTENTS_DIR = BUNDLE_NAME + ".app/Contents/"
34
35 BUNDLE_VERSION = "0.3.0"
36 ICON_FILE = "pics/quassel.icns"
37
38 def createBundle():
39     try:
40         os.makedirs(CONTENTS_DIR + "MacOS")
41         os.makedirs(CONTENTS_DIR + "Resources")
42     except:
43         pass
44
45 def copyFiles(exeFile, iconFile):
46     os.system("cp %s %sMacOs/%s" % (exeFile, CONTENTS_DIR.replace(' ', '\ '), BUNDLE_NAME.replace(' ', '\ ')))
47     os.system("cp %s/%s %s/Resources" % (SOURCE_DIR, iconFile, CONTENTS_DIR.replace(' ', '\ ')))
48
49 def createPlist(bundleName, iconFile, bundleVersion):
50     templateFile = file(SOURCE_DIR + "/scripts/build/Info.plist", 'r')
51     template = templateFile.read()
52     templateFile.close()
53     print 
54
55     plistFile = file(CONTENTS_DIR + "Info.plist", 'w')
56     plistFile.write(template % {"BUNDLE_NAME" : bundleName,
57                                 "ICON_FILE" : iconFile[iconFile.rfind("/")+1:],
58                                 "BUNDLE_VERSION" : bundleVersion})
59     plistFile.close()
60
61 if __name__ == "__main__":
62     createBundle()
63     createPlist(BUNDLE_NAME, ICON_FILE, BUNDLE_VERSION)
64     copyFiles(EXE_NAME, ICON_FILE)
65     pass