doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Setup.py
Go to the documentation of this file.
1 import sys, os, string, time, commands, re, pickle, StringIO, popen2, commands, pdb, zipfile, tempfile
2 
3 import scons_utils
4 
6 
7  # do not alter the sources, specially with strip and brandelfing
8  def BuildSetup( self, target = None, source = None, env = None ):
9  brandelf_path = source[0].abspath
10  if ( target[0].path == 'setup-demo' ):
11  print 'Building demo setup'
12  demo_build = True
13  core_path = source[1].abspath
14  game_path = source[2].abspath
15  else:
16  print 'Building setup'
17  demo_build = False
18  core_path = source[1].abspath
19  ded_path = source[2].abspath
20  game_path = source[3].abspath
21  d3xp_path = source[4].abspath
22  # identify dynamic dependencies that we bundle with the binary
23  ldd_deps = []
24  ldd_output = self.SimpleCommand( 'ldd -r ' + core_path )
25  pat = re.compile( '.*lib(stdc\+\+|gcc_s).* => (.*) \(.*\)' )
26  for i in string.split( ldd_output, '\n' ):
27  if ( pat.match( i ) ):
28  ldd_deps.append( pat.split( i )[ 2 ] )
29  # prep the binaries and update the paths
30  temp_dir = tempfile.mkdtemp( prefix = 'doomsetup' )
31  if ( demo_build ):
32  self.SimpleCommand( 'cp %s %s/doom.x86' % ( core_path, temp_dir ) )
33  core_path = '%s/doom.x86' % temp_dir
34  self.SimpleCommand( 'cp %s %s/gamex86.so' % ( game_path, temp_dir ) )
35  game_path = '%s/gamex86.so' % temp_dir
36  self.SimpleCommand( 'strip ' + core_path )
37  self.SimpleCommand( 'strip ' + game_path )
38  self.SimpleCommand( brandelf_path + ' -t Linux ' + core_path )
39  else:
40  self.SimpleCommand( 'cp %s %s/doom.x86' % ( core_path, temp_dir ) )
41  core_path = '%s/doom.x86' % temp_dir
42  self.SimpleCommand( 'cp %s %s/doomded.x86' % ( ded_path, temp_dir ) )
43  ded_path = '%s/doomded.x86' % temp_dir
44  self.SimpleCommand( 'cp %s %s/gamex86-base.so' % ( game_path, temp_dir ) )
45  game_path = '%s/gamex86-base.so' % temp_dir
46  self.SimpleCommand( 'cp %s %s/gamex86-d3xp.so' % ( d3xp_path, temp_dir ) )
47  d3xp_path = '%s/gamex86-d3xp.so' % temp_dir
48  self.SimpleCommand( 'strip ' + core_path )
49  self.SimpleCommand( 'strip ' + ded_path )
50  self.SimpleCommand( 'strip ' + game_path )
51  self.SimpleCommand( 'strip ' + d3xp_path )
52  self.SimpleCommand( brandelf_path + ' -t Linux ' + core_path )
53  self.SimpleCommand( brandelf_path + ' -t Linux ' + ded_path )
54  # main version tag - ENGINE_VERSION in Licensee.h
55  main_version = self.ExtractEngineVersion( )
56  # build number
57  version = self.ExtractBuildVersion( )
58  if ( demo_build ):
59  base_dirname = 'doom3-linux-%s.%s-demo' % ( main_version, version )
60  else:
61  base_dirname = 'doom3-linux-%s.%s' % ( main_version, version )
62  if ( os.path.exists( base_dirname ) ):
63  self.SimpleCommand( 'rm -rf %s' % base_dirname )
64  self.SimpleCommand( 'mkdir %s' % base_dirname )
65  self.SimpleCommand( 'cp -R sys/linux/setup/image-base/* ' + base_dirname )
66  if ( demo_build ):
67  self.SimpleCommand( 'cp -R -f sys/linux/setup/image-demo/* ' + base_dirname )
68  else:
69  self.SimpleCommand( 'cp -R -f sys/linux/setup/image/* ' + base_dirname )
70  # process M4 stuff
71  if ( demo_build ):
72  m4_dict = { 'M4_PRODUCT' : 'doom3-demo', 'M4_DESC' : 'DOOM III demo', 'M4_VERSION' : '%s.%s' % ( main_version, version ) }
73  else:
74  m4_dict = { 'M4_PRODUCT' : 'doom3', 'M4_DESC' : 'DOOM III', 'M4_VERSION' : '%s.%s' % ( main_version, version ) }
75  M4_LDD = ''
76  for i in ldd_deps:
77  if ( len( M4_LDD ) ):
78  M4_LDD += '\n'
79  M4_LDD += os.path.basename( i )
80  m4_dict[ 'M4_LDD' ] = M4_LDD
81  self.M4Processing( base_dirname + '/setup.data/setup.xml.in', m4_dict )
82  # build the game pak
83  if ( demo_build ):
84  # the demo doesn't use a game pak
85  self.SimpleCommand( 'cp ' + game_path + ' ' + base_dirname )
86  else:
87  # comment out this part to stick to game paks already provided in the media tree
88 # print 'zipping together base game01.pk4'
89 # game_zip = zipfile.ZipFile( 'sys/linux/setup/media/base/game01.pk4', 'w', zipfile.ZIP_DEFLATED )
90 # game_zip.write( game_path, 'gamex86.so' )
91 # game_zip.write( 'sys/linux/setup/binary.conf', 'binary.conf' )
92 # game_zip.printdir()
93 # game_zip.close()
94 # print 'zipping together d3xp game01.pk4'
95 # game_zip = zipfile.ZipFile( 'sys/linux/setup/media/d3xp/game01.pk4', 'w', zipfile.ZIP_DEFLATED )
96 # game_zip.write( d3xp_path, 'gamex86.so' )
97 # game_zip.write( 'sys/linux/setup/binary.conf', 'binary.conf' )
98 # game_zip.printdir()
99 # game_zip.close()
100  pass
101  # copy media
102  if ( demo_build ):
103  # we use a different repository path for large binary data
104  # extract or symlink from media-demo
105  if ( not os.path.exists( 'sys/linux/setup/media-demo' ) ):
106  print 'demo media is missing (sys/linux/setup/media-demo)'
107  sys.exit( 1 )
108  # check the md5 of the demo pack to be sure
109  md5sum = self.SimpleCommand( 'md5sum sys/linux/setup/media-demo/demo/demo00.pk4' )
110  if ( md5sum != '70c2c63ef1190158f1ebd6c255b22d8e sys/linux/setup/media-demo/demo/demo00.pk4' ):
111  print 'demo media has invalid checksum'
112  sys.exit( 1 )
113  self.SimpleCommand( 'cp -R sys/linux/setup/media-demo/* ' + base_dirname )
114  else:
115  if ( not os.path.exists( 'sys/linux/setup/media' ) ):
116  print 'media is missing (sys/linux/setup/media)'
117  sys.exit( 1 )
118  # copy the CHANGES file
119  self.SimpleCommand( 'cp -v sys/linux/setup/media/CHANGES ' + base_dirname )
120  # copy out the pk4 files from the main media tree
121  self.SimpleCommand( 'mkdir ' + base_dirname + '/base' )
122  self.SimpleCommand( 'mkdir ' + base_dirname + '/d3xp' )
123  self.SimpleCommand( 'find sys/linux/setup/media/ -name "*.pk4" | grep -v zpak | cut -b 23- | while read i ; do cp -v sys/linux/setup/media/$i ' + base_dirname + '/$i ; done' )
124  # copy
125  self.SimpleCommand( 'cp ' + core_path + ' ' + base_dirname + '/bin/Linux/x86' )
126  if ( not demo_build ):
127  self.SimpleCommand( 'cp ' + ded_path + ' ' + base_dirname + '/bin/Linux/x86' )
128  for i in ldd_deps:
129  self.SimpleCommand( 'cp ' + i + ' ' + base_dirname + '/' + os.path.basename( i ) )
130  # punkbuster
131  if ( not demo_build ):
132  self.SimpleCommand( 'cp -R punkbuster/setup/pb ' + base_dirname )
133  self.SimpleCommand( 'cp -Rf punkbuster/setup/linux/pb ' + base_dirname )
134  self.SimpleCommand( 'cp sys/linux/setup/media/PB_EULA.txt ' + base_dirname + '/pb' )
135  # put a version tag, xqf request
136  f = open( base_dirname + '/version.info', 'w' )
137  f.write( main_version + '\n' )
138  f.write( self.ExtractProtocolVersion() + '\n' )
139  f.close()
140  # create the FreeBSD symlinks
141  self.SimpleCommand( 'cd ' + base_dirname + '/bin ; ln -s Linux FreeBSD' )
142  self.SimpleCommand( 'cd ' + base_dirname + '/setup.data/bin ; ln -s Linux FreeBSD' )
143  # create amd64 symlinks
144  self.SimpleCommand( 'cd ' + base_dirname + '/bin/Linux ; ln -s x86 amd64' )
145  self.SimpleCommand( 'cd ' + base_dirname + '/setup.data/bin/Linux ; ln -s x86 amd64' )
146  # remove .svn entries
147  self.SimpleCommand( 'find ' + base_dirname + ' -name \'.svn\' -type d | xargs rm -rf' )
148  # remove D3XP related stuff until final release
149  #self.SimpleCommand( 'rm -rf ' + base_dirname + '/d3xp/*' )
150  # package it
151  target_setup = base_dirname + '.x86.run'
152  if ( demo_build ):
153  self.SimpleCommand( 'sys/linux/setup/makeself/makeself.sh ' + base_dirname + ' ' + target_setup + ' \'DOOM III demo\' ./setup.sh' )
154  else:
155  self.SimpleCommand( 'sys/linux/setup/makeself/makeself.sh ' + base_dirname + ' ' + target_setup + ' \'DOOM III\' ./setup.sh' )
156  # take out the temp dir
157  self.SimpleCommand( 'rm -rf %s' % temp_dir )
158  # success
159  return None
160 
def BuildSetup
Definition: Setup.py:8