Re: [PATCH 1/3] waf_generator: Copy headers if necessary.

2017-08-10 Thread Chris Johns
On 10/08/2017 16:41, Christian Mauderer wrote:
> 
> I was more concerned that the include list in builder.py has grown
> significantly. If you don't have a problem with that, it's OK.
> 

I will fix this after the merge.

>> I could look at making libbsd.py into libbsd/__init__.py with a file per 
>> module
>> and the top level just sees the imports. I still see no need for us to have
>> module build control, we always build all modules.
> 
> Currently I wouldn't see a big advantage in splitting up libbsd.py
> except that the files are smaller.

Easier to review changes.

> It might would be nice to have some more control over the modules that
> get build with some kind of configuration or BSP-config file in the
> future. If it would be possibility to set custom defines depending on
> the configuration that would even add some more flexibility. With that
> it would for example be possible to exclude IPv6 support on small
> targets or add a BSP specific driver. But that's a problem that can be
> solved some when in the future when someone in the community has time or
> budget to do that.

Yes this would be nice.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 1/3] waf_generator: Copy headers if necessary.

2017-08-10 Thread Christian Mauderer
From: Christian Mauderer 

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
. 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   | 14 ++
 libbsd_waf.py| 15 +++
 waf_generator.py | 24 +++-
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/builder.py b/builder.py
index bb633cb2..1be1ced1 100755
--- a/builder.py
+++ b/builder.py
@@ -194,6 +194,10 @@ def includes():
 '-ImDNSResponder/mDNSPosix',
 '-Itestsuite/include']
 
+def buildInclude():
+""" Returns the path where headers will be copied during build. """
+return 'build-include'
+
 def cpuIncludes():
 return ['-Irtemsbsd/@CPU@/include',
 '-Ifreebsd/sys/@CPU@/include']
@@ -205,6 +209,16 @@ def cxxflags():
 return []
 
 def headerPaths():
+""" Returns a list of information about what header files should be
+installed.
+
+The list is also used to find headers with a local path that doesn't match
+it's dest path. Due to the difference in the path name such files are
+problematic during the build if they are included using their later
+installation path (dest path) name. Therefore they are copied into a
+sub-directory of the build path so that they can be included with their
+normal installation path. """
+
 # local path  wildcard dest path
 return [('rtemsbsd/include',  '*.h',   ''),
 ('rtemsbsd/mghttpd',  'mongoose.h','mghttpd'),
diff --git a/libbsd_waf.py b/libbsd_waf.py
index aee2e7ad..cbb0ae23 100644
--- a/libbsd_waf.py
+++ b/libbsd_waf.py
@@ -83,6 +83,7 @@ def build(bld):
 includes += ["mDNSResponder/mDNSShared"]
 includes += ["mDNSResponder/mDNSPosix"]
 includes += ["testsuite/include"]
+includes += ["build-include"]
 
 # Collect the libbsd uses
 libbsd_use = []
@@ -123,6 +124,20 @@ 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("build-include", headers[2])
+start_dir = bld.path.find_dir(headers[0])
+for header in start_dir.ant_glob("**/" + headers[1]):
+relsourcepath = header.path_from(start_dir)
+targetheader = os.path.join(target, relsourcepath)
+bld(features = 'subst',
+target = targetheader,
+source = header,
+is_copy = True)
+
 # 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..271aed96 100755
--- a/waf_generator.py
+++ b/waf_generator.py
@@ -392,7 +392,7 @@ class ModuleManager(builder.ModuleManager):
 self.add('if bld.get_env()["RTEMS_ARCH"] == "i386":')
 self.add('for i in %r:' % (builder.cpuIncludes()))
 self.add('includes += ["%s" % (i[2:].replace("@CPU@", 
"x86"))]')
-for i in builder.includes():
+for i in builder.includes() + ['-I' + builder.buildInclude()]:
 self.add('includes += ["%s"]' % (i[2:]))
 self.add('')
 self.add('# Collect the libbsd uses')
