Index: libbsd.py
===================================================================
--- libbsd.py	(revision 8189ea825a2c1a3c7ed8df3d2fc0d1df078a4e31)
+++ libbsd.py	(revision f7a09b59853bae31861e572f5d5cde42f762c233)
@@ -1,4 +1,5 @@
 #
-#  Copyright (c) 2015-2016 Chris Johns <chrisj@rtems.org>. All rights reserved.
+#  Copyright (c) 2015-2016, 2018 Chris Johns <chrisj@rtems.org>.
+#  All rights reserved.
 #
 #  Copyright (c) 2009, 2018 embedded brains GmbH.  All rights reserved.
@@ -36,8 +37,150 @@
 
 #
-# RTEMS version
-#
-def rtems_version():
-    return '4.12'
+# Default configuration.
+#
+_defaults = {
+    #
+    # Compile flags
+    #
+    'common-flags': ['-g',
+                     '-fno-strict-aliasing',
+                     '-ffreestanding',
+                     '-fno-common'],
+    'common-warnings' : ['-Wall',
+                         '-Wno-format',
+                         '-Wno-pointer-sign'],
+    'common-no-warnings': ['-w'],
+    'cflags': [],
+    'cxxflags': [],
+
+    #
+    # Includes
+    #
+    'include-paths': ['rtemsbsd/include',
+                      'freebsd/sys',
+                      'freebsd/sys/contrib/pf',
+                      'freebsd/crypto',
+                      'freebsd/sys/net',
+                      'freebsd/include',
+                      'freebsd/lib',
+                      'freebsd/lib/libbsdstat',
+                      'freebsd/lib/libc/include',
+                      'freebsd/lib/libc/isc/include',
+                      'freebsd/lib/libc/resolv',
+                      'freebsd/lib/libutil',
+                      'freebsd/lib/libkvm',
+                      'freebsd/lib/libmemstat',
+                      'freebsd/lib/libipsec',
+                      'freebsd/contrib/expat/lib',
+                      'freebsd/contrib/libpcap',
+                      'freebsd/contrib/libxo',
+                      'linux/include',
+                      'linux/drivers/net/ethernet/freescale/fman',
+                      'rtemsbsd/sys',
+                      'mDNSResponder/mDNSCore',
+                      'mDNSResponder/mDNSShared',
+                      'mDNSResponder/mDNSPosix',
+                      'testsuite/include'],
+    'cpu-include-paths': ['rtemsbsd/@CPU@/include',
+                          'freebsd/sys/@CPU@/include'],
+
+    # The path where headers will be copied during build.
+    'build-include-path': ['build-include'],
+
+    #
+    # Install headers
+    #
+    # 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.
+    #
+    'header-paths':
+    #  local path                               wildcard                           dest path
+    [('rtemsbsd/include',                       '**/*.h',                          ''),
+     ('rtemsbsd/@CPU@/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/contrib/libpcap',                '*.h',                             ''),
+     ('freebsd/contrib/libpcap/pcap',           '*.h',                             'pcap'),
+     ('freebsd/crypto/openssl',                 '*.h',                             'openssl'),
+     ('freebsd/crypto/openssl/crypto',          '*.h',                             'openssl'),
+     ('freebsd/crypto/openssl/ssl',             '(ssl|kssl|ssl2).h',               'openssl'),
+     ('freebsd/crypto/openssl/crypto/aes',      'aes.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/err',      'err.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/bio',      '*.h',                             'openssl'),
+     ('freebsd/crypto/openssl/crypto/dsa',      '*.h',                             'openssl'),
+     ('freebsd/crypto/openssl/ssl',             '*.h',                             'openssl'),
+     ('freebsd/crypto/openssl/crypto/bn',       'bn.h',                            'openssl'),
+     ('freebsd/crypto/openssl/crypto/x509',     'x509.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/cast',     'cast.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/lhash',    'lhash.h',                         'openssl'),
+     ('freebsd/crypto/openssl/crypto/ecdh',     'ecdh.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/ecdsa',    'ecdsa.h',                         'openssl'),
+     ('freebsd/crypto/openssl/crypto/idea',     'idea.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/mdc2',     'mdc2.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/md4',      'md4.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/md5',      'md5.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/rc2',      'rc2.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/rc4',      'rc4.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/ripemd',   'ripemd.h',                        'openssl'),
+     ('freebsd/crypto/openssl/crypto/seed',     'seed.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/sha',      'sha.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/x509v3',   'x509v3.h',                        'openssl'),
+     ('freebsd/crypto/openssl/crypto/x509',     'x509_vfy.h',                      'openssl'),
+     ('freebsd/crypto/openssl/crypto/buffer',   'buffer.h',                        'openssl'),
+     ('freebsd/crypto/openssl/crypto/comp',     'comp.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/asn1',     'asn1_mac.h',                      'openssl'),
+     ('freebsd/crypto/openssl/crypto/pem',      '(pem|pem2).h',                    'openssl'),
+     ('freebsd/crypto/openssl/crypto/rsa',      'rsa.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/evp',      'evp.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/ec',       'ec.h',                            'openssl'),
+     ('freebsd/crypto/openssl/crypto/engine',   'engine.h',                        'openssl'),
+     ('freebsd/crypto/openssl/crypto/pkcs7',    'pkcs7.h',                         'openssl'),
+     ('freebsd/crypto/openssl/crypto/hmac',     'hmac.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/pqueue',   'pqueue.h',                        'openssl'),
+     ('freebsd/crypto/openssl/crypto/ocsp',     'ocsp.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/rand',     'rand.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/srp',      'srp.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/dh',       'dh.h',                            'openssl'),
+     ('freebsd/crypto/openssl/crypto/dso',      'dso.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/krb5',     'krb5_asn.h',                      'openssl'),
+     ('freebsd/crypto/openssl/crypto/cms',      'cms.h',                           'openssl'),
+     ('freebsd/crypto/openssl/crypto/txt_db',   'txt_db.h',                        'openssl'),
+     ('freebsd/crypto/openssl/crypto/ts',       'ts.h',                            'openssl'),
+     ('freebsd/crypto/openssl/crypto/modes',    'modes.h',                         'openssl'),
+     ('freebsd/crypto/openssl/crypto/pkcs12',   'pkcs12.h',                        'openssl'),
+     ('freebsd/crypto/openssl/crypto/bf',       'blowfish.h',                      'openssl'),
+     ('freebsd/crypto/openssl/crypto/cmac',     'cmac.h',                          'openssl'),
+     ('freebsd/crypto/openssl/crypto/asn1',     '(asn1|asn1t).h',                  'openssl'),
+     ('freebsd/crypto/openssl/crypto/camellia', 'camellia.h',                      'openssl'),
+     ('freebsd/crypto/openssl/crypto/objects',  '(objects|obj_mac).h',             'openssl'),
+     ('freebsd/crypto/openssl/crypto/conf',     '(conf|conf_api).h',               'openssl'),
+     ('freebsd/crypto/openssl/crypto/des',      '(des|des_old).h',                 'openssl'),
+     ('freebsd/crypto/openssl/crypto/ui',       '(ui_compat|ui).h',                'openssl'),
+     ('freebsd/crypto/openssl/crypto/whrlpool', 'whrlpool.h',                      'openssl'),
+     ('freebsd/crypto/openssl/crypto/stack',    '(stack|safestack).h',             'openssl'),
+     ('freebsd/crypto/openssl/crypto',          '(opensslconf|opensslv|crypto).h', 'openssl'),
+     ('freebsd/sys/rpc',                        '**/*.h',                          'rpc'),
+     ('freebsd/sys/sys',                        '**/*.h',                          'sys'),
+     ('freebsd/sys/vm',                         '**/*.h',                          'vm'),
+     ('freebsd/sys/dev/mii',                    '**/*.h',                          'dev/mii'),
+     ('linux/include',                          '**/*.h',                          ''),
+     ('mDNSResponder/mDNSCore',                 'mDNSDebug.h',                     ''),
+     ('mDNSResponder/mDNSCore',                 'mDNSEmbeddedAPI.h',               ''),
+     ('mDNSResponder/mDNSShared',               'dns_sd.h',                        ''),
+     ('mDNSResponder/mDNSPosix',                'mDNSPosix.h',                     '')]
+}
 
 #
