summaryrefslogtreecommitdiff
path: root/distribution/bin/makebindist.py
blob: 99ca66ae85c9c7aab8b7b968ee533d915a36bd7b (plain)
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************

import os, sys, shutil, glob, fnmatch, string, re
from stat import *

version = "3.3.0"
#version = "@ver@"
distDir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(os.path.join(distDir, "lib"))
from DistUtils import *

#
# Defines which languges are supported on a given platform
#
languages = { \
    'SunOS' : ['cpp', 'java'], \
    'HP-UX' : ['cpp', 'java'], \
    'Darwin' : ['cpp', 'java', 'py'], \
    'Linux' : ['cpp', 'java', 'cs', 'py', 'rb', 'php'], \
}

#
# Defines third party dependencies for each supported platform and their default 
# location.
#
bzip2 = { 'HP-UX' : '/usr/local' }

berkeleydb = { \
    'SunOS' : '/opt/db', \
    'Darwin' : '/opt/db', \
    'HP-UX' : '/opt/db', \
}

berkeleydbjar = { \
    'Linux' : '/usr/share/java/db46/db.jar', \
}

expat = { \
    'SunOS' : '/usr/sfw', \
    'HP-UX' : '/usr/local', \
    'Darwin' : '/opt/expat', \
}

openssl = { \
    'SunOS' : '/usr/sfw', \
    'HP-UX' : '/opt/openssl', \
}

mcpp = { 
    'SunOS' : '/opt/mcpp', \
    'HP-UX' : '/opt/mcpp', \
    'Darwin' : '/opt/mcpp' 
}

jgoodies_looks = { \
    'SunOS' : '/share/opt/looks-2.1.4/looks-2.1.4.jar', \
    'HP-UX' : '/share/opt/looks-2.1.4/looks-2.1.4.jar', \
    'Darwin' : '/opt/looks-2.1.4/looks-2.1.4.jar', \
    'Linux' : '/opt/looks-2.1.4/looks-2.1.4.jar', \
}

jgoodies_forms = { \
    'SunOS' : '/share/opt/forms-1.1.0/forms-1.1.0.jar', \
    'HP-UX' : '/share/opt/forms-1.1.0/forms-1.1.0.jar', \
    'Darwin' : '/opt/forms-1.1.0/forms-1.1.0.jar', \
    'Linux' : '/opt/forms-1.1.0/forms-1.1.0.jar', \
}

proguard = { \
    'SunOS' : '/share/opt/proguard4.1/lib/proguard.jar', \
    'HP-UX' : '/share/opt/proguard4.1/lib/proguard.jar', \
    'Darwin' : '/opt/proguard/lib/proguard.jar', \
    'Linux' : '/opt/proguard/lib/proguard.jar', \
}    

class BerkeleyDB(ThirdParty):
    def __init__(self, platform, locations, jarlocations):
        ThirdParty.__init__(self, platform, "BerkeleyDB", locations, ["cpp", "java"], None, "DB_HOME")
        if not self.location:
            self.languages = ["java"]
            self.location = jarlocations.get(str(platform), None)

    def getJar(self):
        if self.location:
            if self.location.endswith(".jar"):
                return self.location
            else:
                return os.path.join(self.location, "lib", "db.jar")

    def getFiles(self, platform):
        files = [ os.path.join("lib", "db.jar"), os.path.join("bin", "db_*") ]
        files += platform.getSharedLibraryFiles(self.location, os.path.join("lib", "*"))
        files += platform.getSharedLibraryFiles(self.location, os.path.join("lib", "*"), "jnilib")
        return files

class Bzip2(ThirdParty):
    def __init__(self, platform, locations):
        ThirdParty.__init__(self, platform, "Bzip2", locations, ["cpp"])

    def getFiles(self, platform):
        return platform.getSharedLibraryFiles(self.location, os.path.join("lib", "*"))

