Browse Source

Implement a skeleton for compatibility modules

This commit introduces the skeleton needed to implement reusable
operating system compatibility modules. This skeleton can then be
extended with the actual compatibility modules that work around
operating system specifics.

For example this will be used to be able to compile files that use
alloca on Windows. Also it can be used to implement replacements for
functions that are missing on some systems.
tags/v1.9.13
Karl Linden Karl Lindén 7 years ago
parent
commit
7fa02c2132
3 changed files with 103 additions and 0 deletions
  1. +40
    -0
      compat/README.md
  2. +57
    -0
      compat/wscript
  3. +6
    -0
      wscript

+ 40
- 0
compat/README.md View File

@@ -0,0 +1,40 @@
# Operating System Compatibility Modules for WAF

This directory contains waf modules that aid compatibility across
different operating systems. Here a module is a pluggable and reusable
piece of code for the waf build system along with necessary
replacements.

To create a new compatibility module simply create a new subdirectory
containing a `wscript` file and any necessary replacement files. The
`wscript` must define the `options`, `configure` and `build` functions.

To use the modules you need to call `recurse` in your `options`,
`configure` and `build` commands. For example
```python
def options(opt):
# Do stuff...
opt.recurse('compat')
# Do other stuff...

def configure(conf):
# Do stuff...
conf.recurse('compat')
# Do other stuff...

def build(bld):
# Do stuff...
bld.recurse('compat')
# Do other stuff...
```
assuming this directory is called `compat`. After doing this you need to
take any necessary actions described in the modules you want to use.

The code in this directory is inteded to be generic and reusable. When
writing new modules, please keep this in mind. Whenever necessary it
should be possible to make this directory a git submodule and all the
subdirectories other submodules, to aid reuse.

If you would like to use these modules in another project, please file
an issue so that we can join forces and maintain the compatabilitiy
modules in a separate repository.

+ 57
- 0
compat/wscript View File

@@ -0,0 +1,57 @@
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (C) 2018 Karl Linden <karl.j.linden@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import os

def get_subdirs(ctx):
"""
Get the compatibility module subirectories.

The compat modules are found dynamically so that this script does
not have to be modified if more modules are added.

:param ctx: the waf context
:type ctx: waflib.Context.Context
:returns: list of str -- the subdirectories
"""
subdirs = []
for entry in ctx.path.listdir():
path = os.path.join(ctx.path.abspath(), entry)
if os.path.isdir(path) and not entry.startswith('.'):
subdirs.append(entry)
return subdirs

def recurse_into_subdirs(ctx):
"""
Recurse into compatibility module subdirectories.

:param ctx: the waf context
:type ctx: waflib.Context.Context
"""
for x in get_subdirs(ctx):
ctx.recurse(x)

def options(opt):
recurse_into_subdirs(opt)

def configure(conf):
recurse_into_subdirs(conf)

def build(bld):
recurse_into_subdirs(bld)

+ 6
- 0
wscript View File

@@ -55,6 +55,8 @@ def options(opt):


opt.load('xcode6') opt.load('xcode6')


opt.recurse('compat')

# install directories # install directories
opt.add_option('--htmldir', type='string', default=None, help='HTML documentation directory [Default: <prefix>/share/jack-audio-connection-kit/reference/html/') opt.add_option('--htmldir', type='string', default=None, help='HTML documentation directory [Default: <prefix>/share/jack-audio-connection-kit/reference/html/')
opt.add_option('--libdir', type='string', help='Library directory [Default: <prefix>/lib]') opt.add_option('--libdir', type='string', help='Library directory [Default: <prefix>/lib]')
@@ -217,6 +219,8 @@ def configure(conf):


conf.load('autooptions') conf.load('autooptions')


conf.recurse('compat')

# Check for functions. # Check for functions.
conf.check( conf.check(
fragment='' fragment=''
@@ -729,6 +733,8 @@ def build(bld):
# only the wscript in common/ knows how to handle variants # only the wscript in common/ knows how to handle variants
return return


bld.recurse('compat')

if not os.access('svnversion.h', os.R_OK): if not os.access('svnversion.h', os.R_OK):
def post_run(self): def post_run(self):
sg = Utils.h_file(self.outputs[0].abspath(self.env)) sg = Utils.h_file(self.outputs[0].abspath(self.env))


Loading…
Cancel
Save