3a2f284fba37e2e6da425a8337f5301709f69e0f
[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 ./include/version.default is used to generate RADIANT_MAJOR and RADIANT_MINOR
26 """
27
28 import os
29 import shutil
30
31 def assertMessage(condition, message):
32   if not condition:
33     raise Exception(message)
34
35 def copyFile(source, target):
36   assertMessage(os.path.isfile(source), "failed to find file: " + source)
37   print source, "->", target
38   shutil.copy2(source, target)
39
40 def copyFileIfExists(source, target):
41   if os.path.exists(source):
42     copyFile(source, target)
43
44 def copySvn(source, target):
45   assertMessage(os.path.isdir(source), "failed to find directory: " + source)
46   if not os.path.exists(target):
47     os.mkdir(target)
48   for name in os.listdir(source):
49     absolute = os.path.join(source, name)
50     absTarget = os.path.join(target, name)
51     if os.path.isdir(absolute):
52       if name != ".svn":
53         copySvn(absolute, absTarget)
54     else:
55       copyFile(absolute, absTarget)
56
57 def copyGame(source, game, target):
58   assertMessage(os.path.isdir(source), "failed to find directory: " + source)
59   assertMessage(os.path.isdir(target), "failed to find directory: " + target)
60   root = os.path.join(source, os.path.normpath(game[0]))
61   if os.path.exists(root):
62     gamename = game[1] + ".game"
63     copySvn(os.path.join(root, gamename), os.path.join(target, gamename))
64     gamesDir = os.path.join(target, "games")
65     if not os.path.exists(gamesDir):
66       os.mkdir(gamesDir)
67     copyFile(os.path.join(root, "games", gamename), os.path.join(gamesDir, gamename))
68
69 thisDir = os.path.dirname(__file__)
70 gamesRoot = os.path.join(thisDir, "games")
71 installRoot = os.path.join(thisDir, "install")
72
73 if not os.path.exists(installRoot):
74   os.mkdir(installRoot)
75
76 # copy generic data
77 copySvn(os.path.join(thisDir, os.path.normpath("setup/data/tools")), installRoot)
78
79 # root, gamename
80 games = [
81   ("Doom3Pack/tools", "doom3"),
82   ("ETPack", "et"),
83   ("HalfLifePack", "hl"),
84   ("Her2Pack", "heretic2"),
85   ("JAPack/Tools", "ja"),
86   ("JK2Pack", "jk2"),
87   ("Q1Pack", "q1"),
88   ("Q2Pack", "q2"),
89   ("Q3Pack/tools", "q3"),
90   ("Q4Pack/tools", "q4"),
91   ("Sof2Pack", "sof2"),
92   ("STVEFPack", "stvef"),
93   ("WolfPack/bin", "wolf"),
94   ("NexuizPack", "nexuiz"),
95   ("DarkPlacesPack", "darkplaces"),
96   ("WarsowPack/tools", "warsow")
97 ]
98
99 # copy games
100 for game in games:
101   copyGame(gamesRoot, game, installRoot)
102
103 # copy win32 dlls
104 gtk2Root = os.path.normpath(os.path.join(thisDir, "../gtk2-2.10/install"))
105 if os.path.exists(gtk2Root):
106   copySvn(gtk2Root, installRoot)
107
108 libxml2 = os.path.normpath(os.path.join(thisDir, "../libxml2-2.6/bin/libxml2.dll"))
109 copyFileIfExists(libxml2, installRoot)
110
111 libmhash = os.path.normpath(os.path.join(thisDir, "../mhash-0.9/win32/libmhash/Release/libmhash.dll"))
112 copyFileIfExists(libmhash, installRoot)
113
114 copySvn("../msvc_redist", installRoot)
115
116 dbghelp = os.path.normpath(os.path.join(thisDir, "../msvc_redist/dbghelp.dll"))
117 copyFileIfExists(dbghelp, installRoot)
118
119 # create version files
120 version = open(os.path.join(thisDir, "include/version.default"), "rt").readline().split(".")
121 assertMessage(len(version) == 3, "failed to parse include/version.default")
122 open(os.path.join(thisDir, "install/RADIANT_MAJOR"), "wt").write(str(version[1]))
123 open(os.path.join(thisDir, "install/RADIANT_MINOR"), "wt").write(str(version[2]))