File: setup.py

package info (click to toggle)
sketch 0.6.13-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,284 kB
  • ctags: 8,453
  • sloc: python: 34,711; ansic: 16,543; makefile: 83; sh: 26
file content (745 lines) | stat: -rwxr-xr-x 24,603 bytes parent folder | download
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
#! /usr/bin/env python

# Sketch - A Python-based interactive drawing program
# Copyright (C) 1998, 1999, 2000, 2001, 2002 by Bernhard Herzog
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#
# Configure Script for Sketch
#
# This script tries to figure out how to configure Sketch to work work
# with your python installation.
#
# It is very experimental at the moment. In particular it is not as
# generic as it could be and contains lots of hacks to make it work for
# the current release.
#

import sys, os
import re
import glob
import compileall
import shutil, pipes

from string import split, join, strip, atoi

def abspath(path):
    if not os.path.isabs(path):
        path = os.path.join(os.getcwd(), path)
    return os.path.normpath(path)

#
# Part 1:
#
# extract config info from Python's modules Setup.
#

rx_comment = re.compile('^[ \t]*#')
rx_macro = re.compile('^.*=')
rx_ignore = re.compile(r'[ \t]*($|\*)')

class ModuleConfig:

    def __init__(self):
        self.files = []
        self.inc_dirs = []
        self.macros = []
        self.lib_dirs = []
        self.libraries = []


def read_target(args, setup):
    while args[-2:] == '\\\n':
        #print '->', args
        line = setup.readline()
        #print line
        if not line:
            break
        if rx_comment.match(line):
            continue
        args = args[:-2] + line

    config = ModuleConfig()

    for item in split(args):
        if item == '#':
            break
        head = item[:2]
        if head == '-I':
            config.inc_dirs.append(item)
        elif head == '-D':
            config.macros.append(item)
        elif head == '-L':
            config.lib_dirs.append(item)
        elif head == '-l':
            config.libraries.append(item)
        else:
            config.files.append(item)
    
    return config


def extract_config(setup, configs = None):
    if configs is None:
        configs = {}
    setup = open(setup)

    while 1:
        line = setup.readline()
        if not line:
            break
        #print line
        if rx_comment.match(line):
            #print '==>> is comment'
            continue
        if rx_macro.match(line):
            #print '==>> is macro'
            continue
        if rx_ignore.match(line):
            #print '==>> ignore'
            continue

        #print '==>> is target',
        target, args = split(line, None, 1)
        #print target
        configs[target] = read_target(args, setup)
            

    return configs

    
def print_configs(configs):
    for key, value in configs.items():
        print '********', key
        print 'file    ', value.files
        print 'inc_dirs', value.inc_dirs
        print 'macros  ', value.macros
        print 'lib_dirs', value.lib_dirs
        print 'libraries', value.libraries
    

#
# Part 2:
#
# Configure:
# Convert Sketch's Setup.config to Setup
#

def find_include_dir(dir, header):
    try:
        files = os.listdir(dir)
        if header in files:
            return dir
        else:
            for file in files:
                file = os.path.join(dir, file)
                if os.path.isdir(file):
                    result = find_include_dir(file, header)
                    if result:
                        return result
    except IOError:
        pass
    except OSError:
        pass
    return ''


rx_replace = re.compile(r'@([a-zA-Z_0-9]+):([^@]+)@')

setup_comment = '''\
# This file was generated from Setup.config by setup.py
# If you want to edit the configuration by hand, edit Setup.in and
# copy it to Setup
'''

def convert(input, output, configs, flags):
    input = open(input)
    output = open(output, 'w')
    #output = sys.stdout

    output.write(setup_comment)
    write_nl = 0
    while 1:
        line = input.readline()
        if not line:
            break
        if rx_comment.match(line):
            continue
        while 1:
            found = rx_replace.search(line)
            if found:
                config_name = found.group(1)
                if flags.has_key(config_name):
                    flag_name = found.group(2)
                    config_flags = flags[config_name]
                    if config_flags.has_key(flag_name):
                        value = config_flags[flag_name]
                    else:
                        raise ValueError, 'Unknown flag %s:%s' % (config_name,
                                                                  flag_name)
                elif configs.has_key(config_name):
                    config = configs[config_name]
                    items = split(found.group(2), ',')
                    value = []
                    for item in items:
                        if hasattr(config, item):
                            value = value + getattr(config, item)
                        else:
                            raise ValueError, \
                                  'Unknown config item %s:%s' % (config_name,
                                                                 item)
                    value = join(value)
                else:
                    raise ValueError, 'Unknown config type %s' % (config_name,)
                line = line[:found.start(0)] + value + line[found.end(0):]
            else:
                break
        if line[-2:] == '\\\n':
            line = line[:-2]
            write_nl = 1
        output.write(line)
    #print line
    if write_nl:
        output.write('\n')
    write_nl = 0