class Expat(ThirdParty):
    def __init__(self, platform, locations):
        ThirdParty.__init__(self, platform, "Expat", locations, ["cpp"])

    def getFiles(self, platform):
        return platform.getSharedLibraryFiles(self.location, os.path.join("lib", "*"))

class OpenSSL(ThirdParty):
    def __init__(self, platform, locations):
        ThirdParty.__init__(self, platform, "OpenSSL", locations, ["cpp"])

    def getFiles(self, platform):
        files = [ os.path.join("bin", "openssl") ]
        files += platform.getSharedLibraryFiles(self.location, os.path.join("lib", "*"))
        return files

#
# Program usage.
#
def usage():
    print "Usage: " + sys.argv[0] + " [options] tag"
    print
    print "Options:"
    print "-c    Clean previous build"
    print "-n    Don't build any language mapping"
    print "-h    Show this message."
    print "-v    Be verbose."

#
# Instantiate the gobal platform object
#
(sysname, nodename, release, ver, machine) = os.uname();
if not languages.has_key(sysname):
    print sys.argv[0] + ": error: `" + sysname + "' is not a supported system"
platform = eval(sysname.replace("-", ""))(sysname, languages[sysname])

#
# Instantiate the third party libraries
#
thirdParties = [ \
    Bzip2(platform, bzip2), \
    BerkeleyDB(platform, berkeleydb, berkeleydbjar), \
    Expat(platform, expat), \
    OpenSSL(platform, openssl), \
    ThirdParty(platform, "Mcpp", mcpp, ["cpp"]), \
    ThirdParty(platform, "JGoodiesLooks", jgoodies_looks, ["java"], "jgoodies.looks"), \
    ThirdParty(platform, "JGoodiesForms", jgoodies_forms, ["java"], "jgoodies.forms"), \
    ThirdParty(platform, "Proguard", proguard, ["java"]), \
]

#
# Check arguments
#
verbose = 0
forceclean = 0
nobuild = 0
languages = [ ]
for x in sys.argv[1:]:
    if x == "-h":
        usage()
        sys.exit(0)
    elif x == "-v":
        verbose = 1
    elif x == "-c":
        forceclean = 1
    elif x == "-n":
        nobuild = 1
    elif x.startswith("-"):
        print sys.argv[0] + ": unknown option `" + x + "'"
        print
        usage()
        sys.exit(1)
    else:
        if not x in platform.languages:
            print sys.argv[0] + ": language `" + x + "' not supported on this platform"
            print
            usage()
            sys.exit(1)
        languages.append(x)

if len(languages) == 0:
    languages = platform.languages

if nobuild:
    languages = []

if verbose:
    quiet = "v"
else:
    quiet = ""

#
# Ensure the script is being run from the dist-@ver@ directory.
#
cwd = os.getcwd()

if not os.path.exists(os.path.join(distDir, "src", "windows", "LICENSE.rtf")):
    print sys.argv[0] + ": you must run makebindist.py from the dist-" + version + " directory created by makedist.py"
    sys.exit(1)

print "Building Ice " + version + " binary distribution (" + platform.getPackageName(version) + ".tar.gz)"
print "Using the following third party libraries:"
if not platform.checkAndPrintThirdParties():
    print "error: some required third party dependencies were not found"
    sys.exit(1)
    
