[Mesa-dev] [PATCH 1/2] meson: provide Makefile.sources variables to meson build

Scott D Phillips scott.d.phillips at intel.com
Fri Oct 13 23:26:07 UTC 2017


---
Caveat: meson won't pick up modifications to the Makefile.sources
files without something like:

https://github.com/mesonbuild/meson/pull/2490

 bin/get-makefile-sources-vars.py | 50 +++++++++++++++++++++++
 meson.build                      | 85 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 135 insertions(+)
 create mode 100755 bin/get-makefile-sources-vars.py

diff --git a/bin/get-makefile-sources-vars.py b/bin/get-makefile-sources-vars.py
new file mode 100755
index 0000000000..1f6b432d1b
--- /dev/null
+++ b/bin/get-makefile-sources-vars.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+
+import collections
+import os
+import multiprocessing
+import subprocess
+import re
+import sys
+
+# matches variables that contain .c, .cpp, or .h filenames
+VAR_RE = re.compile(r'^(\w+)\s*:?=\s*(.*\.(c|cpp|h).*)$')
+
+# matches makefile variable references
+REF_RE = re.compile(r'\$\(([^)]*)\)')
+
+def get_vars(makefile):
+    out = subprocess.check_output('make -f {0} -n -p -R -r {0}'.format(makefile), shell=True, env={})
+    res = {}
+    for o in out.splitlines():
+        m = VAR_RE.match(o)
+        if not m:
+            continue
+        res[m.group(1)] = m.group(2)
+    for var in res.keys():
+        m = REF_RE.search(res[var])
+        while m:
+            res[var] = res[var][:m.start()] + res.get(m.group(1), '') + res[var][m.end():]
+            m = REF_RE.search(res[var])
+    return (makefile, res)
+
+def main(makefiles):
+    p = multiprocessing.Pool()
+    make_vars = p.imap_unordered(get_vars, makefiles)
+    p.close()
+    srcdir = os.sep.join(__file__.split(os.sep)[:-2] + ['src'])
+    for makefile, vars in make_vars:
+        if makefile.startswith(srcdir):
+            makefile = makefile[len(srcdir):]
+        prefix = '_'.join(makefile.split(os.sep)[1:-1]) + '_'
+        prefix = prefix.replace('-', '_')
+        for name, val in vars.items():
+            name = prefix + name
+            print(name)
+            print(val)
+    return 0
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv[1:]))
diff --git a/meson.build b/meson.build
index 02264aeed4..8c675e2624 100644
--- a/meson.build
+++ b/meson.build
@@ -665,5 +665,90 @@ inc_include = include_directories('include')
 
 pkg = import('pkgconfig')
 
+makefile_sources_vars = run_command('bin/get-makefile-sources-vars.py',
+    files(
+        'src/amd/Makefile.sources',
+        'src/amd/vulkan/Makefile.sources',
+        'src/broadcom/Makefile.sources',
+        'src/compiler/Makefile.sources',
+        'src/egl/Makefile.sources',
+        'src/gallium/auxiliary/Makefile.sources',
+        'src/gallium/auxiliary/pipe-loader/Makefile.sources',
+        'src/gallium/drivers/ddebug/Makefile.sources',
+        'src/gallium/drivers/etnaviv/Makefile.sources',
+        'src/gallium/drivers/freedreno/Makefile.sources',
+        'src/gallium/drivers/i915/Makefile.sources',
+        'src/gallium/drivers/llvmpipe/Makefile.sources',
+        'src/gallium/drivers/noop/Makefile.sources',
+        'src/gallium/drivers/nouveau/Makefile.sources',
+        'src/gallium/drivers/pl111/Makefile.sources',
+        'src/gallium/drivers/r300/Makefile.sources',
+        'src/gallium/drivers/r600/Makefile.sources',
+        'src/gallium/drivers/radeon/Makefile.sources',
+        'src/gallium/drivers/radeonsi/Makefile.sources',
+        'src/gallium/drivers/rbug/Makefile.sources',
+        'src/gallium/drivers/softpipe/Makefile.sources',
+        'src/gallium/drivers/svga/Makefile.sources',
+        'src/gallium/drivers/swr/Makefile.sources',
+        'src/gallium/drivers/trace/Makefile.sources',
+        'src/gallium/drivers/vc4/Makefile.sources',
+        'src/gallium/drivers/vc5/Makefile.sources',
+        'src/gallium/drivers/virgl/Makefile.sources',
+        'src/gallium/state_trackers/clover/Makefile.sources',
+        'src/gallium/state_trackers/dri/Makefile.sources',
+        'src/gallium/state_trackers/glx/xlib/Makefile.sources',
+        'src/gallium/state_trackers/nine/Makefile.sources',
+        'src/gallium/state_trackers/omx_bellagio/Makefile.sources',
+        'src/gallium/state_trackers/osmesa/Makefile.sources',
+        'src/gallium/state_trackers/va/Makefile.sources',
+        'src/gallium/state_trackers/vdpau/Makefile.sources',
+        'src/gallium/state_trackers/wgl/Makefile.sources',
+        'src/gallium/state_trackers/xa/Makefile.sources',
+        'src/gallium/state_trackers/xvmc/Makefile.sources',
+        'src/gallium/winsys/amdgpu/drm/Makefile.sources',
+        'src/gallium/winsys/etnaviv/drm/Makefile.sources',
+        'src/gallium/winsys/freedreno/drm/Makefile.sources',
+        'src/gallium/winsys/i915/drm/Makefile.sources',
+        'src/gallium/winsys/imx/drm/Makefile.sources',
+        'src/gallium/winsys/nouveau/drm/Makefile.sources',
+        'src/gallium/winsys/pl111/drm/Makefile.sources',
+        'src/gallium/winsys/radeon/drm/Makefile.sources',
+        'src/gallium/winsys/svga/drm/Makefile.sources',
+        'src/gallium/winsys/sw/dri/Makefile.sources',
+        'src/gallium/winsys/sw/kms-dri/Makefile.sources',
+        'src/gallium/winsys/sw/null/Makefile.sources',
+        'src/gallium/winsys/sw/wrapper/Makefile.sources',
+        'src/gallium/winsys/sw/xlib/Makefile.sources',
+        'src/gallium/winsys/vc4/drm/Makefile.sources',
+        'src/gallium/winsys/vc5/drm/Makefile.sources',
+        'src/gallium/winsys/virgl/drm/Makefile.sources',
+        'src/gallium/winsys/virgl/vtest/Makefile.sources',
+        'src/gbm/Makefile.sources',
+        'src/intel/Makefile.sources',
+        'src/loader/Makefile.sources',
+        'src/mapi/Makefile.sources',
+        'src/mesa/drivers/dri/common/Makefile.sources',
+        'src/mesa/drivers/dri/i915/Makefile.sources',
+        'src/mesa/drivers/dri/i965/Makefile.sources',
+        'src/mesa/drivers/dri/nouveau/Makefile.sources',
+        'src/mesa/drivers/dri/r200/Makefile.sources',
+        'src/mesa/drivers/dri/radeon/Makefile.sources',
+        'src/mesa/drivers/dri/swrast/Makefile.sources',
+        'src/mesa/Makefile.sources',
+        'src/util/Makefile.sources',
+        'src/vulkan/Makefile.sources',
+    )
+)
+
+_var = ''
+foreach line : makefile_sources_vars.stdout().strip().split('\n')
+    if _var == ''
+        _var = line
+    else
+        set_variable(_var, line)
+        _var = ''
+    endif
+endforeach
+
 subdir('include')
 subdir('src')
-- 
2.13.3



More information about the mesa-dev mailing list