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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2002
# ZeroC, Inc.
# Billerica, MA, USA
#
# All Rights Reserved.
#
# Ice is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# **********************************************************************
import os, sys, shutil, fnmatch, re
#
# Program usage.
#
def usage():
print "Usage: " + sys.argv[0] + " [options] [tag]"
print
print "Options:"
print "-h Show this message."
print "-d Skip SGML documentation conversion."
print
print "If no tag is given, HEAD is used."
#
# Find files matching a pattern.
#
def find(path, patt):
result = [ ]
files = os.listdir(path)
for x in files:
fullpath = os.path.join(path, x);
if os.path.isdir(fullpath) and not os.path.islink(fullpath):
result.extend(find(fullpath, patt))
elif fnmatch.fnmatch(x, patt):
result.append(fullpath)
return result
#
# Comment out rules in a Makefile.
#
def fixMakefile(file, target):
origfile = file + ".orig"
os.rename(file, origfile)
oldMakefile = open(origfile, "r")
newMakefile = open(file, "w")
origLines = oldMakefile.readlines()
doComment = 0
doCheck = 0
newLines = []
for x in origLines:
#
# If the line starts with the target string, then
# comment out this make target.
#
if x.startswith(target) and not x.startswith(target + ".o"):
doComment = 1
#
# If the line starts with "clean::", then check
# the following lines and comment out any that
# contain the target string.
#
elif x.startswith("clean::"):
doCheck = 1
#
# Stop when we encounter an empty line.
#
elif len(x.strip()) == 0:
doComment = 0
doCheck = 0
if doComment or (doCheck and x.find(target) != -1):
x = "#" + x
newLines.append(x)
newMakefile.writelines(newLines)
newMakefile.close()
oldMakefile.close()
os.remove(origfile)
#
# Check arguments
#
tag = "-rHEAD"
skipDocs = 0
for x in sys.argv[1:]:
if x == "-h":
usage()
sys.exit(0)
elif x == "-d":
skipDocs = 1
elif x.startswith("-"):
print "Unknown option `" + x + "'"
usage()
sys.exit(1)
else:
tag = "-r" + x
#
# Remove any existing "dist" directory and create a new one.
#
distdir = "dist"
if os.path.exists(distdir):
shutil.rmtree(distdir)
os.mkdir(distdir)
os.chdir(distdir)
#
# Export sources from CVS.
#
os.system("cvs -z5 -d cvs.mutablerealms.com:/home/cvsroot export " + tag + " ice")
#
# Remove files.
#
filesToRemove = [ \
"ice/makedist.py", \
]
for x in filesToRemove:
os.remove(x)
#
# Generate bison files.
#
cwd = os.getcwd()
grammars = find("ice", "*.y")
for x in grammars:
#
# Change to the directory containing the file.
#
(dir,file) = os.path.split(x)
os.chdir(dir)
(base,ext) = os.path.splitext(file)
#
# Run gmake to create the output files.
#
if file == "cexp.y":
os.system("gmake cexp.c")
else:
os.system("gmake " + base + ".cpp")
#
# Edit the Makefile to comment out the grammar rules.
#
fixMakefile("Makefile", base)
os.chdir(cwd)
#
# Generate flex files.
#
scanners = find("ice", "*.l")
for x in scanners:
#
# Change to the directory containing the file.
#
(dir,file) = os.path.split(x)
os.chdir(dir)
(base,ext) = os.path.splitext(file)
#
# Run gmake to create the output files.
#
os.system("gmake " + base + ".cpp")
#
# Edit the Makefile to comment out the flex rules.
#
fixMakefile("Makefile", base)
os.chdir(cwd)
#
# Generate HTML documentation. We need to build icecpp
# and slice2docbook first.
#
if not skipDocs:
os.chdir(os.path.join("ice", "src", "icecpp"))
os.system("gmake")
os.chdir(cwd)
os.chdir(os.path.join("ice", "src", "IceUtil"))
os.system("gmake")
os.chdir(cwd)
os.chdir(os.path.join("ice", "src", "Slice"))
os.system("gmake")
os.chdir(cwd)
os.chdir(os.path.join("ice", "src", "slice2docbook"))
os.system("gmake")
os.chdir(cwd)
os.chdir(os.path.join("ice", "doc"))
os.system("gmake")
os.chdir(cwd)
#
# Clean the source directory.
#
os.chdir(os.path.join("ice", "src"))
os.system("gmake clean")
os.chdir(cwd)
#
# Get Ice version.
#
config = open(os.path.join("ice", "include", "IceUtil", "Config.h"), "r")
version = re.search("ICE_STRING_VERSION \"(.*)\"", config.read()).group(1)
#
# Create archives.
#
icever = "Ice-" + version
os.rename("ice", icever)
os.system("tar cvzf " + icever + ".tar.gz " + icever)
os.system("zip -9r " + icever + ".zip " + icever)
#
# Copy files (README, etc.).
#
#
# Done.
#
shutil.rmtree(icever)
|