def make_boot(dir):
    # run 'make -f Makefile.pre.in boot' in dir.
    if os.system('cd %s; make -f Makefile.pre.in boot PYTHON=%s'
                 % (dir, sys.executable)):
        print "exiting because of errors"
        sys.exit(1)

def configure_tkinter(configs, flags):
    # If --tk-flags was given on the command line, use those.
    if flags['tk']['flags']:
        configs['_tkinter'] = read_target(flags['tk']['flags'], None)
        return
    # For python < 2.1 just use the tkconfig from python's Setup, unless
    # the user explicitly requests auto-configure
    if (not flags['tk']['autoconf']
        and (atoi(split(sys.version, '.', 1)[0]) < 2 \
             or sys.version_info[:2] < (2, 1))):
        if not configs.has_key('_tkinter'):
            print "Your Python installation doesn't seem to be configured" \
                  " with tkinter."
            sys.exit(1)
        return

    # We're running python 2.1 or higher or the user explicitly
    # requested auto configuratin for _tkinter. Try to figure out
    # which compiler flags to use just like python's setup.py does.
    import distutils.ccompiler
    compiler = distutils.ccompiler.new_compiler()
    configs['_tkinter'] = config = ModuleConfig()
    
    # first find the tcl/tk libraries. Assume that both the tcl and
    # tk libs have the same version and are located in the same lib
    # directory. If the user gave them on the command line, use those
    lib_dirs = ['/usr/lib', '/usr/local/lib']
    print "Looking for tcl/tk libraries under %s..." % (join(lib_dirs, ' ,'),)
    for version in ["8.3", "8.2",  "8.1",  "8.0"]:
        print "   Looking for tcl/tk %s..." % version
        tklib = compiler.find_library_file(lib_dirs, 'tk' + version )
        tcllib = compiler.find_library_file(lib_dirs, 'tcl' + version )
        if tklib and tcllib:
            print "found %s and %s" % (tklib, tcllib)
            # Exit the loop when we've found the Tcl/Tk libraries
            break
    else:
        print "Can't find suitable tcl/tk libraries"
        print "You should perhaps use the --tk-flags option"
        sys.exit(1)

    config.libraries = ['-ltk' + version, '-ltcl' + version]

    dir = "-L" + os.path.split(tklib)[0]
    config.lib_dirs.append(dir)
    dir = "-L" + os.path.split(tcllib)[0]
    if dir not in config.lib_dirs:
        config.lib_dirs.append(dir)

    # next, look for the header files
    std_inc_dirs = ["/usr/include/", "/usr/local/include"]
    inc_dirs = ["/usr/include/tk" + version] + std_inc_dirs
    print "Looking for tk header files in %s..." % (join(inc_dirs, ' ,'),)
    for dir in inc_dirs:
        dir = find_include_dir(dir, "tk.h")
        if dir:
            print "found them in %s" % dir
            config.inc_dirs.append("-I" + dir)
            break
    else:
        print "Can't find tk headerfiles"
        sys.exit(1)

    inc_dirs = ["/usr/include/tcl" + version] + std_inc_dirs
    print "Looking for tcl header files in %s..." % (join(inc_dirs, ' ,'),)
    for dir in inc_dirs:
        dir = find_include_dir(dir, "tcl.h")
        if dir:
            print "found them in %s" % dir
            if dir not in config.inc_dirs:
                config.inc_dirs.append("-I" + dir)
            break
    else:
        print "Can't find tcl headerfiles"
        sys.exit(1)

    # Finally, X compiler flags. 'Borrowed' from Python 2.1's setup.py
    platform = sys.platform
    if platform == 'sunos5':
        config.inc_dirs.append('-I/usr/openwin/include')
        config.lib_dirs.append('-L/usr/openwin/lib')
    elif os.path.exists('/usr/X11R6/include'):
        config.inc_dirs.append('-I/usr/X11R6/include')
        config.lib_dirs.append('-L/usr/X11R6/lib')
    elif os.path.exists('/usr/X11R5/include'):
        config.inc_dirs.append('-I/usr/X11R5/include')
        config.lib_dirs.append('-L/usr/X11R5/lib')
    else:
        # Assume default location for X11
        config.inc_dirs.append('-I/usr/X11/include')
        config.lib_dirs.append('-L/usr/X11/lib')

    # Finally, link with the X11 libraries
    config.libraries.append('-lX11')


