You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by pq...@apache.org on 2009/01/04 02:46:00 UTC
svn commit: r731155 - in /apr/apr/trunk: SConstruct build/aprenv.py
build/subst.py
Author: pquerna
Date: Sat Jan 3 17:46:00 2009
New Revision: 731155
URL: http://svn.apache.org/viewvc?rev=731155&view=rev
Log:
More SCons:
- Generate include/apr.h
- 64bit type detection
- Test for many standard headers
- Start Large file tests
Added:
apr/apr/trunk/build/subst.py (with props)
Modified:
apr/apr/trunk/SConstruct
apr/apr/trunk/build/aprenv.py
Modified: apr/apr/trunk/SConstruct
URL: http://svn.apache.org/viewvc/apr/apr/trunk/SConstruct?rev=731155&r1=731154&r2=731155&view=diff
==============================================================================
--- apr/apr/trunk/SConstruct (original)
+++ apr/apr/trunk/SConstruct Sat Jan 3 17:46:00 2009
@@ -9,6 +9,7 @@
vars.Add('maintainer_mode', 'Turn on debugging and compile time warnings', 0)
vars.Add('profile', 'Turn on profiling for the build (GCC)', 0)
+vars.Add('lfs', 'Large file support on 32-bit platforms', 1)
vars.Add(EnumVariable('pool_debug', 'Turn on pools debugging', 'no',
allowed_values=('yes', 'no', 'verbose', 'verbose-alloc', 'lifetime', 'owner', 'all')))
Modified: apr/apr/trunk/build/aprenv.py
URL: http://svn.apache.org/viewvc/apr/apr/trunk/build/aprenv.py?rev=731155&r1=731154&r2=731155&view=diff
==============================================================================
--- apr/apr/trunk/build/aprenv.py (original)
+++ apr/apr/trunk/build/aprenv.py Sat Jan 3 17:46:00 2009
@@ -33,7 +33,10 @@
class APREnv(Environment):
def __init__(self, parent=None, args=None, **kw):
- Environment.__init__(self, ENV=os.environ, **kw)
+ Environment.__init__(self, ENV=os.environ,
+ tools = ['default', 'subst'],
+ toolpath = [pjoin(os.getcwd(), 'build')],
+ **kw)
# See SCons/Platform/__init__.py for possible values
if self['PLATFORM'] in _platforms:
@@ -95,7 +98,7 @@
def Check_apr_atomic_builtins(self, context):
- context.Message('Checking whether the compiler provides atomic builtins...')
+ context.Message('Checking whether the compiler provides atomic builtins... ')
source = """
int main()
{
@@ -133,10 +136,62 @@
return 0;
}
"""
- result = context.TryLink(source, '.c')
- context.Result(result)
- return result
-
+ result = context.TryRun(source, '.c')
+ context.Result(result[0])
+ return result[0]
+
+ def Check_apr_largefile64(self, context):
+ context.Message('Checking whether to enable -D_LARGEFILE64_SOURCE... ')
+ self.AppendUnique(CPPFLAGS = '-D_LARGEFILE64_SOURCE')
+ source = """
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+void main(void)
+{
+ int fd, ret = 0;
+ struct stat64 st;
+ off64_t off = 4242;
+
+ if (sizeof(off64_t) != 8 || sizeof(off_t) != 4)
+ exit(1);
+ if ((fd = open("conftest.lfs", O_LARGEFILE|O_CREAT|O_WRONLY, 0644)) < 0)
+ exit(2);
+ if (ftruncate64(fd, off) != 0)
+ ret = 3;
+ else if (fstat64(fd, &st) != 0 || st.st_size != off)
+ ret = 4;
+ else if (lseek64(fd, off, SEEK_SET) != off)
+ ret = 5;
+ else if (close(fd) != 0)
+ ret = 6;
+ else if (lstat64("conftest.lfs", &st) != 0 || st.st_size != off)
+ ret = 7;
+ else if (stat64("conftest.lfs", &st) != 0 || st.st_size != off)
+ ret = 8;
+ unlink("conftest.lfs");
+
+ exit(ret);
+}
+ """
+ result = context.TryRun(source, '.c')
+ self.Filter(CPPFLAGS = '-D_LARGEFILE64_SOURCE')
+ context.Result(result[0])
+ return result[0]
+
+ def critical_value(self, f, value, *args):
+ rv = f(*args)
+
+ if rv != value:
+ traceback.print_stack()
+ print "Critial Test failed."
+ self.Exit(1)
+ return rv
+
def critical(self, f, *args):
rv = f(*args)
@@ -146,14 +201,201 @@
self.Exit(1)
def APRAutoconf(self):
+ subst = {}
+
if self.GetOption('clean') or self.GetOption('help'):
return self
-
# TODO Port header detection here etc
- conf = self.Configure(custom_tests = {'Check_apr_atomic_builtins': self.Check_apr_atomic_builtins},
+ conf = self.Configure(custom_tests = {
+ 'Check_apr_atomic_builtins': self.Check_apr_atomic_builtins,
+ 'Check_apr_largefile64': self.Check_apr_largefile64,
+ },
config_h = 'include/arch/%s/apr_private.h' % (self['APR_PLATFORM']))
+ # Do we have a working C Compiler?
+ self.critical(conf.CheckCC)
+ flag_headers = self.Split("""ByteOrder.h
+ conio.h
+ crypt.h
+ ctype.h
+ dir.h
+ dirent.h
+ dl.h
+ dlfcn.h
+ errno.h
+ fcntl.h
+ grp.h
+ io.h
+ limits.h
+ mach-o/dyld.h
+ malloc.h
+ memory.h
+ netdb.h
+ osreldate.h
+ poll.h
+ process.h
+ pwd.h
+ semaphore.h
+ signal.h
+ stdarg.h
+ stddef.h
+ stdio.h
+ stdlib.h
+ string.h
+ strings.h
+ sysapi.h
+ sysgtime.h
+ termios.h
+ time.h
+ tpfeq.h
+ tpfio.h
+ unistd.h
+ unix.h
+ windows.h
+ winsock2.h
+ arpa/inet.h
+ kernel/OS.h
+ net/errno.h
+ netinet/in.h
+ netinet/sctp.h
+ netinet/tcp.h
+ netinet/sctp_uio.h
+ sys/file.h
+ sys/ioctl.h
+ sys/mman.h
+ sys/param.h
+ sys/poll.h
+ sys/resource.h
+ sys/select.h
+ sys/sem.h
+ sys/sendfile.h
+ sys/signal.h
+ sys/socket.h
+ sys/sockio.h
+ sys/stat.h
+ sys/sysctl.h
+ sys/syslimits.h
+ sys/time.h
+ sys/types.h
+ sys/uio.h
+ sys/un.h
+ sys/wait.h
+ pthread.h
+ """)
+ for x in flag_headers:
+ s = x.replace('/', '_').replace('.', '').replace('-', '')
+ if conf.CheckCHeader(x):
+ subst['@%s@' % (s)] = 1
+ else:
+ subst['@%s@' % (s)] = 0
+
+
+ sizeof_char = conf.CheckTypeSize('char')
+ sizeof_int = conf.CheckTypeSize('int')
+ sizeof_long = conf.CheckTypeSize('long')
+ sizeof_short = self.critical_value(conf.CheckTypeSize, 2, 'short')
+ sizeof_long_long = conf.CheckTypeSize('long long')
+ sizeof_longlong = conf.CheckTypeSize('longlong')
+ sizeof_pid_t = conf.CheckTypeSize('pid_t', includes='#include <sys/types.h>')
+ sizeof_off_t = conf.CheckTypeSize('off_t', includes='#include <sys/types.h>')
+ sizeof_size_t = conf.CheckTypeSize('size_t')
+
+ # Now we need to find what apr_int64_t (sizeof == 8) will be.
+ # The first match is our preference.
+ if sizeof_int == 8:
+ subst['@int64_literal@'] = '#define APR_INT64_C(val) (val)'
+ subst['@uint64_literal@'] = '#define APR_UINT64_C(val) (val##U)'
+ subst['@int64_t_fmt@'] = '#define APR_INT64_T_FMT "d"'
+ subst['@uint64_t_fmt@'] = '#define APR_UINT64_T_FMT "u"'
+ subst['@uint64_t_hex_fmt@'] = '#define APR_UINT64_T_HEX_FMT "x"'
+ subst['@int64_value@'] = 'int'
+ subst['@long_value@'] = 'int'
+ subst['@int64_strfn=@'] = 'strtoi'
+ elif sizeof_long == 8:
+ subst['@int64_literal@'] = '#define APR_INT64_C(val) (val##L)'
+ subst['@uint64_literal@'] = '#define APR_UINT64_C(val) (val##UL)'
+ subst['@int64_t_fmt@'] = '#define APR_INT64_T_FMT "ld"'
+ subst['@uint64_t_fmt@'] = '#define APR_UINT64_T_FMT "lu"'
+ subst['@uint64_t_hex_fmt@'] = '#define APR_UINT64_T_HEX_FMT "lx"'
+ subst['@int64_value@'] = 'long'
+ subst['@long_value@'] = 'long'
+ subst['@int64_strfn=@'] = 'strtol'
+ elif sizeof_long_long == 8:
+ subst['@int64_literal@'] = '#define APR_INT64_C(val) (val##LL)'
+ subst['@uint64_literal@'] = '#define APR_UINT64_C(val) (val##ULL)'
+ # Linux, Solaris, FreeBSD all support ll with printf.
+ # BSD 4.4 originated 'q'. Solaris is more popular and
+ # doesn't support 'q'. Solaris wins. Exceptions can
+ # go to the OS-dependent section.
+ subst['@int64_t_fmt@'] = '#define APR_INT64_T_FMT "lld"'
+ subst['@uint64_t_fmt@'] = '#define APR_UINT64_T_FMT "llu"'
+ subst['@uint64_t_hex_fmt@'] = '#define APR_UINT64_T_HEX_FMT "llx"'
+ subst['@int64_value@'] = 'long long'
+ subst['@long_value@'] = 'long long'
+ subst['@int64_strfn=@'] = 'strtoll'
+ elif sizeof_longlong == 8:
+ subst['@int64_literal@'] = '#define APR_INT64_C(val) (val##LL)'
+ subst['@uint64_literal@'] = '#define APR_UINT64_C(val) (val##ULL)'
+ subst['@int64_t_fmt@'] = '#define APR_INT64_T_FMT "qd"'
+ subst['@uint64_t_fmt@'] = '#define APR_UINT64_T_FMT "qu"'
+ subst['@uint64_t_hex_fmt@'] = '#define APR_UINT64_T_HEX_FMT "qx"'
+ subst['@int64_value@'] = '__int64'
+ subst['@long_value@'] = '__int64'
+ subst['@int64_strfn=@'] = 'strtoll'
+ else:
+ print("could not detect a 64-bit integer type")
+ self.Exit(1)
+
+ if conf.CheckDeclaration('INT64_C', includes='#include <stdint.h>'):
+ subst['@int64_literal@'] = '#define APR_INT64_C(val) INT64_C(val)'
+ subst['@uint64_literal@'] = '#define APR_UINT64_C(val) UINT64_C(val)'
+ subst['@stdint@'] = 1
+
+ if sizeof_pid_t == sizeof_short:
+ subst['@pid_t_fmt@'] = '#define APR_PID_T_FMT "hd"'
+ elif sizeof_pid_t == sizeof_int:
+ subst['@pid_t_fmt@'] = '#define APR_PID_T_FMT "d"'
+ elif sizeof_pid_t == sizeof_long:
+ subst['@pid_t_fmt@'] = '#define APR_PID_T_FMT "ld"'
+ elif sizeof_pid_t == sizeof_long_long:
+ subst['@pid_t_fmt@'] = '#define APR_PID_T_FMT APR_INT64_T_FMT'
+ else:
+ subst['@pid_t_fmt@'] = '#error Can not determine the proper size for pid_t'
+
+ # TODO: Per OS changing of these
+
+ if conf.Check_apr_largefile64():
+ self.AppendUnique(CPPFLAGS = '-D_LARGEFILE64_SOURCE')
+
+ aprlfs=0
+ if self['lfs'] and sizeof_off_t == 4:
+ # Check whether the transitional LFS API is sufficient
+ aprlfs=1
+ for f in ['mmap64', 'sendfile64', 'sendfilev64', 'mkstemp64', 'readdir64_r']:
+ conf.CheckFunc(f)
+ elif sizeof_off_t == sizeof_size_t:
+ aprlfs=1
+
if conf.Check_apr_atomic_builtins():
conf.Define('HAVE_ATOMIC_BUILTINS', 1)
+ if not conf.CheckType('size_t', includes='#include <sys/types.h>'):
+ subst['@size_t_value@'] = 'apr_int32_t'
+
+ if not conf.CheckType('ssize_t', includes='#include <sys/types.h>'):
+ subst['@ssize_t_value@'] = 'apr_int32_t'
+
+ if not conf.CheckType('socklen_t', includes='#include <sys/socket.h>'):
+ subst['@socklen_t_value@'] = 'int'
+ else:
+ if self['PLATFORM'] == 'hpux' and sizeof_long == 8:
+ # 64-bit HP-UX requires 32-bit socklens in
+ # kernel, but user-space declarations say
+ # 64-bit (socklen_t == size_t == long).
+ # This will result in many compile warnings,
+ # but we're functionally busted otherwise.
+ subst['@socklen_t_value@'] = 'int'
+
+ self.SubstFile('include/apr.h', 'include/apr.h.in', SUBST_DICT = subst)
+
return conf.Finish()
Added: apr/apr/trunk/build/subst.py
URL: http://svn.apache.org/viewvc/apr/apr/trunk/build/subst.py?rev=731155&view=auto
==============================================================================
--- apr/apr/trunk/build/subst.py (added)
+++ apr/apr/trunk/build/subst.py Sat Jan 3 17:46:00 2009
@@ -0,0 +1,68 @@
+#
+#
+# Ported from <http://www.scons.org/wiki/SubstInFileBuilder>
+# """ This code is freely available for your use. """
+#
+
+import re
+from SCons.Script import *
+
+def do_subst_in_file(targetfile, sourcefile, dict):
+ """Replace all instances of the keys of dict with their values.
+ For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
+ then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
+ """
+ try:
+ f = open(sourcefile, 'rb')
+ contents = f.read()
+ f.close()
+ except:
+ raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
+ for (k,v) in dict.items():
+ contents = re.sub(k, v, contents)
+ try:
+ f = open(targetfile, 'wb')
+ f.write(contents)
+ f.close()
+ except:
+ raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
+ return 0 # success
+
+def subst_in_file(target, source, env):
+ if not env.has_key('SUBST_DICT'):
+ raise SCons.Errors.UserError, "SubstFile requires SUBST_DICT to be set."
+ d = dict(env['SUBST_DICT']) # copy it
+ for (k,v) in d.items():
+ if callable(v):
+ d[k] = env.subst(v())
+ elif SCons.Util.is_String(v):
+ d[k]=env.subst(v)
+ else:
+ d[k] = SCons.Util.to_String(v)
+ for (t,s) in zip(target, source):
+ return do_subst_in_file(str(t), str(s), d)
+
+def subst_in_file_string(target, source, env):
+ """This is what gets printed on the console."""
+ return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
+ for (t,s) in zip(target, source)])
+
+def subst_emitter(target, source, env):
+ """Add dependency from substituted SUBST_DICT to target.
+ Returns original target, source tuple unchanged.
+ """
+ d = env['SUBST_DICT'].copy() # copy it
+ for (k,v) in d.items():
+ if callable(v):
+ d[k] = env.subst(v())
+ elif SCons.Util.is_String(v):
+ d[k] = env.subst(v)
+ Depends(target, SCons.Node.Python.Value(d))
+ return target, source
+
+def generate(env):
+ subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
+ env['BUILDERS']['SubstFile'] = Builder(action=subst_action, emitter=subst_emitter)
+
+def exists(env):
+ return 1
Propchange: apr/apr/trunk/build/subst.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: apr/apr/trunk/build/subst.py
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: apr/apr/trunk/build/subst.py
------------------------------------------------------------------------------
svn:mime-type = text/plain