Added .gitignore
[comos.git] / SConstruct
blob04a0105b39018a2d74cacb2624378fbbb5e510a3
1 import os.path
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 NASM executable name'),
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(options = opts, tools=['default', 'nasm'])
20 Help(opts.GenerateHelpText(env))
21 opts.Save('scache.conf', env)
23 class OurTests:
24 def check_nasm32(context):
25 """check whether nasm uses -f elf or -f elf32"""
26 context.Message('Checking for nasm -f elf32... ')
27 context.env['ASFLAGS'] = '-f elf32'
28 result = context.TryCompile('', '.asm')
29 context.Result(result)
30 return result
32 def check_stack_prot(context):
33 """check whether gcc supports -fno-stack-protector"""
34 context.Message('Checking for -fno-stack-protector... ')
35 context.env['CFLAGS'] = '-fno-stack-protector'
36 result = context.TryCompile('', '.c')
37 context.Result(result)
38 return result
40 old_env = env.Clone()
42 if not env.GetOption('clean'):
43 ### RUN TESTS AND CONFIGURE ENVIRONMENT ###
44 conf = Configure(env, custom_tests = OurTests.__dict__)
46 # Does NASM want '-f elf' or '-f elf32' ?
47 if conf.check_nasm32():
48 env['ASFLAGS'] = old_env['ASFLAGS'] + ' -f elf32'
49 else:
50 env['ASFLAGS'] = old_env['ASFLAGS'] + ' -f elf'
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 env = conf.Finish()
62 # set nice pretty messages
63 if not env['verbose']:
64 env['CCCOMSTR'] = ' Compiling \e[32m$TARGET\e[0m'
65 env['ASCOMSTR'] = ' Assembling \e[32m$TARGET\e[0m'
66 env['LINKCOMSTR'] = ' Linking \e[32m$TARGET\e[0m'
67 env['ARCOMSTR'] = ' Archiving \e[32m$TARGET\e[0m'
68 env['RANLIBCOMSTR'] = ' Indexing \e[32m$TARGET\e[0m'
69 env['NMCOMSTR'] = ' Creating map \e[32m$TARGET\e[0m'
71 SConscript('SConscript',
72 exports = ['env'],
73 build_dir = env['BUILDDIR'],
74 duplicate = 0)
76 # clean config data
77 env.Clean('.', ['config.log', '.sconf_temp'])