|
| 1 | +# |
| 2 | +# |
| 3 | + |
| 4 | +from SCons.Environment import Environment |
| 5 | +from os.path import join as pjoin |
| 6 | +import re |
| 7 | +import os |
| 8 | + |
| 9 | + |
| 10 | +_platforms = [ 'aix', 'beos', 'netware', 'os2', 'os390', 'unix', 'win32' ] |
| 11 | + |
| 12 | +_platform_dirs = ['atomic', |
| 13 | + 'dso', |
| 14 | + 'file_io', |
| 15 | + 'helpers', |
| 16 | + 'locks', |
| 17 | + 'memory', |
| 18 | + 'misc', |
| 19 | + 'mmap', |
| 20 | + 'network_io', |
| 21 | + 'passwd', |
| 22 | + 'poll', |
| 23 | + 'random', |
| 24 | + 'shmem', |
| 25 | + 'strings', |
| 26 | + 'support', |
| 27 | + 'tables', |
| 28 | + 'threadproc', |
| 29 | + 'time', |
| 30 | + 'user'] |
| 31 | + |
| 32 | +_simple_dirs = ['tables', 'strings'] |
| 33 | + |
| 34 | +class APREnv(Environment): |
| 35 | + def __init__(self, parent=None, args=None, **kw): |
| 36 | + Environment.__init__(self, ENV=os.environ, **kw) |
| 37 | + |
| 38 | + # See SCons/Platform/__init__.py for possible values |
| 39 | + if self['PLATFORM'] in _platforms: |
| 40 | + self['APR_PLATFORM'] = self['PLATFORM'] |
| 41 | + else: |
| 42 | + self['APR_PLATFORM'] = 'unix' |
| 43 | + |
| 44 | + # if no *.c files are found in the original APR_PLATFORM, we switch to |
| 45 | + # using this fallback platform. |
| 46 | + self['APR_FALLBACK_PLATFORM'] = 'unix' |
| 47 | + |
| 48 | + self.AppendUnique(CPPPATH = ['include', 'include/arch/'+self['APR_PLATFORM']]) |
| 49 | + |
| 50 | + def is_gcc(self): |
| 51 | + # TOOD: This detection should be smarter, need look at SCons Internals |
| 52 | + # for how it works/base it on the Tool selection. |
| 53 | + return self['CC'] == 'gcc' |
| 54 | + |
| 55 | + def core_lib_files(self): |
| 56 | + rv = [] |
| 57 | + for d in _platform_dirs: |
| 58 | + p = pjoin(d, self['APR_PLATFORM'], '*.c') |
| 59 | + files = self.Glob(p) |
| 60 | + if not files and self['APR_PLATFORM'] != self['APR_FALLBACK_PLATFORM']: |
| 61 | + p = pjoin(d, self['APR_FALLBACK_PLATFORM'], '*.c') |
| 62 | + files = self.Glob(p) |
| 63 | + rv.extend(files) |
| 64 | + |
| 65 | + for d in _simple_dirs: |
| 66 | + p = pjoin(d, '*.c') |
| 67 | + files = self.Glob(p) |
| 68 | + rv.extend(files) |
| 69 | + return rv |
| 70 | + |
| 71 | + def APRVersion(self): |
| 72 | + if not self.has_key('APR_VERSION'): |
| 73 | + self['APR_VERSION'] = self.read_version('APR', 'include/apr_version.h') |
| 74 | + return self['APR_VERSION'] |
| 75 | + |
| 76 | + def read_version(self, prefix, path): |
| 77 | + version_re = re.compile("(.*)%s_(?P<id>MAJOR|MINOR|PATCH)_VERSION(\s+)(?P<num>\d)(.*)" % prefix) |
| 78 | + versions = {} |
| 79 | + fp = open(path, 'rb') |
| 80 | + for line in fp.readlines(): |
| 81 | + m = version_re.match(line) |
| 82 | + if m: |
| 83 | + versions[m.group('id')] = int(m.group('num')) |
| 84 | + fp.close() |
| 85 | + return (versions['MAJOR'], versions['MINOR'], versions['PATCH']) |
| 86 | + |
| 87 | + def Filter(self, **kw): |
| 88 | + for k in kw.keys(): |
| 89 | + self[k] = [x for x in self[k] if x is not kw[k]] |
| 90 | + |
| 91 | + def APRHints(self): |
| 92 | + # TOOD: port more from apr_hints.m4 |
| 93 | + if self['PLATFORM'] == 'darwin': |
| 94 | + self.AppendUnique(CPPFLAGS=['-DDARWIN', '-DSIGPROCMASK_SETS_THREAD_MASK', '-no-cpp-precomp']) |
| 95 | + |
| 96 | + def APRAutoconf(self): |
| 97 | + if self.GetOption('clean'): |
| 98 | + return |
| 99 | + |
| 100 | + # TODO Port header detection here etc |
| 101 | + conf = self.Configure() |
| 102 | + conf.Finish() |
| 103 | + |
0 commit comments