Add Copy headers support for RTEMS-libbsd

来源:互联网 发布:数据新闻报道方向 编辑:程序博客网 时间:2024/05/16 18:43

在移植OpenSSL库的过程中,碰到了问题:

当我从FreeBSD import 文件并port to RTEMS时,被include的头文件的文件路径和其实际的文件路径不同时,会造成编译错误,因为编译器waf找不到头文件。一个例子就是:the <openssl/opensslv.h>. The source for this file is in freebsd/crypto/openssl/crypto/opensslv.h.

针对这个bug,可以将这种头文件copy to 一个暂时的文件夹中,接下来才就详细描述如何实现:


1. Add a temporary catalog in builder.py

def includes():      return ['-Irtemsbsd/include', +            '-Ilibbsd_build/include',              '-Ifreebsd/sys',              '-Ifreebsd/sys/contrib/pf',              '-Ifreebsd/sys/net',


2.Add the copy method in waf_generator.py

## Add a copy rule for all headers where the install path and the source# path are not the same.#self.add('    # copy headers if necessary')headerPaths = builder.headerPaths()self.add('    header_build_copy_paths = [')for hp in headerPaths:if hp[2] != '' and not hp[0].endswith(hp[2]):self.add('                               %s,' % (str(hp)))self.add('                              ]')self.add('    for headers in header_build_copy_paths:')self.add('        target = os.path.join("libbsd_build/include", headers[2])')self.add('        start_dir = bld.path.find_dir(headers[0])')self.add('        for header in start_dir.ant_glob("**/" + headers[1]):')self.add('            relsourcepath = os.path.relpath(str(header), start=str(start_dir))')self.add('            targetheader = os.path.join(target, relsourcepath)')self.add('            bld(features = \'subst\',')self.add('                target = targetheader,')self.add('                source = header,')self.add('                is_copy = True)')self.add('')


So if the imported files installed into a directory with a different name then it's source directory, then this files will be copied into build/arm-rtems4.12-beagleboneblack/libbsd_build/include folder.

因此如果imported file 的路径和其源文件路径不同时,该文件会被copy至build/arm-rtems4.12-beagleboneblack/libbsd_build/include文件夹下。

原创粉丝点击