def configure(dirs, flags, setup):
    if not flags['sketch'].has_key('imaging-include'):
        print 'option --imaging-include=DIR must be provided'
        sys.exit(1)
    else:
        value = flags['sketch']['imaging-include']
        value = os.path.expanduser(os.path.expandvars(value))
        value = abspath(value)
        header = 'Imaging.h'
        print 'looking for include dir for %s under %s' % (header, value)
        dir = find_include_dir(value, header)
        if not dir:
            print header, 'not found under', value, '!'
            sys.exit(1)
        print 'found it in', dir
        flags['sketch']['imaging-include'] = '-I' + dir

    if setup == None:
        configdir = os.path.join(sys.exec_prefix, 'lib',
                                 'python' + sys.version[:3], 'config')
        setup = os.path.join(configdir, 'Setup')
        setup_local = os.path.join(configdir, 'Setup.local')
    else:
        setup_local = ''
    print 'reading configuration from', setup, '...',
    configs = extract_config(setup)
    print 'done'

    if setup_local:
        print 'reading additional configuration from', setup_local, '...',
        configs = extract_config(setup_local, configs)
        print 'done'

    configure_tkinter(configs, flags)
    #if not configs.has_key('_tkinter'):
    #    print "Your Python installation doesn't seem to be configured with "\
    #          "tkinter."
    #    sys.exit(1)        

    for dir in dirs:
        file = os.path.join(dir, 'Setup.config')
        if os.path.isfile(file):
            out = os.path.splitext(file)[0]
            print 'converting', file, 'to', out, '...',
            convert(file, out, configs, flags)
            print 'done'
        make_boot(dir)

#
# Build
#

def make(dir, make_flags):
    # run 'make' in dir.
    return os.system('cd %s; make %s' % (dir, join(make_flags)))
        


def build(makedirs, make_flags):
    for dir in makedirs:
        print "running 'make' in", dir
        if make(dir, make_flags):
            print "exiting because of errors"
            sys.exit(1)


#
# Install
#

rx_replace_dir = re.compile(r'@([a-z]+)')

class InstallDirs:

    prefix = ''
    exec_prefix = ''
    executable = ''
    library = ''
    destdir = ''

    def __init__(self, flags):
        self.prefix = flags['standard']['prefix']
        self.destdir = flags['standard']['destdir']

    def fix_dirs(self, progname, version):
        # e.g. progname = 'sketch', version = '0.5.3'
        if not self.exec_prefix:
            self.exec_prefix = self.prefix
        if not self.executable:
            self.executable = os.path.join(self.exec_prefix, 'bin')
        if not self.library:
            self.library = os.path.join(self.prefix, 'lib',
                                        progname + '-' + version)

    def replace_dirs(self, string):
        result = ''
        match = 1
        while match:
            match = rx_replace_dir.search(string)
            if match is not None:
                start, end = match.span(0)
                dir = getattr(self, match.group(1))
                result = result + string[:start] + dir
                string = string[end:]
            else:
                result = result + string
        return result

    def prepend_destdir(self, dir):
        # this may return a filename with multiple consecutive slashes
        # but that shouldn't be problem on Linux.
        if self.destdir:
            return self.destdir + '/' + dir
        return dir


# return the longest common prefix of path1 and path2 that is a
# directory.
def commonbasedir(path1, path2):
    if path1[-1] != os.sep:
	path1 = path1 + os.sep
    return os.path.split(os.path.commonprefix([path1, path2]))[0]



# return the absolute path PATH2 as a path relative to the directory
# PATH1. If commonbasedir(PATH1, PATH2) is '/', return PATH2. Doesn't
# take symbolic links into account...
def relpath(path1, path2):
    #if not os.path.isabs(path2):
    #	return path2
    basedir = commonbasedir(path1, path2)
    if basedir == os.sep:
	return path2
    path2 = path2[len(basedir) + 1 : ]
    curbase = path1
    while curbase != basedir:
	curbase = os.path.split(curbase)[0]
	path2 = os.pardir + os.sep + path2
    return path2

def create_directory(dir):
    if os.path.isdir(dir):
	return
    parent, base = os.path.split(dir)
    if parent:
        create_directory(parent)
    try:
        os.mkdir(dir, 0777)
    except os.error, exc:
        print "can't create directory %s:%s" % (dir, exc)

    
def link_file(source, dest):
    if os.path.isfile(dest) or os.path.islink(dest):
        # XXX should we really remove this
        try:
            os.unlink(dest)
        except os.error, exc:
            print "can't create remove %s:%s" % (dest, exc)
    try:
        os.symlink(source, dest)
    except os.error, exc:
        print "can't create symbolic link %s in %s:%s" % (source, dest, exc)

