Fixed uninitialised n_chunks in untested vpcreate
[marionette.git] / SConstruct
blobad9629922c2b8d579dd65c87b5332e7a8032c96d
1 import os, re
3 opts = Options('scache.conf')
4 ### These options are global defaults.
5 ### If you want to change your options locally,
6 ### give them to SCons on the command line, or
7 ### edit scache.conf. Don't edit them here.
8 opts.AddOptions(
9 ('CC', 'Set the C compiler to use'),
10 ('AS', 'Set the assembler to use'),
11 ('LINK', 'Set the linker to use'),
12 ('CFLAGS', 'Set the C compiler flags', '-ffreestanding -m32 -O3 -Wall -std=c99 -pedantic'),
13 ('ASFLAGS', 'Set the assembler flags', ''),
14 ('LINKFLAGS', 'Set the linker flags', '-ffreestanding -nostdlib -Wl,--gc-sections,-m,elf_i386'),
15 ('BUILDDIR', 'Set the sub-directory to put object files in', 'build'),
16 BoolOption('verbose', 'Show full commands during the build process', False),
19 env = Environment(
20 options = opts,
21 tools=['default'],
22 ENV = os.environ)
23 Help(opts.GenerateHelpText(env))
24 opts.Save('scache.conf', env)
26 ##### CONFIGURATION #####
28 class OurTests:
29 def check_stack_prot(context):
30 """check whether gcc supports -fno-stack-protector"""
31 context.Message('Checking for -fno-stack-protector... ')
32 context.env['CFLAGS'] = '-fno-stack-protector'
33 result = context.TryCompile('', '.c')
34 context.Result(result)
35 return result
37 def check_for_asciidoc(context):
38 """check whether asciidoc is installed"""
39 context.Message('Checking for asciidoc... ')
40 result = context.TryAction(Action('asciidoc $SOURCE'), '', '.txt')
41 context.Result(result[0])
42 return result[0]
44 old_env = env.Clone()
46 env.build_doc = True
48 if not env.GetOption('clean'):
49 ### RUN TESTS AND CONFIGURE ENVIRONMENT ###
50 conf = Configure(env, custom_tests = OurTests.__dict__)
52 # If the compiler has -fno-stack-protector, we need to disable
53 # it to stop gcc inserting stack protection code (which doesn't
54 # work in a kernel)
55 if conf.check_stack_prot():
56 env['CFLAGS'] = old_env['CFLAGS'] + ' -fno-stack-protector'
57 else:
58 env['CFLAGS'] = old_env['CFLAGS']
60 if not conf.check_for_asciidoc():
61 env.build_doc = False
63 env = conf.Finish()
65 ##### BUILD RULES #####
67 # link a kernel module
69 def KernelModule(env, target, sources):
70 # module_entry_point is set in SConscript
71 module = env.Program('%s.ko' % target[0], sources + [env.module_entry_point],
72 LINKFLAGS = env['LINKFLAGS'] + ' -Wl,-r,-T,' + env.module_linker_script.path,
73 CCCOMSTR = '$MODCCCOMSTR',
74 LINKCOMSTR = '$MODLINKCOMSTR',
76 env.Depends(module, env.module_linker_script)
78 # build asciidoc documentation
79 AsciiDoc = env.Builder(
80 action = Action('asciidoc -o $TARGET $SOURCE', '$DOCCOMSTR'),
81 suffix = '.html',
82 src_suffix = '.txt')
84 env.Append(BUILDERS = {'KernelModule': KernelModule,
85 'AsciiDoc': AsciiDoc})
86 env.module_linker_script = File('module.ld')
88 ##### VANITY #####
90 # set nice pretty messages
91 if not env['verbose']:
92 env['CCCOMSTR'] = ' Compiling \e[32m$TARGET\e[0m'
93 env['ASPPCOMSTR'] = ' Assembling \e[32m$TARGET\e[0m'
94 env['LINKCOMSTR'] = ' Linking \e[32m$TARGET\e[0m'
95 env['MODCCCOMSTR'] = '[M] Compiling \e[32m$TARGET\e[0m'
96 env['MODLINKCOMSTR'] = '[M] Linking \e[32m$TARGET\e[0m'
97 env['ARCOMSTR'] = ' Archiving \e[32m$TARGET\e[0m'
98 env['RANLIBCOMSTR'] = ' Indexing \e[32m$TARGET\e[0m'
99 env['NMCOMSTR'] = ' Creating map \e[32m$TARGET\e[0m'
100 env['DOCCOMSTR'] = ' Documenting \e[32m$TARGET\e[0m'
102 ##### SUB-DIRECTORIES #####
104 SConscript('SConscript',
105 exports = ['env'],
106 build_dir = env['BUILDDIR'],
107 duplicate = 0)
109 # clean config data
110 env.Clean('.', ['config.log', '.sconf_temp'])