This repository has been archived by the owner on Sep 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
configure.py
56 lines (50 loc) · 2.55 KB
/
configure.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
import os.path, sys
class ConfigureScriptGenerator():
def __init__( self, project, path, version, install = True, static = True ):
self.__project = project
self.__path = path
self.__version = version
self.__staticSupported = static
autogen_dir = os.path.dirname( __file__ )
self.__winTemplate = os.path.abspath( autogen_dir + "/configure.bat.in" )
self.__unixTemplate = os.path.abspath( autogen_dir + "/configure.sh.in" )
if not os.path.exists( self.__path + "/LICENSE.GPL.txt") and not os.path.exists( self.__path + "/LICENSE.LGPL.txt" ):
print "no free license (LICENSE.GPL.txt or LICENSE.LGPL.txt) exists"
sys.exit( 1 )
self.__freeLicense = "LGPL" if os.path.exists( self.__path + "/LICENSE.LGPL.txt" ) else "GPL"
self.__licenseName = { 'GPL': 'GNU General Public License',
'LGPL': 'GNU Lesser General Public License' }
def run( self ):
self.__generateFile( self.__unixTemplate, os.path.abspath( self.__path + "/configure.sh" ), "unix" )
self.__generateFile( self.__winTemplate, os.path.abspath( self.__path + "/configure.bat" ), "win32" )
def __replaceValues( self, value ):
mixedname = self.__project
mixedname = mixedname.replace( "KD", "KD " )
value = value.replace( "@VERSION@", self.__version )
strStaticSupported = 'false'
if self.__staticSupported:
strStaticSupported = 'true'
value = value.replace( "@STATIC_BUILD_SUPPORTED@", strStaticSupported )
value = value.replace( "@PRODUCT_UPPERCASE@", self.__project.upper() )
value = value.replace( "@PRODUCT_LOWERCASE@", self.__project.lower() )
value = value.replace( "@PRODUCT_MIXEDCASE@", self.__project )
value = value.replace( "@PRODUCT_MIXEDCASE_SPACED@", mixedname )
value = value.replace( "@PRODUCT_LICENSE_FREE@", self.__freeLicense )
value = value.replace( "@PRODUCT_LICENSE_FREE_NAME@", self.__licenseName[self.__freeLicense] )
return value
def __generateFile( self, templateFile, outputFile, platformString ):
if platformString == "win32":
lineSep = "\r\n"
else:
lineSep = "\n"
with open( outputFile, "wb" ) as fOutput:
with open(os.path.dirname(__file__) + '/' + os.path.basename(outputFile) + '.in') as configureFile:
configure = configureFile.read().splitlines()
for line in ( configure ):
fOutput.write( self.__replaceValues( line.rstrip() ) + lineSep )
# make file executable for Unix
if platformString != "win32":
try:
os.chmod( outputFile, 0755 )
except SyntaxError: # Python 2.6 says syntax error on Windows, ignore it
print "ignoring failing os.chmod call, configure.sh won't be executable"