def install_file(srcfile, dest, flags, dirs, verbose = 1, noop = 0):
    # srcfile must be a relative pathname, dest a directory
    srcdir, basename = os.path.split(srcfile)
    if 'recursive' in flags and not os.path.isabs(srcdir):
        destdir = os.path.join(dest, srcdir)
    else:
        destdir = os.path.normpath(dest)
    if not noop:
        create_directory(destdir)
    if 'link' in flags:
        # symlink
        # XXX should the link be relative if the directories have a
        # common prefix?
        if basename[-3:] == '.py':
            # XXX hack
            basename = basename[:-3]
        destfile = os.path.join(destdir, basename)
        if 'relative' in flags:
            # make srcfile a filename relative to destdir. Strip the
            # value of --dest-dir.
            d = destdir
            if dirs.destdir:
                normalized = os.path.normpath(dirs.destdir)
                length = len(normalized)
                if normalized == destdir[:length]:
                    d = destdir[length:]
                    if d[0] != '/':
                        d = '/' + d
            srcfile = relpath(d, srcfile)
        if verbose:
            print 'create symlink %s in %s' % (srcfile, destfile)
        if not noop:
            link_file(srcfile, destfile)
    else:
        # copy file
        destfile = os.path.join(destdir, basename)
        if verbose:
            print 'copying %s to %s' % (srcfile, destfile)
        if not noop:
            # only copy regular files and remove the destination file if
            # it already exists.
            if os.path.isfile(srcfile):
                try:
                    os.unlink(destfile)
                except:
                    pass
                shutil.copy(srcfile, destfile)
        
def bytecompile(dir):
    compileall.compile_dir(os.path.join(os.getcwd(), dir))

def install(config, dirs):
    # 
    # config is a list of tuples. Each tuple is of the form
    # (PATTERN, DEST)  or  (PATTERN, DEST, FLAGS)
    #
    for item in config:
        if len(item) == 2:
            pattern, dest = item
            flags = ()
        else:
            pattern, dest, flags = item
            if type(flags) == type(''):
                flags = (flags,)
        pattern = dirs.replace_dirs(pattern)
        dest = dirs.prepend_destdir(dirs.replace_dirs(dest))
        files = glob.glob(pattern)
        #print pattern, dest, files
        if not files and 'link' in flags:
            # hack for symlinks. The source may not exist during tests
            files = (pattern,)
        
        for file in files:
            install_file(file, dest, flags, dirs)
            #print 'install', file, 'in', dest
#
# Part 3:
#
# Drivers
#

def get_version():
    version = strip(open('Sketch/VERSION').read())
    return version

def parse_cmd_line():
    setup = None
    argv = sys.argv[1:]
    flags = {}
    flags['standard'] = {'prefix': '/usr/local/', 'destdir':''}
    flags['pax'] = {'XSHM': ''}
    flags['intl'] = {'files': ''}
    flags['sketch'] = {'imaging-include':
                       os.path.join(sys.prefix, 'include',
                                    'python' + sys.version[:3])}
    flags['tk'] = {'autoconf': 0, 'flags': ''}
    flags['make_defs'] = []
    if len(argv) == 0:
        command = 'help'
    else:
        command = argv[0]
        if command in ('-h', '--help'):
            command = 'help'
        del argv[0]
    for arg in argv:
        if '=' in arg:
            arg, value = split(arg, '=')
        else:
            value = None
        if arg == '--prefix':
            if value is None:
                print 'Value required for option --prefix'
                sys.exit(1)
            flags['standard']['prefix'] = value
        elif arg == '--dest-dir':
            flags['standard']['destdir'] = value
        elif arg == '--python-setup':
            setup = value
        elif arg == '--pax-no-xshm':
            flags['pax']['XSHM'] = '-DPAX_NO_XSHM'
        elif arg == '--imaging-include':
            if value is None:
                print 'Value required for option --imaging-include'
                sys.exit(1)
            flags['sketch']['imaging-include'] = value
        elif arg == '--with-nls':
            flags['intl']['files'] = 'intl intl.c'
        elif arg == '--tk-flags':
            flags['tk']['flags'] = value
        elif arg == '--tk-autoconf':
            flags['tk']['autoconf'] = 1
        elif arg in ('-h', '--help'):
            command = 'help'
        elif arg[0] != '-' and value:
            flags['make_defs'].append(pipes.quote(arg + '=' + value))
        else:
            sys.stderr.write('Unknown option %s\n' % arg)
            sys.exit(1)
    return command, flags, setup