@@ -4369,5 +4512,149 @@
 
 #
+# DHCP
+#
+def dhcpcd(mm):
+    mod = builder.Module('dhcpcd')
+    mod.addSourceFiles(
+        [
+            'dhcpcd/arp.c',
+            'dhcpcd/auth.c',
+            'dhcpcd/bpf.c',
+            'dhcpcd/common.c',
+            'dhcpcd/dhcp6.c',
+            'dhcpcd/dhcp.c',
+            'dhcpcd/dhcpcd.c',
+            'dhcpcd/dhcpcd-embedded.c',
+            'dhcpcd/dhcp-common.c',
+            'dhcpcd/duid.c',
+            'dhcpcd/eloop.c',
+            'dhcpcd/if-bsd.c',
+            'dhcpcd/if-options.c',
+            'dhcpcd/if-pref.c',
+            'dhcpcd/ipv4.c',
+            'dhcpcd/ipv4ll.c',
+            'dhcpcd/ipv6.c',
+            'dhcpcd/ipv6nd.c',
+            'dhcpcd/net.c',
+            'dhcpcd/platform-bsd.c',
+            'dhcpcd/compat/pselect.c',
+            'dhcpcd/crypt/hmac_md5.c',
+        ],
+        mm.generator['source']('-D__FreeBSD__ -DTHERE_IS_NO_FORK -DMASTER_ONLY -DINET -DINET6')
+    )
+    mod.addRTEMSSourceFiles(
+        [
+            'rtems/rtems-bsd-shell-dhcpcd.c',
+        ],
+        mm.generator['source']()
+    )
+    return mod
+
+#
+# MDNS Responder
+#
+def mdnsresponder(mm):
+    mod = builder.Module('mdnsresponder')
+    mod.addSourceFiles(
+        [
+            'mDNSResponder/mDNSCore/anonymous.c',
+            'mDNSResponder/mDNSCore/CryptoAlg.c',
+            'mDNSResponder/mDNSCore/DNSCommon.c',
+            'mDNSResponder/mDNSCore/DNSDigest.c',
+            'mDNSResponder/mDNSCore/mDNS.c',
+            'mDNSResponder/mDNSCore/uDNS.c',
+            'mDNSResponder/mDNSShared/dnssd_clientshim.c',
+            'mDNSResponder/mDNSShared/mDNSDebug.c',
+            'mDNSResponder/mDNSShared/PlatformCommon.c',
+            'mDNSResponder/mDNSShared/GenLinkedList.c',
+            'mDNSResponder/mDNSPosix/mDNSPosix.c',
+            'mDNSResponder/mDNSPosix/mDNSUNP.c',
+        ],
+        mm.generator['source']()
+    )
+    return mod
+
+#
+# Mongoose HTTP
+#
+def mghttpd(mm):
+    mod = builder.Module('mghttpd')
+    mod.addSourceFiles(
+        [
+            'rtemsbsd/mghttpd/mongoose.c',
+        ],
+        mm.generator['source']('-DNO_SSL -DNO_POPEN -DNO_CGI -DUSE_WEBSOCKET')
+    )
+    return mod
+
+def dpaa(mm):
+    mod = builder.Module('dpaa')
+    mod.addLinuxHeaderFiles(
+        [
+            'include/soc/fsl/bman.h',
+            'include/soc/fsl/qman.h',
+            'drivers/net/ethernet/freescale/fman/mac.h',
+            'drivers/net/ethernet/freescale/fman/fman.h',
+            'drivers/net/ethernet/freescale/fman/fman_tgec.h',
+            'drivers/net/ethernet/freescale/fman/fman_mac.h',
+            'drivers/net/ethernet/freescale/fman/fman_muram.h',
+            'drivers/net/ethernet/freescale/fman/fman_port.h',
+            'drivers/net/ethernet/freescale/fman/fman_dtsec.h',
+            'drivers/net/ethernet/freescale/fman/fman_memac.h',
+            'drivers/net/ethernet/freescale/fman/fman_sp.h',
+            'drivers/net/ethernet/freescale/dpaa/dpaa_eth.h',
+            'drivers/net/ethernet/freescale/dpaa/dpaa_eth_trace.h',
+            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth.h',
+            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.h',
+            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_common.h',
+            'drivers/soc/fsl/qbman/qman_priv.h',
+            'drivers/soc/fsl/qbman/bman_test.h',
+            'drivers/soc/fsl/qbman/dpaa_sys.h',
+            'drivers/soc/fsl/qbman/bman_priv.h',
+            'drivers/soc/fsl/qbman/qman_test.h',
+        ]
+    )
+    mod.addCPUDependentLinuxSourceFiles(
+        [ 'powerpc' ],
+        [
+            'drivers/net/ethernet/freescale/dpaa/dpaa_eth.c',
+            'drivers/net/ethernet/freescale/fman/fman.c',
+            'drivers/net/ethernet/freescale/fman/fman_dtsec.c',
+            'drivers/net/ethernet/freescale/fman/fman_memac.c',
+            'drivers/net/ethernet/freescale/fman/fman_port.c',
+            'drivers/net/ethernet/freescale/fman/fman_sp.c',
+            'drivers/net/ethernet/freescale/fman/fman_tgec.c',
+            'drivers/net/ethernet/freescale/fman/mac.c',
+            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.c',
+            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_macless.c',
+            'drivers/soc/fsl/qbman/bman.c',
+            'drivers/soc/fsl/qbman/bman_ccsr.c',
+            'drivers/soc/fsl/qbman/bman_test_api.c',
+            'drivers/soc/fsl/qbman/qman.c',
+            'drivers/soc/fsl/qbman/qman_ccsr.c',
+            'drivers/soc/fsl/qbman/qman_portal.c',
+            'drivers/soc/fsl/qbman/qman_test_api.c',
+            'drivers/soc/fsl/qbman/qman_test_stash.c',
+        ],
+        mm.generator['source']()
+    )
+    mod.addCPUDependentRTEMSSourceFiles(
+        [ 'powerpc' ],
+        [
+            'sys/powerpc/compat.c',
+            'sys/powerpc/fdt_phy.c',
+            'sys/powerpc/fman_muram.c',
+            'sys/powerpc/linux_compat.c',
+            'sys/powerpc/drivers/net/ethernet/freescale/dpaa/if_fmanmac.c',
+            'sys/powerpc/drivers/net/ethernet/freescale/sdk_dpaa/if_ml.c',
+        ],
+        mm.generator['source']()
+    )
+    return mod
+
+#
 # Tests
