mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 08:11:58 +00:00
Add more features to the build system
- Windows 32 compilation - Test system - Shared and static libraries Signed-off-by: Vicent Marti <tanoku@gmail.com>
This commit is contained in:
parent
357547fa12
commit
b2898c4500
102
wscript
102
wscript
@ -1,8 +1,14 @@
|
|||||||
|
from waflib.Context import Context
|
||||||
|
from waflib.Build import BuildContext, CleanContext, \
|
||||||
|
InstallContext, UninstallContext
|
||||||
|
|
||||||
CFLAGS = ["-g", "-O2", "-Wall", "-Wextra"]
|
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', help='TODO')
|
opt.add_option('--sha1', action='store', default='builtin',
|
||||||
|
help="Use the builtin SHA1 routines (--sha1=builtin), the\
|
||||||
|
PPC optimized version (--sha1=ppc) or the SHA1 functions from OpenSSH (--sha1=openssh)")
|
||||||
|
|
||||||
def configure(conf):
|
def configure(conf):
|
||||||
conf.load('compiler_c')
|
conf.load('compiler_c')
|
||||||
@ -12,11 +18,19 @@ def configure(conf):
|
|||||||
|
|
||||||
conf.env.sha1 = conf.options.sha1
|
conf.env.sha1 = conf.options.sha1
|
||||||
|
|
||||||
|
|
||||||
def build(bld):
|
def build(bld):
|
||||||
import glob, sys
|
import sys
|
||||||
|
|
||||||
sources = glob.glob('src/*.c')
|
libs = { 'static' : 'cstlib', 'shared' : 'cshlib' }
|
||||||
|
|
||||||
|
if bld.variant not in libs:
|
||||||
|
from waflib import Options
|
||||||
|
Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
|
||||||
|
return
|
||||||
|
|
||||||
|
directory = bld.path
|
||||||
|
|
||||||
|
sources = directory.ant_glob('src/*.c')
|
||||||
flags = CFLAGS
|
flags = CFLAGS
|
||||||
defines = []
|
defines = []
|
||||||
visibility = True
|
visibility = True
|
||||||
@ -48,23 +62,81 @@ def build(bld):
|
|||||||
if not visibility:
|
if not visibility:
|
||||||
flags.append('-fvisibility=hidden')
|
flags.append('-fvisibility=hidden')
|
||||||
|
|
||||||
sources = sources + glob.glob('src/%s/*.c' % os)
|
sources = sources + directory.ant_glob('src/%s/*.c' % os)
|
||||||
|
|
||||||
bld.stlib(
|
bld(features='c ' + libs[bld.variant],
|
||||||
source=sources,
|
source=sources,
|
||||||
target='git2',
|
target='git2',
|
||||||
includes='src',
|
includes='src',
|
||||||
cflags=flags,
|
cflags=flags,
|
||||||
defines=defines
|
defines=defines,
|
||||||
|
inst_to='${LIBDIR}'
|
||||||
)
|
)
|
||||||
|
|
||||||
bld.shlib(
|
bld.install_files('${PREFIX}/include/git', directory.ant_glob('src/git/*.h'))
|
||||||
source=sources,
|
if os == "unix":
|
||||||
target='git2',
|
bld.install_files('${PREFIX}/lib/pkgconfig', 'libgit2.pc')
|
||||||
includes='src',
|
|
||||||
cflags=flags,
|
|
||||||
defines=defines
|
|
||||||
)
|
|
||||||
|
|
||||||
bld.install_files('${PREFIX}/include/git', glob.glob('src/git/*.h'))
|
|
||||||
|
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 _build_tests(BuildContext):
|
||||||
|
cmd = 'build-tests'
|
||||||
|
fun = 'build_tests'
|
||||||
|
variant = 'tests'
|
||||||
|
|
||||||
|
def build_tests(bld):
|
||||||
|
import os
|
||||||
|
|
||||||
|
directory = bld.path
|
||||||
|
bld.objects(source=['tests/test_helpers.c', 'tests/test_lib.c'], includes=['src', 'tests'], target='test_helper')
|
||||||
|
|
||||||
|
for test_file in directory.ant_glob('tests/t????-*.c'):
|
||||||
|
test_name, _ = os.path.splitext(os.path.basename(test_file.abspath()))
|
||||||
|
|
||||||
|
test_toc_file = directory.make_node('tests/%s.toc' % test_name)
|
||||||
|
if bld.cmd == 'clean':
|
||||||
|
test_toc_file.delete()
|
||||||
|
else:
|
||||||
|
test_toc = bld.cmd_and_log(['grep', 'BEGIN_TEST', test_file.abspath()], quiet=True)
|
||||||
|
test_toc_file.write(test_toc)
|
||||||
|
|
||||||
|
bld.program(
|
||||||
|
source=[test_file, 'tests/test_main.c'],
|
||||||
|
target=test_name,
|
||||||
|
includes=['src', 'tests'],
|
||||||
|
defines=['TEST_TOC="%s.toc"' % test_name],
|
||||||
|
stlib=['git2', 'z'],
|
||||||
|
stlibpath=[directory.abspath(), 'build'],
|
||||||
|
use='test_helper')
|
||||||
|
|
||||||
|
class _run_tests(Context):
|
||||||
|
cmd = 'run-tests'
|
||||||
|
fun = 'run_tests'
|
||||||
|
|
||||||
|
def run_tests(ctx):
|
||||||
|
test_folder = ctx.path.make_node('tests/tmp/')
|
||||||
|
|
||||||
|
for test in ctx.path.ant_glob('build/tests/t????-*'):
|
||||||
|
test_folder.delete()
|
||||||
|
test_folder.mkdir()
|
||||||
|
|
||||||
|
if ctx.exec_command(test.abspath(), cwd=test_folder.abspath()) != 0:
|
||||||
|
ctx.fatal('Test run failed')
|
||||||
|
break
|
||||||
|
|
||||||
|
test_folder.delete()
|
||||||
|
|
||||||
|
for var in ('static', 'shared'):
|
||||||
|
for ctx in (BuildContext, CleanContext, InstallContext, UninstallContext):
|
||||||
|
name = ctx.__name__.replace('Context', '').lower()
|
||||||
|
class _genclass(ctx):
|
||||||
|
cmd = name + '-' + var
|
||||||
|
variant = var
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user