def print_help():
    setup = os.path.join(sys.prefix, 'lib/python' + sys.version[:3],
                         'config/Setup')
    print help_message % {'version': get_version(), 
                          'pyprefix': sys.prefix,
                          'pyversion': sys.version[:3],
                          'pysetup': setup}

help_message = """\
Usage: setup.py COMMAND [options...]

setup.py configures, builds and installs Sketch. COMMAND is one of:

        configure         configure Sketch
        build             compile the C extension modules
        install           install Sketch on your system

Generic options:
  -h, --help              print this help message
Options for configure:
  --imaging-include=DIR   Look (recursively) under DIR for the header files
                          of PIL (Python Imaging Library)
                          [%(pyprefix)s/include/python%(pyversion)s]
  --pax-no-xshm           Compile Pax (a module for direct access to Xlib)
                          without support for the X Shared Memory extension.
  --with-nls              Enable national language support for messages, menus,
                          etc. You need the gettext library for this.
  --python-setup=FILE     The python Setup file to parse.
                          [%(pysetup)s]
  --tk-flags=flags        Compiler flags to use for building the tk-modules
  --tk-autoconf           Determine the compiler flags for Sketch's tk-modules
                          without referring to Python's Setup file. When run
                          under Python 2.1 this will always be done.
Options for build:
  <VAR>=<VALUE>           Options like this are passed through to make
                          to let you override variables like CC or OPT.
                          See the generated Makefiles for more details.
Options for install:
  --prefix=PREFIX         Install files in PREFIX/lib/sketch-%(version)s/ and
                          PREFIX/bin [/usr/local]
  --dest-dir=DIR          If given, install the files under DIR, but pretend
                          that the files are really under the prefix directory.
"""

    
make_dirs = ('Pax', 'Filter', 'Sketch/Modules')

lib = '@library'
bin = '@executable'
install_config = \
[
    ('sketch.py', lib, 'executable'),
    ('sk2ps.py', lib, 'executable'),
    ('sk2ppm.py', lib, 'executable'),
    ('skconvert.py', lib, 'executable'),
    ('skshow.py', lib, 'executable'),
    ('Plugins/*/*.py', lib, 'recursive'),
    ('Plugins/*/*/*.py', lib, 'recursive'),
    ('Plugins/*/*/*/*.py', lib, 'recursive'),
    ('Sketch/*.py', lib, 'recursive'),
    ('Sketch/VERSION', lib, 'recursive'),
    ('Sketch/*/*.py', lib, 'recursive'),
    ('Sketch/*/*.so', lib, 'recursive'),
    ('Sketch/*/*.xbm', lib, 'recursive'),
    ('Sketch/*/*/*.xbm', lib, 'recursive'),
    ('Sketch/*/*.gif', lib, 'recursive'),
    ('Script/*.py', lib, 'recursive'),
    ('Resources/Fontmetrics/*', lib, 'recursive'),
    ('Resources/Misc/*', lib, 'recursive'),
    ('Pax/*.so', os.path.join(lib, 'Lib')),
    ('Pax/*.py', os.path.join(lib, 'Lib')),
    ('Filter/*.so', os.path.join(lib, 'Lib')),
    (os.path.join(lib, 'sketch.py'), bin, ('link', 'relative')),
    (os.path.join(lib, 'sk2ps.py'), bin, ('link', 'relative')),
    (os.path.join(lib, 'sk2ppm.py'), bin, ('link', 'relative')),
    (os.path.join(lib, 'skconvert.py'), bin, ('link', 'relative')),
    (os.path.join(lib, 'skshow.py'), bin, ('link', 'relative')),
]
progname = 'sketch'
version = None

def intl_available():
    sys.path.insert(0, os.path.join(sys.path[0], 'Pax'))
    try:
        import intl
        #print 'intl available'
        return 1
    except:
        #print 'intl not available'
        return 0

def main():
    global version
    version = get_version()
    command, flags, setup = parse_cmd_line()
    if command == 'help':
        print_help()
    elif command == 'configure':
        configure(make_dirs, flags, setup)
    elif command == 'build':
        build(make_dirs, flags['make_defs'])
    elif command == 'install':
        dirs = InstallDirs(flags)
        dirs.fix_dirs(progname = progname, version = version)
        install(install_config, dirs)
        if intl_available():
            install([('Resources/Messages/*/*/*.mo', lib, 'recursive')], dirs)
        for dir in ('Sketch', 'Plugins', 'Lib', 'Script'):
            dir = dirs.prepend_destdir(os.path.join(dirs.library, dir))
            #bytecompile(dir)
    else:
        print 'unknown command', command
        print_help()



if __name__ == '__main__':
    main()