added msvc dlls to install.py; added svn revision lookup to makeversion.py; updated...
[xonotic/netradiant.git] / install.py
1 # Copyright (C) 2001-2006 William Joseph.
2
3 # This file is part of GtkRadiant.
4
5 # GtkRadiant is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9
10 # GtkRadiant is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with GtkRadiant; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19 """
20 Builds the ./install directory.
21
22 Copies files from various locations:
23 ./setup/data/tools/
24 ./games/<gamepack>/
25 ../<library>/<library>.dll
26 ./include/version.default is used to generate RADIANT_MAJOR and RADIANT_MINOR
27 """
28
29 import os
30 import shutil
31
32 def assertMessage(condition, message):
33   if not condition:
34     raise Exception(message)
35     
36 def copyFile(source, target):
37   assertMessage(os.path.isfile(source), "failed to find file: " + source)
38   targetFile = target
39   if os.path.isdir(targetFile):
40     targetFile = os.path.join(target, os.path.basename(source))
41   print source, "->", targetFile
42   shutil.copyfile(source, targetFile)
43   
44 def copyFileIfExists(source, target):
45   if os.path.exists(source):
46     copyFile(source, target)
47     
48 def copySvn(source, target):
49   assertMessage(os.path.isdir(source), "failed to find directory: " + source)
50   if not os.path.exists(target):
51     os.mkdir(target)
52   for name in os.listdir(source):
53     absolute = os.path.join(source, name)
54     absTarget = os.path.join(target, name)
55     if os.path.isdir(absolute):
56       if name != ".svn":
57         copySvn(absolute, absTarget)
58     else:
59       copyFile(absolute, absTarget)
60       
61 def copyGame(source, game, target):
62   assertMessage(os.path.isdir(source), "failed to find directory: " + source)
63   assertMessage(os.path.isdir(target), "failed to find directory: " + target)
64   root = os.path.join(source, os.path.normpath(game[0]))
65   if os.path.exists(root):
66     gamename = game[1] + ".game"
67     copySvn(os.path.join(root, gamename), os.path.join(target, gamename))
68     gamesDir = os.path.join(target, "games")
69     if not os.path.exists(gamesDir):
70       os.mkdir(gamesDir)
71     copyFile(os.path.join(root, "games", gamename), os.path.join(gamesDir, gamename))  
72   
73 thisDir = os.path.dirname(__file__)
74 gamesRoot = os.path.join(thisDir, "games")
75 installRoot = os.path.join(thisDir, "install")
76
77 if not os.path.exists(installRoot):
78   os.mkdir(installRoot)
79   
80 # copy generic data
81 copySvn(os.path.join(thisDir, os.path.normpath("setup/data/tools")), installRoot)
82
83 # root, gamename
84 games = [
85   ("Doom3Pack/tools", "doom3"),
86   ("ETPack", "et"),
87   ("HalfLifePack", "hl"),
88   ("Her2Pack", "heretic2"),
89   ("JAPack/Tools", "ja"),
90   ("JK2Pack", "jk2"),
91   ("Q1Pack", "q1"),
92   ("Q2Pack", "q2"),
93   ("Q3Pack/tools", "q3"),
94   ("Q4Pack/tools", "q4"),
95   ("Sof2Pack", "sof2"),
96   ("STVEFPack", "stvef"),
97   ("WolfPack/bin", "wolf")
98 ]
99
100 # copy games
101 for game in games:
102   copyGame(gamesRoot, game, installRoot)
103
104 # copy win32 dlls
105 gtk2Root = os.path.normpath(os.path.join(thisDir, "../gtk2-2.4"))
106 if os.path.exists(gtk2Root):
107   copySvn(os.path.join(gtk2Root, "install"), installRoot)
108   
109 libxml2 = os.path.normpath(os.path.join(thisDir, "../libxml2-2.6/win32/install/libxml2.dll"))
110 copyFileIfExists(libxml2, installRoot)
111   
112 libpng = os.path.normpath(os.path.join(thisDir, "../libpng-1.2/lib/libpng13.dll"))
113 copyFileIfExists(libpng, installRoot)
114   
115 libmhash = os.path.normpath(os.path.join(thisDir, "../mhash-0.9/win32/libmhash/Release/libmhash.dll"))
116 copyFileIfExists(libmhash, installRoot)
117   
118 zlib = os.path.normpath(os.path.join(thisDir, "../zlib1-1.2/zlib1.dll"))
119 copyFileIfExists(zlib, installRoot)
120
121 msvcr71 = os.path.normpath(os.path.join(thisDir, "../msvc_redist/msvcr71.dll"))
122 copyFileIfExists(msvcr71, installRoot)
123
124 dbghelp = os.path.normpath(os.path.join(thisDir, "../msvc_redist/dbghelp.dll"))
125 copyFileIfExists(dbghelp, installRoot)
126
127 # create version files
128 version = open(os.path.join(thisDir, "include/version.default"), "rt").readline().split(".")
129 assertMessage(len(version) == 3, "failed to parse include/version.default")
130 open(os.path.join(thisDir, "install/RADIANT_MAJOR"), "wt").write(str(version[1]))
131 open(os.path.join(thisDir, "install/RADIANT_MINOR"), "wt").write(str(version[2]))