mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-22 09:57:15 +01:00
added export_includes/export_defines parameters to read_shlib/read_stlib
This commit is contained in:
parent
f4a6a218e3
commit
856db9cc90
10
playground/dynamic_build3/main.c
Normal file
10
playground/dynamic_build3/main.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#if A == 1
|
||||||
|
|
||||||
|
#include "external.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
return zero();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
90
playground/dynamic_build3/wscript
Normal file
90
playground/dynamic_build3/wscript
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
# Thomas Nagy, 2013 (ita)
|
||||||
|
|
||||||
|
VERSION='0.0.1'
|
||||||
|
APPNAME='dynamic_build3'
|
||||||
|
|
||||||
|
"""
|
||||||
|
An advanced dynamic build simulating a call to an external system.
|
||||||
|
|
||||||
|
That external build system produces a library which is then used in the current build.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os, shutil, sys, subprocess
|
||||||
|
from waflib import Utils, Build, Logs
|
||||||
|
|
||||||
|
top = '.'
|
||||||
|
out = 'build'
|
||||||
|
|
||||||
|
def options(opt):
|
||||||
|
opt.load('compiler_c')
|
||||||
|
|
||||||
|
def configure(conf):
|
||||||
|
conf.load('compiler_c')
|
||||||
|
|
||||||
|
def build(bld):
|
||||||
|
bld.post_mode = Build.POST_LAZY
|
||||||
|
|
||||||
|
# build the external library
|
||||||
|
bld(rule=some_fun, target='external_lib/flag.file')
|
||||||
|
|
||||||
|
# once it is done create a second build group
|
||||||
|
bld.add_group()
|
||||||
|
|
||||||
|
# read the library
|
||||||
|
bld.read_shlib('foo', paths=['build/external_lib'], export_includes='build/external_lib', export_defines=['A=1'])
|
||||||
|
|
||||||
|
# and use this library, for a target
|
||||||
|
# no additional build group needed since "app" will wait on "foo" through the use= system
|
||||||
|
bld.program(source='main.c', target='app', use='foo')
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------
|
||||||
|
# the following is a pointless exercise simulating the execution of an external buildsystem
|
||||||
|
# do not spend too much time on it :-)
|
||||||
|
|
||||||
|
SNIP = """
|
||||||
|
top = '.'
|
||||||
|
out = '.'
|
||||||
|
def options(opt):
|
||||||
|
opt.load('compiler_c')
|
||||||
|
def configure(conf):
|
||||||
|
conf.load('compiler_c')
|
||||||
|
def build(bld):
|
||||||
|
bld.shlib(source='external.c', target='foo', includes='.')
|
||||||
|
"""
|
||||||
|
|
||||||
|
def some_fun(task):
|
||||||
|
# first, clean everything
|
||||||
|
output_dir = task.outputs[0].parent
|
||||||
|
shutil.rmtree(output_dir.abspath())
|
||||||
|
os.makedirs(output_dir.abspath())
|
||||||
|
|
||||||
|
# we have a clean directory, create a fake project in it
|
||||||
|
h_node = output_dir.make_node('external.h')
|
||||||
|
h_node.write('int zero();\n', flags='w')
|
||||||
|
|
||||||
|
c_node = output_dir.make_node('external.c')
|
||||||
|
c_node.write('int zero() { return 0; }\n', flags='w')
|
||||||
|
|
||||||
|
w_node = output_dir.make_node('wscript')
|
||||||
|
w_node.write(SNIP)
|
||||||
|
|
||||||
|
cmd = [sys.executable, sys.argv[0], 'configure', 'build']
|
||||||
|
cwd = output_dir.abspath()
|
||||||
|
|
||||||
|
try:
|
||||||
|
task.generator.bld.cmd_and_log(cmd, cwd=cwd, quiet=0, output=0)
|
||||||
|
except Exception as e:
|
||||||
|
try:
|
||||||
|
print(e.stderr)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
Logs.error("Build of the external library failed")
|
||||||
|
return -1
|
||||||
|
|
||||||
|
Logs.info(' (the external library has been compiled)')
|
||||||
|
|
||||||
|
# then write a lock file, so that a rebuild occurs if everything is removed manually
|
||||||
|
task.outputs[0].write('ok')
|
||||||
|
|
@ -568,7 +568,7 @@ class fake_stlib(stlink_task):
|
|||||||
return Task.SKIP_ME
|
return Task.SKIP_ME
|
||||||
|
|
||||||
@conf
|
@conf
|
||||||
def read_shlib(self, name, paths=[]):
|
def read_shlib(self, name, paths=[], export_includes=[], export_defines=[]):
|
||||||
"""
|
"""
|
||||||
Read a system shared library, enabling its use as a local library. Will trigger a rebuild if the file changes::
|
Read a system shared library, enabling its use as a local library. Will trigger a rebuild if the file changes::
|
||||||
|
|
||||||
@ -576,14 +576,14 @@ def read_shlib(self, name, paths=[]):
|
|||||||
bld.read_shlib('m')
|
bld.read_shlib('m')
|
||||||
bld.program(source='main.c', use='m')
|
bld.program(source='main.c', use='m')
|
||||||
"""
|
"""
|
||||||
return self(name=name, features='fake_lib', lib_paths=paths, lib_type='shlib')
|
return self(name=name, features='fake_lib', lib_paths=paths, lib_type='shlib', export_includes=export_includes, export_defines=export_defines)
|
||||||
|
|
||||||
@conf
|
@conf
|
||||||
def read_stlib(self, name, paths=[]):
|
def read_stlib(self, name, paths=[], export_includes=[], export_defines=[]):
|
||||||
"""
|
"""
|
||||||
Read a system static library, enabling a use as a local library. Will trigger a rebuild if the file changes.
|
Read a system static library, enabling a use as a local library. Will trigger a rebuild if the file changes.
|
||||||
"""
|
"""
|
||||||
return self(name=name, features='fake_lib', lib_paths=paths, lib_type='stlib')
|
return self(name=name, features='fake_lib', lib_paths=paths, lib_type='stlib', export_includes=export_includes, export_defines=export_defines)
|
||||||
|
|
||||||
lib_patterns = {
|
lib_patterns = {
|
||||||
'shlib' : ['lib%s.so', '%s.so', 'lib%s.dylib', 'lib%s.dll', '%s.dll'],
|
'shlib' : ['lib%s.so', '%s.so', 'lib%s.dylib', 'lib%s.dll', '%s.dll'],
|
||||||
|
Loading…
Reference in New Issue
Block a user