#
# Ensure that the source archive or directory exists and create the build directory.
#
buildRootDir = os.path.join(cwd, os.path.join("build-" + platform.pkgname + "-" + version))
srcDir = os.path.join(buildRootDir, "Ice-" + version + "-src")
buildDir = os.path.join(buildRootDir, "Ice-" + version)
if forceclean or not os.path.exists(srcDir) or not os.path.exists(buildDir):
    if os.path.exists(buildRootDir):
        print "Removing previous build from " + os.path.join("build-" + platform.pkgname + "-" + version) + "...",
        sys.stdout.flush()
        shutil.rmtree(buildRootDir)
        print "ok"
    os.mkdir(buildRootDir)

    #
    # If we can't find the source archive in the current directory, ask its location
    #
    if not os.path.exists(os.path.join(cwd, "Ice-" + version + ".tar.gz")):
        print
        src = raw_input("Couldn't find Ice-" + version + ".tar.gz in current directory, please specify\n" + \
                        "where to download or copy the source distribution or hit enter to \n" + \
                        "download it from sun:/share/srcdists/" + version + ": ")
        if src == "":
            src = "sun:/share/srcdists/" + version + "/Ice-" + version + ".tar.gz"
        elif not src.endswith("Ice-" + version + ".tar.gz"):
            src = os.path.join(src, "Ice-" + version + ".tar.gz")

        if os.system("scp " + src + " ."):
            print sys.argv[0] + ": couldn't copy " + src
            sys.exit(1)
        
    print "Unpacking ./Ice-" + version + ".tar.gz ...",
    sys.stdout.flush()
    os.chdir(buildRootDir)
    if os.system("gunzip -c " + os.path.join(cwd, "Ice-" + version + ".tar.gz") + " | tar x" + quiet + "f -"):
        print sys.argv[0] + ": failed to unpack ./Ice-" + version + ".tar.gz"
        sys.exit(1)
    os.rename("Ice-" + version, srcDir)
    os.chdir(cwd)
    print "ok"

    os.mkdir(buildDir)

#
# Build and install each language mappings supported by this platform in the build directory.
#
for l in languages:
    print
    print "============= Building " + l + " sources ============="
    print
    os.chdir(os.path.join(srcDir, l))

    if l != "java":
        if os.system("gmake " + platform.getMakeEnvs(version, l) + " prefix=" + buildDir + " install") != 0:
            print sys.argv[0] + ": `" + l + "' build failed"
            os.chdir(cwd)
            sys.exit(1)
    else:
        antCmd = platform.getAntEnv() + " ant " + platform.getAntOptions() + " -Dprefix=" + buildDir

        if os.system(antCmd + " -Dbuild.suffix=-java2 -Dice.mapping=java2 install") != 0 or \
           os.system(antCmd + " -Dbuild.suffix=-java5 -Dice.mapping=java5 install") != 0: 
           print sys.argv[0] + ": `" + l + "' build failed"
           os.chdir(cwd)
           sys.exit(1)

    os.chdir(os.path.join(cwd))
    print
    print "============= Finished buiding " + l + " sources ============="
    print

#
# Copy platform third party dependencies.
#
print "Copying third party dependencies..."
sys.stdout.flush()
platform.copyThirdPartyDependencies(buildDir)
platform.completeDistribution(buildDir, version)

#
# Copy platform specific files (README, SOURCES, etc)
#
print "Copying distribution files (README, SOURCES, etc)...",
sys.stdout.flush()
platform.copyDistributionFiles(distDir, buildDir)

if os.path.exists(os.path.join(buildDir, "doc")):
    shutil.rmtree(os.path.join(buildDir, "doc"))
print "ok"

if not os.path.exists("RELEASE_NOTES.txt"):
    print "warning: couldn't find ./RELEASE_NOTES.txt file"
else:
    copy("RELEASE_NOTES.txt", os.path.join(buildDir, "RELEASE_NOTES.txt"))

#
# Everything should be clean now, we can create the binary distribution archive
# 
print "Archiving " + platform.getPackageName(version) + ".tar.gz ...",
sys.stdout.flush()
os.chdir(buildRootDir)
tarfile = os.path.join(cwd, platform.getPackageName(version)) + ".tar.gz"
os.system("tar c" + quiet + "f - Ice-" + version + " | gzip -9 - > " + tarfile)
os.chdir(cwd)
print "ok"

#
# Done.
#
print "Cleaning up...",
sys.stdout.flush()
shutil.rmtree(buildRootDir)
print "ok"

os.chdir(cwd)