1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00

build: install public headers in the build tree

this symlinks our public headers into the build tree, which will allow
us to refer to the public headers by their public name inside the
source tree.
This commit is contained in:
Andrew Tridgell 2011-02-28 15:48:25 +11:00
parent b7b2426fe3
commit 4f52becec1
2 changed files with 57 additions and 15 deletions

View File

@ -726,6 +726,20 @@ def INSTALL_DIRS(bld, destdir, dirs):
Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
def header_install_path(header, header_path):
'''find the installation path for a header, given a header_path option'''
if not header_path:
return ''
if not isinstance(header_path, list):
return header_path
for (p1, dir) in header_path:
for p2 in TO_LIST(p1):
if fnmatch.fnmatch(header, p2):
return dir
# default to current path
return ''
re_header = re.compile('#include[ \t]*"([^"]+)"', re.I | re.M) re_header = re.compile('#include[ \t]*"([^"]+)"', re.I | re.M)
class header_task(Task.Task): class header_task(Task.Task):
""" """
@ -819,21 +833,7 @@ def make_public_headers(self):
for x in self.to_list(self.headers): for x in self.to_list(self.headers):
# too complicated, but what was the original idea? inst_path = header_install_path(x, header_path)
if isinstance(header_path, list):
add_dir = ''
for (p1, dir) in header_path:
lst = self.to_list(p1)
for p2 in lst:
if fnmatch.fnmatch(x, p2):
add_dir = dir
break
else:
continue
break
inst_path = add_dir
else:
inst_path = header_path
dest = '' dest = ''
name = x name = x
@ -868,6 +868,20 @@ def make_public_headers(self):
val = hash((val, k, self.bld.hnodemap[k])) val = hash((val, k, self.bld.hnodemap[k]))
self.bld.env.HEADER_DEPS = val self.bld.env.HEADER_DEPS = val
def symlink_header(task):
'''symlink a header in the build tree'''
src = task.inputs[0].abspath(task.env)
tgt = task.outputs[0].bldpath(task.env)
if os.path.lexists(tgt):
if os.path.islink(tgt) and os.readlink(tgt) == src:
return
os.unlink(tgt)
os.symlink(src, tgt)
def PUBLIC_HEADERS(bld, public_headers, header_path=None): def PUBLIC_HEADERS(bld, public_headers, header_path=None):
'''install some headers '''install some headers
@ -877,6 +891,31 @@ def PUBLIC_HEADERS(bld, public_headers, header_path=None):
''' '''
bld.SET_BUILD_GROUP('final') bld.SET_BUILD_GROUP('final')
ret = bld(features=['pubh'], headers=public_headers, header_path=header_path) ret = bld(features=['pubh'], headers=public_headers, header_path=header_path)
if bld.env.build_public_headers:
# when build_public_headers is set, symlink the headers into the include/public
# directory
for h in TO_LIST(public_headers):
inst_path = header_install_path(h, header_path)
if h.find(':') != -1:
s = h.split(":")
h_name = s[0]
inst_name = s[1]
else:
h_name = h
inst_name = os.path.basename(h)
relpath1 = os_path_relpath(bld.srcnode.abspath(), bld.curdir)
relpath2 = os_path_relpath(bld.curdir, bld.srcnode.abspath())
targetdir = os.path.normpath(os.path.join(relpath1, bld.env.build_public_headers, inst_path))
if not os.path.exists(os.path.join(bld.curdir, targetdir)):
raise Utils.WafError("missing source directory %s for public header %s" % (targetdir, inst_name))
target = os.path.join(targetdir, inst_name)
bld.SAMBA_GENERATOR('HEADER_%s/%s' % (relpath2, inst_name),
rule=symlink_header,
source=h_name,
target=target)
return ret return ret
Build.BuildContext.PUBLIC_HEADERS = PUBLIC_HEADERS Build.BuildContext.PUBLIC_HEADERS = PUBLIC_HEADERS

View File

@ -17,6 +17,9 @@ bld.env.suffix3 = "3"
bld.SETUP_BUILD_GROUPS() bld.SETUP_BUILD_GROUPS()
bld.AUTOCLEANUP_STALE_FILES() bld.AUTOCLEANUP_STALE_FILES()
# enable building of public headers in the build tree
bld.env.build_public_headers = 'include/public'
samba_version.load_version(bld.env) samba_version.load_version(bld.env)
bld.SAMBA_MKVERSION('version.h') bld.SAMBA_MKVERSION('version.h')