+#
+#  Note: Keep as the last module
 #
 def tests(mm):
@@ -4448,147 +4735,8 @@
     return mod
 
-#
-# DHCP
-#
-def dhcpcd(mm):
-    mod = builder.Module('dhcpcd')
-    mod.addSourceFiles(
-        [
-            'dhcpcd/arp.c',
-            'dhcpcd/auth.c',
-            'dhcpcd/bpf.c',
-            'dhcpcd/common.c',
-            'dhcpcd/dhcp6.c',
-            'dhcpcd/dhcp.c',
-            'dhcpcd/dhcpcd.c',
-            'dhcpcd/dhcpcd-embedded.c',
-            'dhcpcd/dhcp-common.c',
-            'dhcpcd/duid.c',
-            'dhcpcd/eloop.c',
-            'dhcpcd/if-bsd.c',
-            'dhcpcd/if-options.c',
-            'dhcpcd/if-pref.c',
-            'dhcpcd/ipv4.c',
-            'dhcpcd/ipv4ll.c',
-            'dhcpcd/ipv6.c',
-            'dhcpcd/ipv6nd.c',
-            'dhcpcd/net.c',
-            'dhcpcd/platform-bsd.c',
-            'dhcpcd/compat/pselect.c',
-            'dhcpcd/crypt/hmac_md5.c',
-        ],
-        mm.generator['source']('-D__FreeBSD__ -DTHERE_IS_NO_FORK -DMASTER_ONLY -DINET -DINET6')
-    )
-    mod.addRTEMSSourceFiles(
-        [
-            'rtems/rtems-bsd-shell-dhcpcd.c',
-        ],
-        mm.generator['source']()
-    )
-    return mod
-
-#
-# MDNS Responder
-#
-def mdnsresponder(mm):
-    mod = builder.Module('mdnsresponder')
-    mod.addSourceFiles(
-        [
-            'mDNSResponder/mDNSCore/anonymous.c',
-            'mDNSResponder/mDNSCore/CryptoAlg.c',
-            'mDNSResponder/mDNSCore/DNSCommon.c',
-            'mDNSResponder/mDNSCore/DNSDigest.c',
-            'mDNSResponder/mDNSCore/mDNS.c',
-            'mDNSResponder/mDNSCore/uDNS.c',
-            'mDNSResponder/mDNSShared/dnssd_clientshim.c',
-            'mDNSResponder/mDNSShared/mDNSDebug.c',
-            'mDNSResponder/mDNSShared/PlatformCommon.c',
-            'mDNSResponder/mDNSShared/GenLinkedList.c',
-            'mDNSResponder/mDNSPosix/mDNSPosix.c',
-            'mDNSResponder/mDNSPosix/mDNSUNP.c',
-        ],
-        mm.generator['source']()
-    )
-    return mod
-
-#
-# Mongoose HTTP
-#
-def mghttpd(mm):
-    mod = builder.Module('mghttpd')
-    mod.addSourceFiles(
-        [
-            'rtemsbsd/mghttpd/mongoose.c',
-        ],
-        mm.generator['source']('-DNO_SSL -DNO_POPEN -DNO_CGI -DUSE_WEBSOCKET')
-    )
-    return mod
-
-def dpaa(mm):
-    mod = builder.Module('dpaa')
-    mod.addLinuxHeaderFiles(
-        [
-            'include/soc/fsl/bman.h',
-            'include/soc/fsl/qman.h',
-            'drivers/net/ethernet/freescale/fman/mac.h',
-            'drivers/net/ethernet/freescale/fman/fman.h',
-            'drivers/net/ethernet/freescale/fman/fman_tgec.h',
-            'drivers/net/ethernet/freescale/fman/fman_mac.h',
-            'drivers/net/ethernet/freescale/fman/fman_muram.h',
-            'drivers/net/ethernet/freescale/fman/fman_port.h',
-            'drivers/net/ethernet/freescale/fman/fman_dtsec.h',
-            'drivers/net/ethernet/freescale/fman/fman_memac.h',
-            'drivers/net/ethernet/freescale/fman/fman_sp.h',
-            'drivers/net/ethernet/freescale/dpaa/dpaa_eth.h',
-            'drivers/net/ethernet/freescale/dpaa/dpaa_eth_trace.h',
-            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth.h',
-            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.h',
-            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_common.h',
-            'drivers/soc/fsl/qbman/qman_priv.h',
-            'drivers/soc/fsl/qbman/bman_test.h',
-            'drivers/soc/fsl/qbman/dpaa_sys.h',
-            'drivers/soc/fsl/qbman/bman_priv.h',
-            'drivers/soc/fsl/qbman/qman_test.h',
-        ]
-    )
-    mod.addCPUDependentLinuxSourceFiles(
-        [ 'powerpc' ],
-        [
-            'drivers/net/ethernet/freescale/dpaa/dpaa_eth.c',
-            'drivers/net/ethernet/freescale/fman/fman.c',
-            'drivers/net/ethernet/freescale/fman/fman_dtsec.c',
-            'drivers/net/ethernet/freescale/fman/fman_memac.c',
-            'drivers/net/ethernet/freescale/fman/fman_port.c',
-            'drivers/net/ethernet/freescale/fman/fman_sp.c',
-            'drivers/net/ethernet/freescale/fman/fman_tgec.c',
-            'drivers/net/ethernet/freescale/fman/mac.c',
-            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.c',
-            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_macless.c',
-            'drivers/soc/fsl/qbman/bman.c',
-            'drivers/soc/fsl/qbman/bman_ccsr.c',
-            'drivers/soc/fsl/qbman/bman_test_api.c',
-            'drivers/soc/fsl/qbman/qman.c',
-            'drivers/soc/fsl/qbman/qman_ccsr.c',
-            'drivers/soc/fsl/qbman/qman_portal.c',
-            'drivers/soc/fsl/qbman/qman_test_api.c',
-            'drivers/soc/fsl/qbman/qman_test_stash.c',
-        ],
-        mm.generator['source']()
-    )
-    mod.addCPUDependentRTEMSSourceFiles(
-        [ 'powerpc' ],
-        [
-            'sys/powerpc/compat.c',
-            'sys/powerpc/fdt_phy.c',
-            'sys/powerpc/fman_muram.c',
-            'sys/powerpc/linux_compat.c',
-            'sys/powerpc/drivers/net/ethernet/freescale/dpaa/if_fmanmac.c',
-            'sys/powerpc/drivers/net/ethernet/freescale/sdk_dpaa/if_ml.c',
-        ],
-        mm.generator['source']()
-    )
-    return mod
-
-def sources(mm):
+def load(mm):
+
+    mm.setConfiguration(_defaults)
+
     mm.addModule(dpaa(mm))
     mm.addModule(rtems(mm))
@@ -4660,9 +4808,10 @@
     mm.addModule(crypto_openssl(mm))
 
-    mm.addModule(tests(mm))
     mm.addModule(dhcpcd(mm))
     mm.addModule(mghttpd(mm))
     mm.addModule(mdnsresponder(mm))
 
+    mm.addModule(tests(mm))
+
     # XXX TODO Check that no file is also listed in empty
     # XXX TODO Check that no file in in two modules
