1# $Id: make.py,v 1.30 2003/01/03 00:21:45 gelderen Exp $
2#
3# Cryptix JCE Make Script
4#
5# Copyright (C) 1995-2001 The Cryptix Foundation Limited.
6# All rights reserved.
7#
8# Use, modification, copying and distribution of this software is subject
9# the terms and conditions of the Cryptix General Licence. You should have
10# received a copy of the Cryptix General Licence along with this library;
11# if not, you can download a copy from http://www.cryptix.org/ .
12#
13# Quick hack by Jeroen C. van Gelderen (gelderen@cryptix.org) who got tired
14# from trying to create cross platform (*@&#($ shell scripts/batch files.
15
16
17import os
18import os.path
19import shutil
20import stat
21import sys
22import time
23
24#
25# Need to set these in environment or the make will crash
26#
27JAVAC       = os.environ['JAVAC']
28JAVAC_FLAGS = os.environ['JAVAC_FLAGS']
29CLASSPATH   = os.environ['CLASSPATH']
30CLASSPATH11 = os.environ['CLASSPATH11']
31
32if CLASSPATH == CLASSPATH11:
33    JDK11=1
34else:
35    JDK11=0
36
37
38def target_clean():
39    if os.path.exists('build'):
40        print '  Removing build directory'
41        shutil.rmtree('build')
42
43
44def target_compat():
45    generic_target(
46        ('java.security',
47         'java.security.spec',
48         'java.security.interfaces',
49         'java.security.cert',
50         'java.util'),
51        'compat',
52        ('',),
53        CLASSPATH,
54        CLASSPATH11)
55
56
57def target_api():
58    generic_target(
59        ('cryptix.jce.util',
60         'javax.crypto',
61         'javax.crypto.spec',
62         'javax.crypto.interfaces'),
63        'api',
64        ('',),
65        CLASSPATH,
66        CLASSPATH)
67
68
69def target_provider_1():
70    generic_target(
71        ('cryptix.jce',
72         'cryptix.jce.provider.asn',
73         'cryptix.jce.provider.util'),
74        'provider',
75        ('../api',),
76        CLASSPATH,
77        CLASSPATH)
78
79def target_provider_2():
80    generic_target(
81        ('cryptix.jce.provider',
82         'cryptix.jce.examples',
83         'cryptix.jce.provider.key',
84         'cryptix.jce.provider.keyfactory',
85         'cryptix.jce.provider.cipher',
86         'cryptix.jce.provider.dh',
87         'cryptix.jce.provider.dsa',
88         'cryptix.jce.provider.mac',
89         'cryptix.jce.provider.md',
90         'cryptix.jce.provider.random',
91         'cryptix.jce.provider.rsa',
92         'cryptix.jce.provider.parameters',
93         'cryptix.jce.provider.elgamal'),
94        'provider',
95        ('../api',),
96        CLASSPATH,
97        CLASSPATH)
98
99
100def target_tests():
101    generic_target(
102        ('cryptix.jce.test',),
103        'tests',
104        ('../api', '../provider'),
105        CLASSPATH,
106        CLASSPATH)
107
108
109def target_all():
110    target_compat()
111    target_api()
112    target_provider_1()
113    target_provider_2()
114    target_tests()
115
116
117def target_jars():
118    target_all()
119    generic_makejar('compat', 'cryptix-jce-compat.jar')
120    generic_makejar('api', 'cryptix-jce-api.jar')
121    generic_makejar('provider', 'cryptix-jce-provider.jar')
122    generic_makejar('tests', 'cryptix-jce-tests.jar')
123
124
125def target_dist():
126    target_clean()
127    target_jars()
128    os.system('jarsigner -keystore /.cryptix/cryptix.keystore build/jars/cryptix-jce-provider.jar cryptix')
129
130    print '  Copying files'
131    makedirs('build/dist/')
132
133    # copy jars
134    shutil.copytree('build/jars', 'build/dist/bin')
135
136    # copy source and remove CVS dirs
137    shutil.copytree('src', 'build/dist/src')
138    remove_recursive('build/dist/src', 'CVS')
139
140    # copy doco
141    shutil.copy('doc/README.TXT', 'build/dist/README.TXT')
142    shutil.copy('LICENCE.TXT',    'build/dist')
143    shutil.copy('make.py',        'build/dist')
144
145    date = time.strftime("%Y%m%d", time.gmtime(time.time()))
146    fname = "cryptix-jce-" + date + "-snap.zip"
147    print "  Creating " + fname
148    os.system("cd build/dist && zip -9rq ../" + fname + " .")
149
150
151#
152# Recursively remove all directories named 'name',
153# starting in directory 'dir'
154#
155def remove_recursive(dir, name):
156    for f in os.listdir(dir):
157        path = '%s/%s' % (dir, f)
158        mode = os.stat(path)[stat.ST_MODE]
159        if stat.S_ISDIR(mode):
160            if f == name:
161                shutil.rmtree(path)
162            else:
163                remove_recursive(path, name)
164
165
166def generic_makejar(dir, name):
167    makedirs('build/jars/')
168    os.chdir('build/classes/' + dir)
169    print '  Creating ' + name
170    os.system('jar -cf ../../jars/' + name + ' *')
171    os.chdir('../../..')
172
173
174def generic_target(classes, output_dir, extra_classpath, sys_classpath, boot_classpath):
175    makedirs('build/classes/' + output_dir)
176    os.chdir('build/classes/' + output_dir)
177
178    my_classpath = os.pathsep
179    for a in extra_classpath:
180        my_classpath = my_classpath + a + os.pathsep
181
182    if output_dir != 'compat':
183        if JDK11==1:
184            my_classpath = my_classpath + '../compat' + os.pathsep
185
186    if JAVAC=='jikes':
187        my_classpath = my_classpath + boot_classpath
188        command = (JAVAC + ' ' +
189                   JAVAC_FLAGS + ' ' +
190                   '-d . ' +
191                   '-classpath .' + my_classpath )
192    else:
193        my_classpath = my_classpath + sys_classpath
194        command = (JAVAC + ' ' +
195                   JAVAC_FLAGS + ' ' +
196                   '-d . ' +
197                   '-classpath .' + my_classpath + ' ' +
198                   '-bootclasspath ' + boot_classpath)
199
200    files = ''
201    print '  Building:'
202    for c in classes:
203        print '    ' + c
204        files = files + '' + os.path.normcase(' ../../../src/' + c + '/*.java')
205    os.system(command + files)
206
207    os.chdir("../../..")
208
209def makedirs(path):
210    try:    os.makedirs(path)
211    except: pass
212
213
214if __name__ == "__main__":
215    print 'Cryptix JCE Make Script - http://www.cryptix.org/\n'
216
217    if JDK11==0:
218        print "Assuming JDK 1.2.x mode\n"
219    else:
220        print "Assuming JDK 1.1.x mode\n"
221
222    if len(sys.argv) == 1:
223        sys.argv.append("all")
224
225    for target in sys.argv[1:]:
226        try:
227            print 'Making', target
228            eval( 'target_' + target + '()' )
229        except NameError, e:
230            print "Undefined target:", e
231