-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwindows_build.py
168 lines (138 loc) · 5.31 KB
/
windows_build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/python
# -*- coding: latin-1 -*-
# Reggie Next - New Super Mario Bros. Wii / New Super Mario Bros 2 Level Editor
# Milestone 2 Alpha 4
# Copyright (C) 2009-2014 Treeki, Tempus, angelsl, JasonP27, Kamek64,
# MalStar1000, RoadrunnerWMC
# This file is part of Reggie Next.
# Reggie Next is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Reggie Next is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Reggie Next. If not, see <http://www.gnu.org/licenses/>.
# windows_build.py
# Builds Reggie! to a Windows binary (*.exe)
# Use the values below to configure the release:
PackageName = 'reggie_next_m2a4_win32'
Version = '0.14' # This must be a valid float in string format
################################################################
################################################################
# Imports
import os, os.path, shutil, sys
try:
from cx_Freeze import setup, Executable
except ImportError:
print('>> Imports failed; please install cx_Freeze.')
# Verbose flag
verboseFlag = False
if '-v' in sys.argv:
sys.argv.remove('-v')
verboseFlag = True
if '--verbose' in sys.argv:
sys.argv.remove('--verbose')
verboseFlag = True
# Useful function to print text only if in verbose mode
def printv(text):
"""Convenience function"""
if verboseFlag: print(text)
# UPX flag
upxFlag = False
if '-upx' in sys.argv:
sys.argv.remove('-upx')
upxFlag = True
# Pick a build directory
dir_ = 'distrib/' + PackageName
printv('>> Build directory will be ' + dir_)
# Print some stuff
print('[[ Freezing Reggie! Next ]]')
print('>> Destination directory: %s' % dir_)
# Add the "build" parameter to the system argument list
if 'build' not in sys.argv:
sys.argv.append('build')
# Clear the directory
printv('>> Clearing/creating directory...')
if os.path.isdir(dir_): shutil.rmtree(dir_)
os.makedirs(dir_)
printv('>> Directory ready!')
# exclude QtWebKit to save space, plus Python stuff we don't use
excludes = ['doctest', 'pdb', 'unittest', 'difflib', 'inspect',
'os2emxpath', 'posixpath', 'optpath', 'locale', 'calendar',
'select', 'multiprocessing', 'ssl',
'PyQt5.QtWebKit', 'PyQt5.QtNetwork']
# Set it up
printv('>> Running build functions...')
base = 'Win32GUI' if sys.platform == 'win32' else None
setup(
name = 'Reggie! Level Editor Next',
version = Version,
description = 'Reggie! Level Editor Next',
options={
'build_exe': {
'excludes': excludes,
'packages': ['sip', 'encodings', 'encodings.hex_codec', 'encodings.utf_8'],
'compressed': 1,
'build_exe': dir_,
'icon': 'reggiedata/win_icon.ico',
},
},
executables = [
Executable(
'reggie.py',
base = base,
),
],
)
print('>> Built frozen executable!')
# Now that it's built, configure everything
# Remove a useless file we don't need
printv('>> Attempting to remove w9xpopen.exe ...')
try: os.unlink(dir_ + '/w9xpopen.exe')
except: pass
printv('>> Done.')
if upxFlag:
if os.path.isfile('upx/upx.exe'):
print('>> Found UPX, using it to compress the executables!')
files = os.listdir(dir_)
upx = []
for f in files:
if f.endswith('.exe') or f.endswith('.dll') or f.endswith('.pyd'):
upx.append('"%s/%s"' % (dir_,f))
os.system('upx/upx.exe -9 ' + ' '.join(upx))
print('>> Compression complete.')
else:
print('>> UPX not found, binaries can\'t be compressed.')
print('>> In order to build Reggie! with UPX, place the upx.exe file into '
'a subdirectory named "upx".')
else:
print('>> No \'-upx\' flag specified, so UPX compression will not be attempted.')
print('>> Attempting to copy required files...')
if os.path.isdir(dir_ + '/reggiedata'): shutil.rmtree(dir_ + '/reggiedata')
if os.path.isdir(dir_ + '/reggieextras'): shutil.rmtree(dir_ + '/reggieextras')
shutil.copytree('reggiedata', dir_ + '/reggiedata')
shutil.copytree('reggieextras', dir_ + '/reggieextras')
shutil.copy('license.txt', dir_)
shutil.copy('readme.md', dir_)
if not os.path.isfile(dir_ + '/libEGL.dll'):
shutil.copy('libEGL.dll', dir_)
print('>> Files copied!')
print('>> Attempting to write a new release.txt ...')
release = open(dir_ + '/release.txt', 'w', encoding='utf-8')
release.write('windows')
release.close()
del release
print('>> release.txt written!')
print('>> Attempting to copy VC++2008 libraries...')
if os.path.isdir('Microsoft.VC90.CRT'):
shutil.copytree('Microsoft.VC90.CRT', dir_ + '/Microsoft.VC90.CRT')
print('>> Copied libraries!')
else:
print('>> Libraries not found! The frozen executable will require the '
'Visual C++ 2008 runtimes to be installed in order to work.')
print('>> In order to automatically include the runtimes, place the '
'Microsoft.VC90.CRT folder into this folder.')
print('>> Reggie has been frozen to %s !' % dir_)