3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 # Copyright (c) 2009 Dominik Riebeling
12 # All files in this archive are subject to the GNU General Public License.
13 # See the file COPYING in the source tree root for full license agreement.
15 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 # KIND, either express or implied.
19 # Automate building releases for deployment.
20 # Run from source folder. Error checking / handling rather is limited.
21 # If the required Qt installation isn't in PATH use --qmake option.
22 # Tested on Linux and MinGW / W32
24 # requires python which package (http://code.google.com/p/which/)
25 # requires upx.exe in PATH on Windows.
39 # Windows nees some special treatment. Differentiate between program name
40 # and executable filename.
42 if sys
.platform
== "win32":
43 progexe
= "Release/rbutilqt.exe"
47 programfiles
= [ progexe
]
52 print "Usage: %s [options]" % myself
53 print " -q, --qmake=<qmake> path to qmake"
54 print " -h, --help this help"
57 def findversion(versionfile
):
58 '''figure most recent program version from version.h,
59 returns version string.'''
60 h
= open(versionfile
, "r")
63 r
= re
.compile("#define +VERSION +\"(.[0-9\.a-z]+)\"")
65 s
= re
.compile("\$Revision: +([0-9]+)")
68 print "WARNING: Revision not found!"
73 '''Search for Qt4 installation. Return path to qmake.'''
74 print "Searching for Qt"
75 bins
= ["qmake", "qmake-qt4"]
78 q
= which
.which(binary
)
80 output
= subprocess
.Popen([q
, "-version"], stdout
=subprocess
.PIPE
,
81 stderr
=subprocess
.PIPE
).communicate()
83 r
= re
.compile("Qt[^0-9]+([0-9\.]+[a-z]*)")
86 print "Qt found: %s" % m
.group(1)
87 s
= re
.compile("4\..*")
88 n
= re
.search(s
, m
.group(1))
92 print "ERROR: No suitable Qt found!"
97 def qmake(qmake
="qmake"):
98 print "Running qmake ..."
99 output
= subprocess
.Popen([qmake
, "-config", "static", "-config", "release"],
100 stdout
=subprocess
.PIPE
).communicate()
106 output
= subprocess
.Popen(["make"], stdout
=subprocess
.PIPE
).communicate()
108 print "Stripping binary."
109 output
= subprocess
.Popen(["strip", progexe
], stdout
=subprocess
.PIPE
).communicate()
114 print "UPX'ing binary ..."
115 output
= subprocess
.Popen(["upx", progexe
], stdout
=subprocess
.PIPE
).communicate()
118 def zipball(versionstring
):
119 '''package created binary'''
120 print "Creating binary zipball."
121 outfolder
= program
+ "-v" + versionstring
122 archivename
= outfolder
+ ".zip"
123 # create output folder
125 # move program files to output folder
126 for f
in programfiles
:
127 shutil
.copy(f
, outfolder
)
128 # create zipball from output folder
129 zf
= zipfile
.ZipFile(archivename
, mode
='w', compression
=zipfile
.ZIP_DEFLATED
)
130 for root
, dirs
, files
in os
.walk(outfolder
):
132 zf
.write(os
.path
.join(root
, name
))
134 zf
.write(os
.path
.join(root
, name
))
136 # remove output folder
137 for root
, dirs
, files
in os
.walk(outfolder
, topdown
=False):
139 os
.remove(os
.path
.join(root
, name
))
141 os
.rmdir(os
.path
.join(root
, name
))
143 st
= os
.stat(archivename
)
144 print "done: %s, %i bytes" % (archivename
, st
.st_size
)
147 def tarball(versionstring
):
148 '''package created binary'''
149 print "Creating binary tarball."
150 outfolder
= program
+ "-v" + versionstring
151 archivename
= outfolder
+ ".tar.bz2"
152 # create output folder
154 # move program files to output folder
155 for f
in programfiles
:
156 shutil
.copy(f
, outfolder
)
157 # create tarball from output folder
158 tf
= tarfile
.open(archivename
, mode
='w:bz2')
161 # remove output folder
162 for root
, dirs
, files
in os
.walk(outfolder
, topdown
=False):
164 os
.remove(os
.path
.join(root
, name
))
166 os
.rmdir(os
.path
.join(root
, name
))
168 st
= os
.stat(archivename
)
169 print "done: %s, %i bytes" % (archivename
, st
.st_size
)
174 opts
, args
= getopt
.getopt(sys
.argv
[1:], "qh", ["qmake=", "help"])
175 except getopt
.GetoptError
, err
:
181 if o
in ("-q", "--qmake"):
183 if o
in ("-h", "--help"):
191 print "ERROR: No suitable Qt installation found."
194 # figure version from sources
195 ver
= findversion("version.h")
196 header
= "Building %s %s" % (program
, ver
)
198 print len(header
) * "="
203 if sys
.platform
== "win32":
211 if __name__
== "__main__":