waf: make all generators depend on their rules
[metze/samba/wip.git] / buildtools / wafsamba / wafsamba.py
index 35b39d365262392521a48500961f08154af97487..3ce44559292162e5e0c490407c99ab43114f3ac6 100644 (file)
@@ -23,11 +23,13 @@ import samba_conftests
 import samba_abi
 import tru64cc
 import irixcc
+import hpuxcc
 import generic_cc
 import samba_dist
 import samba_wildcard
 import stale_files
 import symbols
+import pkgconfig
 
 # some systems have broken threading in python
 if os.environ.get('WAF_NOTHREADS') == '1':
@@ -55,6 +57,7 @@ def SAMBA_BUILD_ENV(conf):
     '''create the samba build environment'''
     conf.env.BUILD_DIRECTORY = conf.blddir
     mkdir_p(os.path.join(conf.blddir, LIB_PATH))
+    mkdir_p(os.path.join(conf.blddir, LIB_PATH, "private"))
     mkdir_p(os.path.join(conf.blddir, "modules"))
     mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc'))
     # this allows all of the bin/shared and bin/python targets
@@ -100,6 +103,7 @@ def SAMBA_LIBRARY(bld, libname, source,
                   vnum=None,
                   soname=None,
                   cflags='',
+                  ldflags='',
                   external_library=False,
                   realname=None,
                   autoproto=None,
@@ -185,11 +189,24 @@ def SAMBA_LIBRARY(bld, libname, source,
     else:
         bundled_name = PRIVATE_NAME(bld, libname, bundled_extension, private_library)
 
+    ldflags = TO_LIST(ldflags)
+
     if private_library:
         if vnum:
             Logs.error("vnum is invalid for private libraries")
             sys.exit(1)
-        vnum = Utils.g_module.VERSION
+        vnum = Utils.g_module.VERSION.split(".")[0]
+        version = "%s_%s" % (Utils.g_module.APPNAME, Utils.g_module.VERSION)
+    else:
+        version = "%s_%s" % (Utils.g_module.APPNAME, Utils.g_module.VERSION.split(".")[0])
+
+    if bld.env.HAVE_LD_VERSION_SCRIPT:
+        vscript = "%s.vscript" % libname
+        bld.SAMBA_GENERATOR(vscript,
+                            rule="echo %s \{ global: \*\; \}\; > ${TGT}" % version.replace("-","_").upper(),
+                            group='vscripts',
+                            target=vscript)
+        ldflags.append("-Wl,--version-script=%s/%s" % (bld.path.abspath(bld.env), vscript))
 
     features = 'cc cshlib symlink_lib install_lib'
     if target_type == 'PYTHON':
@@ -210,6 +227,7 @@ def SAMBA_LIBRARY(bld, libname, source,
         source          = [],
         target          = bundled_name,
         depends_on      = depends_on,
+        ldflags                = ldflags,
         samba_deps      = deps,
         samba_includes  = includes,
         local_include   = local_include,
@@ -336,9 +354,9 @@ def SAMBA_MODULE(bld, modname, source,
                  includes='',
                  subsystem=None,
                  init_function=None,
+                 module_init_name='samba_init_module',
                  autoproto=None,
                  autoproto_extra_source='',
-                 aliases=None,
                  cflags='',
                  internal_module=True,
                  local_include=True,
@@ -367,37 +385,6 @@ def SAMBA_MODULE(bld, modname, source,
         SET_TARGET_TYPE(bld, modname, 'DISABLED')
         return
 
-    if aliases is not None:
-        # if we have aliases, then create a private base library, and a set
-        # of modules on top of that library
-        if init_function:
-            cflags += " -D%s=samba_init_module" % init_function
-
-        basename = modname + '-base'
-        bld.SAMBA_LIBRARY(basename,
-                          source,
-                          deps=deps,
-                          cflags=cflags,
-                          autoproto = autoproto,
-                          local_include=local_include,
-                          vars=vars,
-                          pyembed=pyembed,
-                          private_library=True
-                          )
-
-        aliases = TO_LIST(aliases)
-        aliases.append(modname)
-
-        for alias in aliases:
-            bld.SAMBA_MODULE(alias,
-                             source=[],
-                             internal_module=False,
-                             subsystem=subsystem,
-                             init_function=init_function,
-                             deps=basename)
-        return
-
-
     obj_target = modname + '.objlist'
 
     realname = modname
@@ -415,7 +402,7 @@ def SAMBA_MODULE(bld, modname, source,
     build_link_name = "modules/%s/%s" % (subsystem, realname)
 
     if init_function:
-        cflags += " -D%s=samba_init_module" % init_function
+        cflags += " -D%s=%s" % (init_function, module_init_name)
 
     bld.SAMBA_LIBRARY(modname,
                       source,
@@ -533,6 +520,8 @@ def SAMBA_GENERATOR(bld, name, rule, source='', target='',
         on_results=True,
         before='cc',
         ext_out='.c',
+        samba_type='GENERATOR',
+        vars = [rule],
         name=name)
 
     if always:
@@ -553,6 +542,7 @@ def SETUP_BUILD_GROUPS(bld):
     bld.env['USING_BUILD_GROUPS'] = True
     bld.add_group('setup')
     bld.add_group('build_compiler_source')
+    bld.add_group('vscripts')
     bld.add_group('base_libraries')
     bld.add_group('generators')
     bld.add_group('compiler_prototypes')
@@ -595,7 +585,7 @@ def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
 
 
 
-t = Task.simple_task_type('copy_script', 'rm -f ${LINK_TARGET} && ln -s ${SRC[0].abspath(env)} ${LINK_TARGET}',
+t = Task.simple_task_type('copy_script', 'rm -f "${LINK_TARGET}" && ln -s "${SRC[0].abspath(env)}" ${LINK_TARGET}',
                           shell=True, color='PINK', ext_in='.bin')
 t.quiet = True
 
@@ -850,62 +840,6 @@ def PUBLIC_HEADERS(bld, public_headers, header_path=None):
 Build.BuildContext.PUBLIC_HEADERS = PUBLIC_HEADERS
 
 
-def subst_at_vars(task):
-    '''substiture @VAR@ style variables in a file'''
-    src = task.inputs[0].srcpath(task.env)
-    tgt = task.outputs[0].bldpath(task.env)
-
-    f = open(src, 'r')
-    s = f.read()
-    f.close()
-    # split on the vars
-    a = re.split('(@\w+@)', s)
-    out = []
-    done_var = {}
-    back_sub = [ ('PREFIX', '${prefix}'), ('EXEC_PREFIX', '${exec_prefix}')]
-    for v in a:
-        if re.match('@\w+@', v):
-            vname = v[1:-1]
-            if not vname in task.env and vname.upper() in task.env:
-                vname = vname.upper()
-            if not vname in task.env:
-                Logs.error("Unknown substitution %s in %s" % (v, task.name))
-                sys.exit(1)
-            v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
-            # now we back substitute the allowed pc vars
-            for (b, m) in back_sub:
-                s = task.env[b]
-                if s == v[0:len(s)]:
-                    if not b in done_var:
-                        # we don't want to substitute the first usage
-                        done_var[b] = True
-                    else:
-                        v = m + v[len(s):]
-                    break
-        out.append(v)
-    contents = ''.join(out)
-    f = open(tgt, 'w')
-    s = f.write(contents)
-    f.close()
-    return 0
-
-
-def PKG_CONFIG_FILES(bld, pc_files, vnum=None):
-    '''install some pkg_config pc files'''
-    dest = '${PKGCONFIGDIR}'
-    dest = bld.EXPAND_VARIABLES(dest)
-    for f in TO_LIST(pc_files):
-        base=os.path.basename(f)
-        t = bld.SAMBA_GENERATOR('PKGCONFIG_%s' % base,
-                                rule=subst_at_vars,
-                                source=f+'.in',
-                                target=f)
-        if vnum:
-            t.env.PACKAGE_VERSION = vnum
-        INSTALL_FILES(bld, dest, f, flat=True, destname=base)
-Build.BuildContext.PKG_CONFIG_FILES = PKG_CONFIG_FILES
-
-
 def MANPAGES(bld, manpages):
     '''build and install manual pages'''
     bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'