PD#141500 midgard r16p0 release
[GitHub/LineageOS/G12/android_hardware_amlogic_kernel-modules_mali-driver.git] / t83x / kernel / drivers / sconscript
CommitLineData
d25bc64b 1#
dd8e48ad 2# (C) COPYRIGHT 2010-2013, 2016 ARM Limited. All rights reserved.
d25bc64b
JY
3#
4# This program is free software and is provided to you under the terms of the
5# GNU General Public License version 2 as published by the Free Software
6# Foundation, and any use by you of this program is subject to the terms
7# of such GNU licence.
8#
9# A copy of the licence is included with the program, and can also be obtained
10# from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
11# Boston, MA 02110-1301, USA.
12#
13#
14
15
dd8e48ad
JY
16import glob
17import os
18import shutil
19import subprocess
20
21from SCons.Script import SCons
22
23Import("env")
24
25# -----------------------------------------------------------------------------
26g_kernel_config = dict()
27
28def kernel_config_enabled(sEnv, option):
29 """Return true if a given kernel config option is enabled"""
30 global g_kernel_config
31 if not g_kernel_config:
32 config_file = os.path.join(sEnv["ENV"]["KDIR"], "include/config/auto.conf")
33 print "Parsing kernel config '%s'." % config_file
34 with open(config_file, "rt") as fp:
35 for line in fp.readlines():
36 try:
37 (key, val) = line.split("=")
38 g_kernel_config[key.strip()] = val.strip()
39 except ValueError:
40 pass
41 if option not in g_kernel_config:
42 return False
43 val = g_kernel_config[option]
44 if val == "y":
45 return True
46 return False
47
48env.AddMethod(kernel_config_enabled, "KernelConfigEnabled")
49
50def kernel_module_builder(env = None, target = None, source = None):
51 assert (len(target) == 1 and 'M' in env and 'make_args' in env and
52 'built_module' in env)
53
54 module_dir = str(env['M'])
55 cmd = ['make', '-j%d' % GetOption('num_jobs')] + env['make_args']
56 status = subprocess.call(cmd, cwd = module_dir, env = env['ENV'])
57 if status:
58 return status
59
60 shutil.copy2(env['built_module'], target[0].abspath)
61 return 0 # Success (SCons will catch any exceptions thrown by copy2).
62
63action = SCons.Action.Action(kernel_module_builder, "[KBUILD] $TARGET")
64builder = env.Builder(action = action)
65env.Append(BUILDERS = {'KernelModuleBuilder': builder})
66
67def build_kernel_module(env, target, sources, M = None, make_args = [],
68 built_module = None):
69 if not M:
70 M = Dir('.').srcnode().abspath
71 if not built_module:
72 built_module = os.path.basename(str(target))
73 built_module = os.path.join(M, built_module)
74
75 env_kern = env.Clone()
76 kdir = env_kern['ENV']['KDIR']
77 env_kern.Append(CPPPATH = [M, '#kernel/include', os.path.join(kdir, 'include')])
78 mod = env_kern.KernelModuleBuilder(target, sources, M = M,
79 make_args = make_args,
80 built_module = built_module)
81
82 # Kbuild implicitly #includes kconfig.h (which includes autoconf.h) when
83 # building kernel module source files.
84 env_kern.Depends(mod, os.path.join(kdir, 'include/generated/autoconf.h'))
85 # Built files may change depending on CONFIG_* values in auto.conf.
86 env_kern.Depends(mod, os.path.join(kdir, 'include/config/auto.conf'))
87
88 for f in ['Kconfig', 'Kbuild', 'Makefile*']:
89 env_kern.Depends(mod, glob.glob(os.path.join(M, f)))
90
91 scanner = SCons.Scanner.C.CScanner()
92 all_headers = set()
93 for src in Flatten(sources):
94 src = env_kern.File(src)
95 (base, ext) = os.path.splitext(src.abspath)
96 if ext == '.c':
97 env_kern.Clean(mod, base + '.o')
98 # Scan for header dependencies explicitly.
99 headers = scanner(src, env_kern, scanner.path_function(env_kern))
100 env_kern.Depends(mod, headers)
101 all_headers.update(headers)
102
103 env_kern.Clean(mod, os.path.join(M, 'Module.symvers'))
104 env_kern.Clean(mod, os.path.join(M, 'module.order'))
105
106 return mod
107
108env.AddMethod(build_kernel_module, 'BuildKernelModule')
d25bc64b
JY
109
110if Glob('base/sconscript'):
111 SConscript('base/sconscript')
112
113if Glob('video/sconscript'):
114 SConscript('video/sconscript')
115
116SConscript('gpu/sconscript')