@@ -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')
+self.add('header_build_copy_paths = [')
+for hp in builder.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("%s", headers[2])' % 
(builder.buildInclude()))
+self.add('start_dir = bld.path.find_dir(headers[0])')
+self.add('for header in start_dir.ant_glob("**/" + 
headers[1]):')
+self.add('relsourcepath = header.path_from(start_dir)')
+self.add('targetheader = os.path.join(target, 
relsourcepath)')
+self.add('bld(features 

[PATCH 3/3] waf: Move glob operator ** to builder.py

2017-08-10 Thread Christian Mauderer
From: Christian Mauderer 

This allows a finer decision which headers should be installed.
---
 builder.py   | 26 +-
 libbsd_waf.py| 30 +++---
 waf_generator.py |  4 ++--
 3 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/builder.py b/builder.py
index 92a83dd8..21173992 100755
--- a/builder.py
+++ b/builder.py
@@ -220,16 +220,16 @@ def headerPaths():
 normal installation path. """
 
 # local path  wildcard dest path
-return [('rtemsbsd/include',  '*.h',   ''),
+return [('rtemsbsd/include',  '**/*.h',''),
 ('rtemsbsd/mghttpd',  'mongoose.h','mghttpd'),
-('freebsd/include',   '*.h',   ''),
-('freebsd/sys/bsm',   '*.h',   'bsm'),
-('freebsd/sys/cam',   '*.h',   'cam'),
-('freebsd/sys/net',   '*.h',   'net'),
-('freebsd/sys/net80211',  '*.h',   'net80211'),
-('freebsd/sys/netinet',   '*.h',   'netinet'),
-('freebsd/sys/netinet6',  '*.h',   'netinet6'),
-('freebsd/sys/netipsec',  '*.h',   'netipsec'),
+('freebsd/include',   '**/*.h',''),
+('freebsd/sys/bsm',   '**/*.h','bsm'),
+('freebsd/sys/cam',   '**/*.h','cam'),
+('freebsd/sys/net',   '**/*.h','net'),
+('freebsd/sys/net80211',  '**/*.h','net80211'),
+('freebsd/sys/netinet',   '**/*.h','netinet'),
+('freebsd/sys/netinet6',  '**/*.h','netinet6'),
+('freebsd/sys/netipsec',  '**/*.h','netipsec'),
 ('freebsd/crypto/openssl', '*.h', 'openssl'),
 ('freebsd/crypto/openssl/crypto', '*.h', 'openssl'),
 ('freebsd/crypto/openssl/crypto', 
'(opensslconf|opensslv|crypto).h', 'openssl'),
@@ -288,10 +288,10 @@ def headerPaths():
 ('freebsd/crypto/openssl/crypto/cmac', 'cmac.h',   
'openssl'),
 ('freebsd/crypto/openssl/ssl', '(ssl|kssl|ssl2).h', 'openssl'),
 ('freebsd/crypto/openssl/ssl', '*.h', 'openssl'),
-('freebsd/sys/rpc',   '*.h',   'rpc'),
-('freebsd/sys/sys',   '*.h',   'sys'),
-('freebsd/sys/vm','*.h',   'vm'),
-('freebsd/sys/dev/mii',   '*.h',   'dev/mii'),
+('freebsd/sys/rpc',   '**/*.h','rpc'),
+('freebsd/sys/sys',   '**/*.h','sys'),
+('freebsd/sys/vm','**/*.h','vm'),
+('freebsd/sys/dev/mii',   '**/*.h','dev/mii'),
 ('mDNSResponder/mDNSCore','mDNSDebug.h',   ''),
 ('mDNSResponder/mDNSCore','mDNSEmbeddedAPI.h', ''),
 ('mDNSResponder/mDNSShared',  'dns_sd.h',  ''),
diff --git a/libbsd_waf.py b/libbsd_waf.py
index 4d69e628..499a85ad 100644
--- a/libbsd_waf.py
+++ b/libbsd_waf.py
@@ -187,7 +187,7 @@ def build(bld):
 for headers in header_build_copy_paths:
 target = os.path.join("build-include", headers[2])
 start_dir = bld.path.find_dir(headers[0])
-for header in start_dir.ant_glob("**/" + headers[1]):
+for header in start_dir.ant_glob(headers[1]):
 relsourcepath = header.path_from(start_dir)
 targetheader = os.path.join(target, relsourcepath)
 bld(features = 'subst',
@@ -2292,16 +2292,16 @@ def build(bld):
 
 # Installs.
 bld.install_files("${PREFIX}/" + 
rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP), 
["libbsd.a"])
-header_paths = [('rtemsbsd/include', '*.h', ''),
+header_paths = [('rtemsbsd/include', '**/*.h', ''),
  ('rtemsbsd/mghttpd', 'mongoose.h', 'mghttpd'),
- ('freebsd/include', '*.h', ''),
- ('freebsd/sys/bsm', '*.h', 'bsm'),
- ('freebsd/sys/cam', '*.h', 'cam'),
- ('freebsd/sys/net', '*.h', 'net'),
- ('freebsd/sys/net80211', '*.h', 'net80211'),
- ('freebsd/sys/netinet', '*.h', 'netinet'),
- ('freebsd/sys/netinet6', '*.h', 'netinet6'),
- ('freebsd/sys/netipsec', '*.h', 'netipsec'),
+ ('freebsd/include', '**/*.h', ''),
+ ('freebsd/sys/bsm', '**/*.h', 'bsm'),
+ ('freebsd/sys/cam', '**/*.h', 'cam'),
+ ('freebsd/sys/net', '

Re [PATCH 1/3] waf_generator: Copy headers if necessary.

2017-08-10 Thread Christian Mauderer
Hello Chris and Sichen,

I updated the patch "waf_generator: Copy headers if necessary."
according to Chris suggestions.

@Chris: Could you have a look if it now looks OK for you?
@Sichen: Could you replace the first patch in your patch set with this
one?

I also created a patch that moves the ** of the glob from
waf_generator.py to builder.py. That avoids that a lot of unnecessary
headers are installed. For example, with the current version of Sichens
patch, the aes.h is installed three times:
 - lib/include/openssl/aes.h,
 - lib/include/openssl/aes/aes.h
 - lib/include/openssl/crypto/aes/aes.h

With the patch, it is possible to install it only one time by just
skipping the ** in the pattern.

@Sichen: Could you check whether all necessary files are still
installed?

Theoretically, that patch could be rebased so that it is before Sichens
openssl patches but I'm not sure if it is worth the effort. It only
means that there is one intermediate version which installs to many
headers but it would work too.

Regards

Christian

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 1/3] waf_generator: Copy headers if necessary.

2017-08-10 Thread Chris Johns
OK with the minor change.

On 11/08/2017 04:14, Christian Mauderer wrote:
> From: Christian Mauderer 
> 
> 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
> . 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   | 14 ++
>  libbsd_waf.py| 15 +++
>  waf_generator.py | 24 +++-
>  3 files changed, 52 insertions(+), 1 deletion(-)
> 
> diff --git a/builder.py b/builder.py
> index bb633cb2..1be1ced1 100755
> --- a/builder.py
> +++ b/builder.py
> @@ -194,6 +194,10 @@ def includes():
>  '-ImDNSResponder/mDNSPosix',
>  '-Itestsuite/include']
>  
> +def buildInclude():
> +""" Returns the path where headers will be copied during build. """
> +return 'build-include'
> +
>  def cpuIncludes():
>  return ['-Irtemsbsd/@CPU@/include',
>  '-Ifreebsd/sys/@CPU@/include']
> @@ -205,6 +209,16 @@ def cxxflags():
>  return []
>  
>  def headerPaths():
> +""" Returns a list of information about what header files should be
> +installed.
> +
> +The list is also used to find headers with a local path that doesn't 
> match
> +it's dest path. Due to the difference in the path name such files are
> +problematic during the build if they are included using their later
> +installation path (dest path) name. Therefore they are copied into a
> +sub-directory of the build path so that they can be included with their
> +normal installation path. """
> +
>  # local path  wildcard dest path
>  return [('rtemsbsd/include',  '*.h',   ''),
>  ('rtemsbsd/mghttpd',  'mongoose.h',
> 'mghttpd'),
> diff --git a/libbsd_waf.py b/libbsd_waf.py
> index aee2e7ad..cbb0ae23 100644
> --- a/libbsd_waf.py
> +++ b/libbsd_waf.py
> @@ -83,6 +83,7 @@ def build(bld):
>  includes += ["mDNSResponder/mDNSShared"]
>  includes += ["mDNSResponder/mDNSPosix"]
>  includes += ["testsuite/include"]
> +includes += ["build-include"]
>  
>  # Collect the libbsd uses
>  libbsd_use = []
> @@ -123,6 +124,20 @@ 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("build-include", headers[2])
> +start_dir = bld.path.find_dir(headers[0])
> +for header in start_dir.ant_glob("**/" + headers[1]):

Minor nit .. 'start_dir.ant_glob(os.path.join("**", headers[1]))' ?

> +relsourcepath = header.path_from(start_dir)
> +targetheader = os.path.join(target, relsourcepath)
> +bld(features = 'subst',
> +target = targetheader,
> +source = header,
> +is_copy = True)
> +
>  # 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..271aed96 100755
> --- a/waf_generator.py
> +++ b/waf_generator.py
> @@ -392,7 +392,7 @@ class ModuleManager(builder.ModuleManager):
>  self.add('if bld.get_env()["RTEMS_ARCH"] == "i386":')
>  self.add('for i in %r:' % (builder.cpuIncludes()))
>  self.add('includes += ["%s" % (i[2:].replace("@CPU@", 
> "x86"))]')
> -for i in builder.includes():
> +for i in builder.includes() + ['-I' + builder.buildInclude()]:
>  self.add('includes += ["%s"]' % (i[2:]))
>  self.add('')
>  self.add('# Collect the libbsd uses')
> @@ -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')
> +self.add('header_build_copy_paths = [')
> +for hp in builder.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("%s", headers[2])' % 
> (buil

Re: [PATCH 3/3] waf: Move glob operator ** to builder.py

2017-08-10 Thread Chris Johns
OK.

On 11/08/2017 04:14, Christian Mauderer wrote:
> From: Christian Mauderer 
> 
> This allows a finer decision which headers should be installed.
> ---
>  builder.py   | 26 +-
>  libbsd_waf.py| 30 +++---
>  waf_generator.py |  4 ++--
>  3 files changed, 30 insertions(+), 30 deletions(-)
> 
> diff --git a/builder.py b/builder.py
> index 92a83dd8..21173992 100755
> --- a/builder.py
> +++ b/builder.py
> @@ -220,16 +220,16 @@ def headerPaths():
>  normal installation path. """
>  
>  # local path  wildcard dest path
> -return [('rtemsbsd/include',  '*.h',   ''),
> +return [('rtemsbsd/include',  '**/*.h',''),
>  ('rtemsbsd/mghttpd',  'mongoose.h',
> 'mghttpd'),
> -('freebsd/include',   '*.h',   ''),
> -('freebsd/sys/bsm',   '*.h',   'bsm'),
> -('freebsd/sys/cam',   '*.h',   'cam'),
> -('freebsd/sys/net',   '*.h',   'net'),
> -('freebsd/sys/net80211',  '*.h',   
> 'net80211'),
> -('freebsd/sys/netinet',   '*.h',   
> 'netinet'),
> -('freebsd/sys/netinet6',  '*.h',   
> 'netinet6'),
> -('freebsd/sys/netipsec',  '*.h',   
> 'netipsec'),
> +('freebsd/include',   '**/*.h',''),
> +('freebsd/sys/bsm',   '**/*.h','bsm'),
> +('freebsd/sys/cam',   '**/*.h','cam'),
> +('freebsd/sys/net',   '**/*.h','net'),
> +('freebsd/sys/net80211',  '**/*.h',
> 'net80211'),
> +('freebsd/sys/netinet',   '**/*.h',
> 'netinet'),
> +('freebsd/sys/netinet6',  '**/*.h',
> 'netinet6'),
> +('freebsd/sys/netipsec',  '**/*.h',
> 'netipsec'),
>  ('freebsd/crypto/openssl', '*.h', 'openssl'),
>  ('freebsd/crypto/openssl/crypto', '*.h', 'openssl'),
>  ('freebsd/crypto/openssl/crypto', 
> '(opensslconf|opensslv|crypto).h', 'openssl'),
> @@ -288,10 +288,10 @@ def headerPaths():
>  ('freebsd/crypto/openssl/crypto/cmac', 'cmac.h',   
> 'openssl'),
>  ('freebsd/crypto/openssl/ssl', '(ssl|kssl|ssl2).h', 'openssl'),
>  ('freebsd/crypto/openssl/ssl', '*.h', 'openssl'),
> -('freebsd/sys/rpc',   '*.h',   'rpc'),
> -('freebsd/sys/sys',   '*.h',   'sys'),
> -('freebsd/sys/vm','*.h',   'vm'),
> -('freebsd/sys/dev/mii',   '*.h',   
> 'dev/mii'),
> +('freebsd/sys/rpc',   '**/*.h','rpc'),
> +('freebsd/sys/sys',   '**/*.h','sys'),
> +('freebsd/sys/vm','**/*.h','vm'),
> +('freebsd/sys/dev/mii',   '**/*.h',
> 'dev/mii'),
>  ('mDNSResponder/mDNSCore','mDNSDebug.h',   ''),
>  ('mDNSResponder/mDNSCore','mDNSEmbeddedAPI.h', ''),
>  ('mDNSResponder/mDNSShared',  'dns_sd.h',  ''),
> diff --git a/libbsd_waf.py b/libbsd_waf.py
> index 4d69e628..499a85ad 100644
> --- a/libbsd_waf.py
> +++ b/libbsd_waf.py
> @@ -187,7 +187,7 @@ def build(bld):
>  for headers in header_build_copy_paths:
>  target = os.path.join("build-include", headers[2])
>  start_dir = bld.path.find_dir(headers[0])
> -for header in start_dir.ant_glob("**/" + headers[1]):
> +for header in start_dir.ant_glob(headers[1]):
>  relsourcepath = header.path_from(start_dir)
>  targetheader = os.path.join(target, relsourcepath)
>  bld(features = 'subst',
> @@ -2292,16 +2292,16 @@ def build(bld):
>  
>  # Installs.
>  bld.install_files("${PREFIX}/" + 
> rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP), 
> ["libbsd.a"])
> -header_paths = [('rtemsbsd/include', '*.h', ''),
> +header_paths = [('rtemsbsd/include', '**/*.h', ''),
>   ('rtemsbsd/mghttpd', 'mongoose.h', 'mghttpd'),
> - ('freebsd/include', '*.h', ''),
> - ('freebsd/sys/bsm', '*.h', 'bsm'),
> - ('freebsd/sys/cam', '*.h', 'cam'),
> - ('freebsd/sys/net', '*.h', 'net'),
> - ('freebsd/sys/net80211', '*.h', 'net80211'),
> - ('freebsd/sys/netinet', '*.h', 'netinet'),
> - ('freebsd/sys/netinet6', '*.h', 'netinet6'),
> - ('freebs

[PATCH v2 3/3] waf: Move glob operator ** to builder.py

2017-08-10 Thread Christian Mauderer
From: Christian Mauderer 

This allows a finer decision which headers should be installed.
---
 builder.py   | 26 +-
 libbsd_waf.py| 30 +++---
 waf_generator.py |  4 ++--
 3 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/builder.py b/builder.py
index 92a83dd8..21173992 100755
--- a/builder.py
+++ b/builder.py
@@ -220,16 +220,16 @@ def headerPaths():
 normal installation path. """
 
 # local path  wildcard dest path
-return [('rtemsbsd/include',  '*.h',   ''),
+return [('rtemsbsd/include',  '**/*.h',''),
 ('rtemsbsd/mghttpd',  'mongoose.h','mghttpd'),
-('freebsd/include',   '*.h',   ''),
-('freebsd/sys/bsm',   '*.h',   'bsm'),
-('freebsd/sys/cam',   '*.h',   'cam'),
-('freebsd/sys/net',   '*.h',   'net'),
-('freebsd/sys/net80211',  '*.h',   'net80211'),
-('freebsd/sys/netinet',   '*.h',   'netinet'),
-('freebsd/sys/netinet6',  '*.h',   'netinet6'),
-('freebsd/sys/netipsec',  '*.h',   'netipsec'),
+('freebsd/include',   '**/*.h',''),
+('freebsd/sys/bsm',   '**/*.h','bsm'),
+('freebsd/sys/cam',   '**/*.h','cam'),
+('freebsd/sys/net',   '**/*.h','net'),
+('freebsd/sys/net80211',  '**/*.h','net80211'),
+('freebsd/sys/netinet',   '**/*.h','netinet'),
+('freebsd/sys/netinet6',  '**/*.h','netinet6'),
+('freebsd/sys/netipsec',  '**/*.h','netipsec'),
 ('freebsd/crypto/openssl', '*.h', 'openssl'),
 ('freebsd/crypto/openssl/crypto', '*.h', 'openssl'),
 ('freebsd/crypto/openssl/crypto', 
'(opensslconf|opensslv|crypto).h', 'openssl'),
@@ -288,10 +288,10 @@ def headerPaths():
 ('freebsd/crypto/openssl/crypto/cmac', 'cmac.h',   
'openssl'),
 ('freebsd/crypto/openssl/ssl', '(ssl|kssl|ssl2).h', 'openssl'),
 ('freebsd/crypto/openssl/ssl', '*.h', 'openssl'),
-('freebsd/sys/rpc',   '*.h',   'rpc'),
-('freebsd/sys/sys',   '*.h',   'sys'),
-('freebsd/sys/vm','*.h',   'vm'),
-('freebsd/sys/dev/mii',   '*.h',   'dev/mii'),
+('freebsd/sys/rpc',   '**/*.h','rpc'),
+('freebsd/sys/sys',   '**/*.h','sys'),
+('freebsd/sys/vm','**/*.h','vm'),
+('freebsd/sys/dev/mii',   '**/*.h','dev/mii'),
 ('mDNSResponder/mDNSCore','mDNSDebug.h',   ''),
 ('mDNSResponder/mDNSCore','mDNSEmbeddedAPI.h', ''),
 ('mDNSResponder/mDNSShared',  'dns_sd.h',  ''),
diff --git a/libbsd_waf.py b/libbsd_waf.py
index 8800f9b9..499a85ad 100644
--- a/libbsd_waf.py
+++ b/libbsd_waf.py
@@ -187,7 +187,7 @@ def build(bld):
 for headers in header_build_copy_paths:
 target = os.path.join("build-include", headers[2])
 start_dir = bld.path.find_dir(headers[0])
-for header in start_dir.ant_glob(os.path.join("**/", headers[1])):
+for header in start_dir.ant_glob(headers[1]):
 relsourcepath = header.path_from(start_dir)
 targetheader = os.path.join(target, relsourcepath)
 bld(features = 'subst',
@@ -2292,16 +2292,16 @@ def build(bld):
 
 # Installs.
 bld.install_files("${PREFIX}/" + 
rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP), 
["libbsd.a"])
-header_paths = [('rtemsbsd/include', '*.h', ''),
+header_paths = [('rtemsbsd/include', '**/*.h', ''),
  ('rtemsbsd/mghttpd', 'mongoose.h', 'mghttpd'),
- ('freebsd/include', '*.h', ''),
- ('freebsd/sys/bsm', '*.h', 'bsm'),
- ('freebsd/sys/cam', '*.h', 'cam'),
- ('freebsd/sys/net', '*.h', 'net'),
- ('freebsd/sys/net80211', '*.h', 'net80211'),
- ('freebsd/sys/netinet', '*.h', 'netinet'),
- ('freebsd/sys/netinet6', '*.h', 'netinet6'),
- ('freebsd/sys/netipsec', '*.h', 'netipsec'),
+ ('freebsd/include', '**/*.h', ''),
+ ('freebsd/sys/bsm', '**/*.h', 'bsm'),
+ ('freebsd/sys/cam', '**/*.h', 'cam'),
+ ('freebs

[PATCH v2 1/3] waf_generator: Copy headers if necessary.

2017-08-10 Thread Christian Mauderer
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
. 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   | 14 ++
 libbsd_waf.py| 15 +++
 waf_generator.py | 24 +++-
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/builder.py b/builder.py
index bb633cb2..1be1ced1 100755
--- a/builder.py
+++ b/builder.py
@@ -194,6 +194,10 @@ def includes():
 '-ImDNSResponder/mDNSPosix',
 '-Itestsuite/include']
 
+def buildInclude():
+""" Returns the path where headers will be copied during build. """
+return 'build-include'
+
 def cpuIncludes():
 return ['-Irtemsbsd/@CPU@/include',
 '-Ifreebsd/sys/@CPU@/include']
@@ -205,6 +209,16 @@ def cxxflags():
 return []
 
 def headerPaths():
+""" Returns a list of information about what header files should be
+installed.
+
+The list is also used to find headers with a local path that doesn't match
+it's dest path. Due to the difference in the path name such files are
+problematic during the build if they are included using their later
+installation path (dest path) name. Therefore they are copied into a
+sub-directory of the build path so that they can be included with their
+normal installation path. """
+
 # local path  wildcard dest path
 return [('rtemsbsd/include',  '*.h',   ''),
 ('rtemsbsd/mghttpd',  'mongoose.h','mghttpd'),
diff --git a/libbsd_waf.py b/libbsd_waf.py
index aee2e7ad..8bc2b348 100644
--- a/libbsd_waf.py
+++ b/libbsd_waf.py
@@ -83,6 +83,7 @@ def build(bld):
 includes += ["mDNSResponder/mDNSShared"]
 includes += ["mDNSResponder/mDNSPosix"]
 includes += ["testsuite/include"]
+includes += ["build-include"]
 
 # Collect the libbsd uses
 libbsd_use = []
@@ -123,6 +124,20 @@ 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("build-include", headers[2])
+start_dir = bld.path.find_dir(headers[0])
+for header in start_dir.ant_glob(os.path.join("**/", headers[1])):
+relsourcepath = header.path_from(start_dir)
+targetheader = os.path.join(target, relsourcepath)
+bld(features = 'subst',
+target = targetheader,
+source = header,
+is_copy = True)
+
 # 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..fdc2210f 100755
--- a/waf_generator.py
+++ b/waf_generator.py
@@ -392,7 +392,7 @@ class ModuleManager(builder.ModuleManager):
 self.add('if bld.get_env()["RTEMS_ARCH"] == "i386":')
 self.add('for i in %r:' % (builder.cpuIncludes()))
 self.add('includes += ["%s" % (i[2:].replace("@CPU@", 
"x86"))]')
-for i in builder.includes():
+for i in builder.includes() + ['-I' + builder.buildInclude()]:
 self.add('includes += ["%s"]' % (i[2:]))
 self.add('')
 self.add('# Collect the libbsd uses')
@@ -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')
+self.add('header_build_copy_paths = [')
+for hp in builder.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("%s", headers[2])' % 
(builder.buildInclude()))
+self.add('start_dir = bld.path.find_dir(headers[0])')
+self.add('for header in start_dir.ant_glob(os.path.join("**/", 
headers[1])):')
+self.add('relsourcepath = header.path_from(start_dir)')
+self.add('targetheader = os.path.join(target, 
relsourcepath)')
+self.add('bld(features =