Commit d910be21 by Vicent Marti

Add separate commands for all possible actions

The build script now supports all the required features

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent b2898c45
...@@ -7,8 +7,8 @@ CFLAGS = ["-g", "-O2", "-Wall", "-Wextra"] ...@@ -7,8 +7,8 @@ CFLAGS = ["-g", "-O2", "-Wall", "-Wextra"]
def options(opt): def options(opt):
opt.load('compiler_c') opt.load('compiler_c')
opt.add_option('--sha1', action='store', default='builtin', opt.add_option('--sha1', action='store', default='builtin',
help="Use the builtin SHA1 routines (--sha1=builtin), the\ help="Use the builtin SHA1 routines (builtin), the \
PPC optimized version (--sha1=ppc) or the SHA1 functions from OpenSSH (--sha1=openssh)") PPC optimized version (ppc) or the SHA1 functions from OpenSSH (openssh)")
def configure(conf): def configure(conf):
conf.load('compiler_c') conf.load('compiler_c')
...@@ -19,14 +19,22 @@ def configure(conf): ...@@ -19,14 +19,22 @@ def configure(conf):
conf.env.sha1 = conf.options.sha1 conf.env.sha1 = conf.options.sha1
def build(bld): def build(bld):
import sys
libs = { 'static' : 'cstlib', 'shared' : 'cshlib' } if bld.variant == 'static':
build_library(bld, 'cstlib')
elif bld.variant == 'shared':
build_library(bld, 'cshlib')
elif bld.variant == 'tests':
build_tests(bld)
if bld.variant not in libs: else:
from waflib import Options from waflib import Options
Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
return
def build_library(bld, lib_str):
import sys
directory = bld.path directory = bld.path
...@@ -64,36 +72,30 @@ def build(bld): ...@@ -64,36 +72,30 @@ def build(bld):
sources = sources + directory.ant_glob('src/%s/*.c' % os) sources = sources + directory.ant_glob('src/%s/*.c' % os)
bld(features='c ' + libs[bld.variant], bld(features=['c', lib_str],
source=sources, source=sources,
target='git2', target='git2',
includes='src', includes='src',
cflags=flags, cflags=flags,
defines=defines, defines=defines,
inst_to='${LIBDIR}' install_path='${LIBDIR}',
) )
bld.install_files('${PREFIX}/include/git', directory.ant_glob('src/git/*.h')) if os == 'unix':
if os == "unix": bld(rule="""sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' < ${SRC} > ${TGT}""",
bld.install_files('${PREFIX}/lib/pkgconfig', 'libgit2.pc') source='libgit2.pc.in',
target='libgit2.pc',
install_path='${LIBDIR}/pkgconfig',
)
class _test(BuildContext): bld.install_files('${PREFIX}/include/git', directory.ant_glob('src/git/*.h'))
cmd = 'test'
fun = 'test'
def test(bld):
from waflib import Options
Options.commands = ['build-static', 'build-tests', 'run-tests'] + Options.commands
class _build_tests(BuildContext):
cmd = 'build-tests'
fun = 'build_tests'
variant = 'tests'
def build_tests(bld): def build_tests(bld):
import os import os
if bld.is_install:
return
directory = bld.path directory = bld.path
bld.objects(source=['tests/test_helpers.c', 'tests/test_lib.c'], includes=['src', 'tests'], target='test_helper') bld.objects(source=['tests/test_helpers.c', 'tests/test_lib.c'], includes=['src', 'tests'], target='test_helper')
...@@ -101,9 +103,9 @@ def build_tests(bld): ...@@ -101,9 +103,9 @@ def build_tests(bld):
test_name, _ = os.path.splitext(os.path.basename(test_file.abspath())) test_name, _ = os.path.splitext(os.path.basename(test_file.abspath()))
test_toc_file = directory.make_node('tests/%s.toc' % test_name) test_toc_file = directory.make_node('tests/%s.toc' % test_name)
if bld.cmd == 'clean': if bld.cmd == 'clean-tests':
test_toc_file.delete() test_toc_file.delete()
else: elif bld.cmd == 'build-tests':
test_toc = bld.cmd_and_log(['grep', 'BEGIN_TEST', test_file.abspath()], quiet=True) test_toc = bld.cmd_and_log(['grep', 'BEGIN_TEST', test_file.abspath()], quiet=True)
test_toc_file.write(test_toc) test_toc_file.write(test_toc)
...@@ -113,9 +115,19 @@ def build_tests(bld): ...@@ -113,9 +115,19 @@ def build_tests(bld):
includes=['src', 'tests'], includes=['src', 'tests'],
defines=['TEST_TOC="%s.toc"' % test_name], defines=['TEST_TOC="%s.toc"' % test_name],
stlib=['git2', 'z'], stlib=['git2', 'z'],
stlibpath=[directory.abspath(), 'build'], stlibpath=directory.find_node('build/static/').abspath(),
use='test_helper') use='test_helper')
class _test(BuildContext):
cmd = 'test'
fun = 'test'
def test(bld):
from waflib import Options
Options.commands = ['build-static', 'build-tests', 'run-tests'] + Options.commands
class _run_tests(Context): class _run_tests(Context):
cmd = 'run-tests' cmd = 'run-tests'
fun = 'run_tests' fun = 'run_tests'
...@@ -133,10 +145,31 @@ def run_tests(ctx): ...@@ -133,10 +145,31 @@ def run_tests(ctx):
test_folder.delete() test_folder.delete()
for var in ('static', 'shared'):
for ctx in (BuildContext, CleanContext, InstallContext, UninstallContext): CONTEXTS = {
name = ctx.__name__.replace('Context', '').lower() 'build' : BuildContext,
class _genclass(ctx): 'clean' : CleanContext,
cmd = name + '-' + var 'install' : InstallContext,
variant = var 'uninstall' : UninstallContext
}
def build_command(command):
ctx, var = command.split('-')
class _gen_command(CONTEXTS[ctx]):
cmd = command
variant = var
build_command('build-static')
build_command('build-shared')
build_command('build-tests')
build_command('clean-static')
build_command('clean-shared')
build_command('clean-tests')
build_command('install-static')
build_command('install-shared')
build_command('uninstall-static')
build_command('uninstall-shared')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment