This is a disaster, SCons is annoying the shit out of me, I guess I am going to build...
[ail.git] / SConscript
blobbaf4af8ae5f40e74b3fd74d71d239827306d50bf
1 import nil.directory, nil.environment, sys, os
3 library = 'ail'
4 source = 'source'
6 is_windows = nil.environment.is_windows()
8 if is_windows:
9         boost = ARGUMENTS.get('boost')
10         bzip2 = ARGUMENTS.get('bzip2')
11         zlib = ARGUMENTS.get('zlib')
13         if boost == None:
15                 print 'This library requires boost (www.boost.org) so you will have to specify the path to the boost library in the scons arguments:'
16                 print 'scons boost=<boost directory>'
17                 print 'The bzip2 (www.bzip.org) and the zlib (www.zlib.net) components of this library are optional and will require you to specify their locations the same way:'
18                 print 'scons boost=<boost directory> bzip2=<bzip2 directory> zlib=<zlib directory>'
19                 sys.exit(1)
20                 
21         optional_files = [
22                 (bzip2, 'bzip2.cpp'),
23                 (zlib, 'zlib.cpp')
24         ]
26         defines = {
27                 '_WIN32_WINNT': '0x0501',
28                 '_CRT_SECURE_NO_WARNINGS': '1',
29                 '_SCL_SECURE_NO_WARNINGS': '1',
30                 'BOOST_LIB_DIAGNOSTIC': 1
31         }
33         flags = [
34                 '/EHsc'
35         ]
37         linker_flags = [
38                 '/NOLOGO',
39                 '/LTCG'
40         ]
42         dependencies = [boost, bzip2, zlib]
43         
44 else:
45         optional_files = []
46         defines = {}
47         flags = []
48         linker_flags = []
49         dependencies = []
51 relative_source = os.path.join('..', source)
53 source_files = nil.directory.get_files_by_extension(relative_source, 'cpp')
54 map_path = lambda path: os.path.basename(path)
55 source_files = map(map_path, source_files)
56 if len(source_files) == 0:
57         print 'No targets. CWD: %s' % os.getcwd()
58         sys.exit(1)
59         
60 print '%d targets:' % len(source_files)
62 for source_file in source_files:
63         print source_file
64         
65 for path, file in optional_files:
66         if path == None:
67                 source_files.remove(file)
68                 pass
70 include_directories = ['..'] + filter(lambda path: path != None, dependencies)
72 cpus = int(os.environ.get('NUMBER_OF_PROCESSORS', 1))
74 thread_string = 'thread'
75 if cpus > 1:
76         thread_string += 's'
77 print 'Compiling project with %d %s' % (cpus, thread_string)
79 source_files = map(lambda path: os.path.join('..', source, path), source_files)
81 environment = Environment(CPPPATH = include_directories, CPPDEFINES = defines, CCFLAGS = flags)
82 environment.Append(LINKFLAGS = linker_flags)
83 environment.SetOption('num_jobs', cpus)
84 environment.StaticLibrary(library, source_files)