Removed excessive traces in loadelf.c
[marionette.git] / SConstruct
blob4c7d09a6338665c9dc0dce77a043b0fc17c7603c
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', '-m32'),
14 ('LINKFLAGS', 'Set the linker flags', '-m32 -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 ##### SETTINGS #####
67 import tools.configure
69 env.conf = tools.configure.Config('CONFIG', os.path.join(env['BUILDDIR'], 'config'))
71 ##### BUILD RULES #####
73 # link a kernel module
75 def KernelModule(env, target, sources, config_name = None):
76 if config_name:
77 build_type = env.conf.get(config_name)
78 else:
79 build_type = 'm'
80 if build_type == 'y':
81 # nothing special - compile into kernel like all the other kernel objects
82 env.kernel_objects.extend(env.Object(i) for i in sources)
83 elif build_type == 'm':
84 # build as a module
85 # NOTE: module_entry_point is set in SConscript
86 module = env.Program('%s.ko' % target[0], sources + [env.module_entry_point],
87 LINKFLAGS = env['LINKFLAGS'] + ' -Wl,-r,-T,' + env.module_linker_script.path,
88 CCCOMSTR = '$MODCCCOMSTR',
89 LINKCOMSTR = '$MODLINKCOMSTR',
91 env.Depends(module, env.module_linker_script)
92 else:
93 # don't build at all!
94 pass
96 # build asciidoc documentation
97 AsciiDoc = env.Builder(
98 action = Action('asciidoc -o $TARGET $SOURCE', '$DOCCOMSTR'),
99 suffix = '.html',
100 src_suffix = '.txt')
102 env.Append(BUILDERS = {'KernelModule': KernelModule,
103 'AsciiDoc': AsciiDoc})
104 env.module_linker_script = File('kernel/module.ld')
106 ##### VANITY #####
108 # set nice pretty messages
109 if not env['verbose']:
110 env['CCCOMSTR'] = ' Compiling \e[32m$TARGET\e[0m'
111 env['ASPPCOMSTR'] = ' Assembling \e[32m$TARGET\e[0m'
112 env['LINKCOMSTR'] = ' Linking \e[32m$TARGET\e[0m'
113 env['MODCCCOMSTR'] = '[M] Compiling \e[32m$TARGET\e[0m'
114 env['MODLINKCOMSTR'] = '[M] Linking \e[32m$TARGET\e[0m'
115 env['ARCOMSTR'] = ' Archiving \e[32m$TARGET\e[0m'
116 env['RANLIBCOMSTR'] = ' Indexing \e[32m$TARGET\e[0m'
117 env['NMCOMSTR'] = ' Creating map \e[32m$TARGET\e[0m'
118 env['DOCCOMSTR'] = ' Documenting \e[32m$TARGET\e[0m'
120 ##### SUB-DIRECTORIES #####
122 SConscript('SConscript',
123 exports = ['env'],
124 build_dir = env['BUILDDIR'],
125 duplicate = 0)
127 # clean config data
128 env.Clean('.', ['config.log', '.sconf_temp'])