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.
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),
23 Help(opts
.GenerateHelpText(env
))
24 opts
.Save('scache.conf', env
)
26 ##### CONFIGURATION #####
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
)
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])
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
55 if conf
.check_stack_prot():
56 env
['CFLAGS'] = old_env
['CFLAGS'] + ' -fno-stack-protector'
58 env
['CFLAGS'] = old_env
['CFLAGS']
60 if not conf
.check_for_asciidoc():
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):
77 build_type
= env
.conf
.get(config_name
)
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':
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
)
96 # build asciidoc documentation
97 AsciiDoc
= env
.Builder(
98 action
= Action('asciidoc -o $TARGET $SOURCE', '$DOCCOMSTR'),
102 env
.Append(BUILDERS
= {'KernelModule': KernelModule
,
103 'AsciiDoc': AsciiDoc
})
104 env
.module_linker_script
= File('kernel/module.ld')
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',
124 build_dir
= env
['BUILDDIR'],
128 env
.Clean('.', ['config.log', '.sconf_temp'])