2a9b4e75d3a52f499665012931afbd2999c6a15a
[minwii.git] / setup_win_exe.py
1 # -*- coding: utf-8 -*-
2 # This will create a dist directory containing the executable file, all the data
3 # directories. All Libraries will be bundled in executable file.
4 #
5 # Run the build process by entering 'pygame2exe.py' or
6 # 'python pygame2exe.py' in a console prompt.
7 #
8 # To build exe, python, pygame, and py2exe have to be installed. After
9 # building exe none of this libraries are needed.
10
11 try:
12 from distutils.core import setup
13 import py2exe, pygame
14 from modulefinder import Module
15 import glob, fnmatch
16 import sys, os, shutil
17 import operator
18 except ImportError, message:
19 raise SystemExit, "Unable to load module. %s" % message
20
21
22 origIsSystemDLL = py2exe.build_exe.isSystemDLL
23 def isSystemDLL(pathname):
24 if os.path.basename(pathname).lower() in ["sdl_ttf.dll"]:
25 return 0
26 return origIsSystemDLL(pathname)
27 py2exe.build_exe.isSystemDLL = isSystemDLL
28
29
30 class pygame2exe(py2exe.build_exe.py2exe): #This hack make sure that pygame default font is copied: no need to modify code for specifying default font
31 def copy_extensions(self, extensions):
32 #Get pygame default font
33 pygamedir = os.path.split(pygame.base.__file__)[0]
34 pygame_default_font = os.path.join(pygamedir, pygame.font.get_default_font())
35
36 #Add font to list of extension to be copied
37 extensions.append(Module("pygame.font", pygame_default_font))
38 py2exe.build_exe.py2exe.copy_extensions(self, extensions)
39
40 class BuildExe:
41 def __init__(self):
42 #Name of starting .py
43 self.script = "src/minwii/start_win.py"
44
45 #Name of program
46 self.project_name = "MINWii"
47
48 #Project url
49 self.project_url = "about:none"
50
51 #Version of program
52 self.project_version = "0.0"
53
54 #License of the program
55 self.license = "MyApps License"
56
57 #Auhor of program
58 self.author_name = "Me"
59 self.author_email = "example@example.com"
60 self.copyright = "Copyright (c) 2009 Me."
61
62 #Description
63 self.project_description = "MyApps Description"
64
65 #Icon file (None will use pygame default icon)
66 self.icon_file = None
67
68 #Extra files/dirs copied to game
69 self.data_files = [('minwii/fonts',
70 glob.glob('src/minwii/fonts/*.ttf'))]
71
72 #Extra/excludes python modules
73 self.extra_modules = []
74 self.exclude_modules = []
75
76 #DLL Excludes
77 self.exclude_dll = ['']
78
79 #Zip file name (None will bundle files in exe instead of zip file)
80 self.zipfile_name = None
81
82 #Dist directory
83 self.dist_dir ='dist'
84
85
86 def run(self):
87 if os.path.isdir(self.dist_dir): #Erase previous destination dir
88 shutil.rmtree(self.dist_dir)
89
90 if os.path.isdir('build'): #Clean up build dir
91 shutil.rmtree('build')
92
93
94 #Use the default pygame icon, if none given
95 if self.icon_file == None:
96 path = os.path.split(pygame.__file__)[0]
97 self.icon_file = os.path.join(path, 'pygame.ico')
98
99
100 setup(
101 cmdclass = {'py2exe': pygame2exe},
102 version = self.project_version,
103 description = self.project_description,
104 name = self.project_name,
105 url = self.project_url,
106 author = self.author_name,
107 author_email = self.author_email,
108 license = self.license,
109
110 # targets to build
111 #windows = [{
112 # 'script': self.script,
113 # 'icon_resources': [(0, self.icon_file)],
114 # 'copyright': self.copyright
115 #}],
116 console = [self.script],
117 options = {'py2exe': {#'optimize': 2,
118 'bundle_files': 1,
119 #'compressed': True,
120 'excludes': self.exclude_modules,
121 'packages': self.extra_modules,
122 'dll_excludes': self.exclude_dll}
123 },
124 zipfile = self.zipfile_name,
125 data_files = self.data_files,
126 dist_dir = self.dist_dir
127 )
128
129 #if os.path.isdir('build'): #Clean up build dir
130 # shutil.rmtree('build')
131
132 if __name__ == '__main__':
133 if operator.lt(len(sys.argv), 2):
134 sys.argv.append('py2exe')
135 BuildExe().run() #Run generation
136 #raw_input("Press any key to continue") #Pause to let user see that things ends