Branch oldpackages for 14.07
[14.07/packages.git] / lang / pypcap / patches / 000-no_cpickle.patch
1 --- pypcap/setup.py     2006-03-15 13:59:54.000000000 -0600
2 +++ pypcap.new/setup.py 2007-05-25 17:29:02.413355500 -0500
3 @@ -4,69 +4,53 @@
4  
5  from distutils.core import setup, Extension
6  from distutils.command import config, clean
7 -import cPickle, glob, os, sys
8 +import os,sys,glob
9  
10 -pcap_config = {}
11 -pcap_cache = 'config.pkl'
12 +# where to find pcap
13 +pcap_location = os.environ.get('PCAP_HOME')
14  
15 -class config_pcap(config.config):
16 -    description = 'configure pcap paths'
17 -    user_options = [ ('with-pcap=', None,
18 -                      'path to pcap build or installation directory') ]
19 -    
20 -    def initialize_options(self):
21 -        config.config.initialize_options(self)
22 -        self.dump_source = 0
23 -        #self.noisy = 0
24 -        self.with_pcap = None
25 -
26 -    def _write_config_h(self, cfg):
27 -        # XXX - write out config.h for pcap_ex.c
28 -        d = {}
29 -        if os.path.exists(os.path.join(cfg['include_dirs'][0], 'pcap-int.h')):
30 -            d['HAVE_PCAP_INT_H'] = 1
31 -        buf = open(os.path.join(cfg['include_dirs'][0], 'pcap.h')).read()
32 -        if buf.find('pcap_file(') != -1:
33 -            d['HAVE_PCAP_FILE'] = 1
34 -        if buf.find('pcap_compile_nopcap(') != -1:
35 -            d['HAVE_PCAP_COMPILE_NOPCAP'] = 1
36 -        if buf.find('pcap_setnonblock(') != -1:
37 -            d['HAVE_PCAP_SETNONBLOCK'] = 1
38 -        f = open('config.h', 'w')
39 -        for k, v in d.iteritems():
40 -            f.write('#define %s %s\n' % (k, v))
41 -    
42 -    def _pcap_config(self, dirs=[ None ]):
43 -        cfg = {}
44 -        if not dirs[0]:
45 -            dirs = [ '/usr', sys.prefix ] + glob.glob('/opt/libpcap*') + \
46 -                   glob.glob('../libpcap*') + glob.glob('../wpdpack*')
47 -        for d in dirs:
48 -            for sd in ('include', 'include/pcap', ''):
49 -                incdirs = [ os.path.join(d, sd) ]
50 -                if os.path.exists(os.path.join(d, sd, 'pcap.h')):
51 -                    cfg['include_dirs'] = [ os.path.join(d, sd) ]
52 -                    for sd in ('lib', ''):
53 -                        for lib in (('pcap', 'libpcap.a'),
54 -                                    ('pcap', 'libpcap.dylib'),
55 -                                    ('wpcap', 'wpcap.lib')):
56 -                            if os.path.exists(os.path.join(d, sd, lib[1])):
57 -                                cfg['library_dirs'] = [ os.path.join(d, sd) ]
58 -                                cfg['libraries'] = [ lib[0] ]
59 -                                if lib[0] == 'wpcap':
60 -                                    cfg['libraries'].append('iphlpapi')
61 -                                    cfg['extra_compile_args'] = \
62 -                                        [ '-DWIN32', '-DWPCAP' ]
63 -                                print 'found', cfg
64 -                                self._write_config_h(cfg)
65 -                                return cfg
66 -        raise "couldn't find pcap build or installation directory"
67 -    
68 -    def run(self):
69 -        #config.log.set_verbosity(0)
70 -        cPickle.dump(self._pcap_config([ self.with_pcap ]),
71 -                     open(pcap_cache, 'wb'))
72 -        self.temp_files.append(pcap_cache)
73 +def write_config_h(cfg):
74 +    # XXX - write out config.h for pcap_ex.c
75 +    d = {}
76 +    if os.path.exists(os.path.join(cfg['include_dirs'][0], 'pcap-int.h')):
77 +        d['HAVE_PCAP_INT_H'] = 1
78 +    buf = open(os.path.join(cfg['include_dirs'][0], 'pcap.h')).read()
79 +    if buf.find('pcap_file(') != -1:
80 +        d['HAVE_PCAP_FILE'] = 1
81 +    if buf.find('pcap_compile_nopcap(') != -1:
82 +        d['HAVE_PCAP_COMPILE_NOPCAP'] = 1
83 +    if buf.find('pcap_setnonblock(') != -1:
84 +        d['HAVE_PCAP_SETNONBLOCK'] = 1
85 +    f = open('config.h', 'w')
86 +    for k, v in d.iteritems():
87 +        f.write('#define %s %s\n' % (k, v))
88 +
89 +
90 +def f_pcap_config(dirs=[ None ]):
91 +    cfg = {}
92 +    if not dirs[0]:
93 +        dirs = [ '/usr', sys.prefix ] + glob.glob('/opt/libpcap*') + \
94 +               glob.glob('../libpcap*') + glob.glob('../wpdpack*')
95 +    for d in dirs:
96 +        for sd in ('include/pcap', 'include', ''):
97 +            incdirs = [ os.path.join(d, sd) ]
98 +            if os.path.exists(os.path.join(d, sd, 'pcap.h')):
99 +                cfg['include_dirs'] = [ os.path.join(d, sd) ]
100 +                for sd in ('lib', ''):
101 +                    for lib in (('pcap', 'libpcap.a'),
102 +                                ('pcap', 'libpcap.dylib'),
103 +                                ('wpcap', 'wpcap.lib')):
104 +                        if os.path.exists(os.path.join(d, sd, lib[1])):
105 +                            cfg['library_dirs'] = [ os.path.join(d, sd) ]
106 +                            cfg['libraries'] = [ lib[0] ]
107 +                            if lib[0] == 'wpcap':
108 +                                cfg['libraries'].append('iphlpapi')
109 +                                cfg['extra_compile_args'] = \
110 +                                    [ '-DWIN32', '-DWPCAP' ]
111 +                            print 'found', cfg
112 +                            write_config_h(cfg)
113 +                            return cfg
114 +    raise "couldn't find pcap build or installation directory"
115  
116  class clean_pcap(clean.clean):
117      def run(self):
118 @@ -75,13 +59,9 @@
119              print "removing '%s'" % pcap_cache
120              os.unlink(pcap_cache)
121  
122 -if len(sys.argv) > 1 and sys.argv[1] == 'build':
123 -    try:
124 -        pcap_config = cPickle.load(open(pcap_cache))
125 -    except IOError:
126 -        print >>sys.stderr, 'run "%s config" first!' % sys.argv[0]
127 -        sys.exit(1)
128  
129 +
130 +pcap_config = f_pcap_config([pcap_location])
131  pcap = Extension(name='pcap',
132                   sources=[ 'pcap.c', 'pcap_ex.c' ],
133                   include_dirs=pcap_config.get('include_dirs', ''),
134 @@ -89,7 +69,7 @@
135                   libraries=pcap_config.get('libraries', ''),
136                   extra_compile_args=pcap_config.get('extra_compile_args', ''))
137  
138 -pcap_cmds = { 'config':config_pcap, 'clean':clean_pcap }
139 +pcap_cmds = { 'clean':clean_pcap }
140  
141  setup(name='pcap',
142        version='1.1',