[PATCH] waf_generator: Copy headers if necessary.

Sichen Zhao zsc19940506 at outlook.com
Sun Jul 23 08:16:59 UTC 2017


Hi all,
I have tested the patch in libbsd, and it works well.

Best Regards
Sichen Zhao

________________________________________
From: Christian Mauderer <list at c-mauderer.de>
Sent: Sunday, July 23, 2017 1:30
To: devel at rtems.org
Cc: Chris Johns; Sichen Zhao; Christian Mauderer
Subject: [PATCH] waf_generator: Copy headers if necessary.

From: Christian Mauderer <christian.mauderer at embedded-brains.de>

There are some cases, where a header is installed into a directory with
a different name then it's source directory. In that case, the build
might fail because the header is not found. One example would be the
<openssl/opensslv.h>. The source for this file is in
freebsd/crypto/openssl/crypto/opensslv.h.

To allow the build to work in such cases too, copy such files into a
temporary location in the build tree.
---
 builder.py       |  1 +
 libbsd_waf.py    | 14 ++++++++++++++
 waf_generator.py | 22 ++++++++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/builder.py b/builder.py
index 7f2a2576..610dc0e8 100755
--- a/builder.py
+++ b/builder.py
@@ -172,6 +172,7 @@ def commonNoWarnings():

 def includes():
     return ['-Irtemsbsd/include',
+            '-Ilibbsd_build/include',
             '-Ifreebsd/sys',
             '-Ifreebsd/sys/contrib/pf',
             '-Ifreebsd/sys/net',
diff --git a/libbsd_waf.py b/libbsd_waf.py
index e3733421..a63d8c54 100644
--- a/libbsd_waf.py
+++ b/libbsd_waf.py
@@ -62,6 +62,7 @@ def build(bld):
         for i in ['-Irtemsbsd/@CPU@/include', '-Ifreebsd/sys/@CPU@/include']:
             includes += ["%s" % (i[2:].replace("@CPU@", "x86"))]
     includes += ["rtemsbsd/include"]
+    includes += ["libbsd_build/include"]
     includes += ["freebsd/sys"]
     includes += ["freebsd/sys/contrib/pf"]
     includes += ["freebsd/sys/net"]
@@ -123,6 +124,19 @@ def build(bld):
         rule = "sed -e 's/@NET_CFG_SELF_IP@/%s/' -e 's/@NET_CFG_NETMASK@/%s/' -e 's/@NET_CFG_PEER_IP@/%s/' -e 's/@NET_CFG_GATEWAY_IP@/%s/' < ${SRC} > ${TGT}" % (net_cfg_self_ip, net_cfg_netmask, net_cfg_peer_ip, net_cfg_gateway_ip),
         update_outputs = True)

+    # copy headers if necessary
+    header_build_copy_paths = [
+                              ]
+    for headers in header_build_copy_paths:
+        target = os.path.join("libbsd_build/include", headers[2])
+        start_dir = bld.path.find_dir(headers[0])
+        for header in start_dir.ant_glob("**/" + headers[1]):
+            relsourcepath = os.path.relpath(str(header), start=str(start_dir))
+            targetheader = os.path.join(target, relsourcepath)
+            bld(target = targetheader,
+                source = header,
+                rule = "cp ${SRC} ${TGT}")
+
     # KVM Symbols
     bld(target = "rtemsbsd/rtems/rtems-kernel-kvm-symbols.c",
         source = "rtemsbsd/rtems/generate_kvm_symbols",
diff --git a/waf_generator.py b/waf_generator.py
index 35fe35f4..fa3f01cb 100755
--- a/waf_generator.py
+++ b/waf_generator.py
@@ -445,6 +445,28 @@ class ModuleManager(builder.ModuleManager):
         self.add('')

         #
+        # 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(target = targetheader,')
+        self.add('                source = header,')
+        self.add('                rule = "cp ${SRC} ${TGT}")')
+        self.add('')
+
+        #
         # Add the specific rule based builders for generating files.
         #
         if 'KVMSymbols' in data:
--
2.13.3




More information about the devel mailing list