Skip to content

Commit da3c07c

Browse files
committed
A very basic scons based build that barely works on Darwin.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@731120 13f79535-47bb-0310-9956-ffa450edef68
1 parent 55d35b9 commit da3c07c

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

SConstruct

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env scons
2+
#
3+
4+
from build import APREnv
5+
6+
EnsureSConsVersion(1, 1, 0)
7+
8+
vars = Variables('build.py')
9+
10+
vars.Add('maintainer_mode', 'Turn on debugging and compile time warnings', 0)
11+
vars.Add('profile', 'Turn on profiling for the build (GCC)', 0)
12+
vars.Add(EnumVariable('pool_debug', 'Turn on pools debugging', 'no',
13+
allowed_values=('yes', 'no', 'verbose', 'verbose-alloc', 'lifetime', 'owner', 'all')))
14+
15+
env = APREnv(args=ARGUMENTS, variables=vars)
16+
17+
Help(vars.GenerateHelpText(env))
18+
19+
env.APRHints()
20+
21+
env.APRAutoconf()
22+
23+
if env['maintainer_mode']:
24+
if env.is_gcc():
25+
env.AppendUnique(CPPFLAGS = ['-g', '-Wall', '-Wmissing-prototypes', '-Wstrict-prototypes', '-Wmissing-declarations'])
26+
27+
if env['profile']:
28+
env.Filter(CPPFLAGS = '-g')
29+
env.AppendUnique(CPPFLAGS = ['-pg'])
30+
31+
if env['pool_debug'] != 'no':
32+
flags = {'yes': 1,
33+
'verbose': 2,
34+
'lifetime': 4,
35+
'owner': 8,
36+
'verbose-alloc': 16,
37+
'all': 31}
38+
env.AppendUnique(CPPFLAGS = "-DAPR_POOL_DEBUG=%d" % flags[env['pool_debug']])
39+
40+
files = env.core_lib_files()
41+
42+
(major, minor, patch) = env.APRVersion()
43+
44+
libapr = env.SharedLibrary('apr-%d' % (major), files)
45+
46+
targets = [libapr]
47+
48+
env.Default(targets)

build/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from aprenv import *

build/aprenv.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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

Comments
 (0)