This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSconstruct
126 lines (99 loc) · 3.24 KB
/
Sconstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from glob import glob
import os
import fnmatch
project_name = 'alife'
prefix = ''
cc = prefix + 'gcc'
cxx = prefix + 'g++'
ar = prefix + 'ar'
ranlib = prefix + 'ranlib'
build_dir = 'build/'
src_dir = 'src/'
include_dir = 'include/'
static_lib_dir = 'lib/'
lib_dir = 'libraries/'
# system installed libs that are needed.
system_libs = ['SDL2']
# local libs are libraries inside of the project libraries folder.
# asuming the library folder has the same name as the library folderl (lib+foldername).
local_libs = []
# compiler flags for when doing development.
cc_dev_flags = []
cc_dev_flags.append('-ggdb3')
cc_dev_flags.append('-O0')
cc_dev_flags.append('-fdiagnostics-color=always')
# compiler flags for when building a library.
cc_lib_flags = []
cc_lib_flags.append('-fPIC')
# default compiler flags. always included.
ccflags = []
ccflags.append('-O2')
ccflags.append('-ansi')
ccflags.append('-pedantic-errors')
ccflags.append('-Wextra')
ccflags.append('-Wall')
ccflags.append('--std=c++11')
# in a release build no flags are added.
if 'libbuild' in COMMAND_LINE_TARGETS:
ccflags += cc_lib_flags
elif 'devbuild' in COMMAND_LINE_TARGETS:
# remove optimization from default flags.
ccflags.remove('-O2')
ccflags += cc_dev_flags
# setup build environment
env = Environment()
env['CXX'] = cxx
env['CC'] = cc
env['AR'] = ar
env['RANLIB'] = ranlib
env['CCFLAGS'] = ccflags
env['ENV']['PATH'] = os.environ['PATH']
env.Append(CPPPATH=[include_dir])
# lib_build = ARGUMENTS.get('libbuild', 0)
# add all the directories in include
for root, dirnames, filenames in os.walk(include_dir):
for dirname in dirnames:
path = os.path.join(root, dirname)
env.Append(CPPPATH=[path])
# run for local libs
if len(local_libs):
for lib in local_libs:
env.Append(CPPPATH=[lib_dir + lib + '/' + 'include/'])
env.Append(LIBPATH=[lib_dir + lib + '/' + 'lib/'])
env.Append(LIBS=[lib])
# run for system libs
if len(system_libs):
# run for system installed libs
for lib in system_libs:
env.Append(LIBS=[lib]);
print("libs: %s" % env['LIBS'])
# collect source and make object names for them.
obj_targets = []
src_files = []
for root, dirnames, filenames in os.walk(src_dir):
for filename in fnmatch.filter(filenames, '*.cpp'):
if ('libbuild' in COMMAND_LINE_TARGETS) and ("main" in filename):
print("filename: %s" % filename)
else:
src_files.append(os.path.join(root, filename))
for src in src_files:
target = src.replace('.cpp', '.o')
obj_targets.append(build_dir + target)
objects = []
for (obj_target, src_file) in zip(obj_targets, src_files):
objects.append(env.Object(target=obj_target, source=src_file))
program = env.Program(target=build_dir + project_name, source=objects)
static = env.StaticLibrary(target=static_lib_dir + project_name, source=objects)
env.Alias('libbuild', static)
env.Alias('devbuild', program)
env.Default(program)
# this removes both build dir and static dir
# if they exist.
env.Clean(program, build_dir)
env.Clean(program, static_lib_dir)
env.Clean(static, static_lib_dir)
if 'CPPPATH' in env:
print("cpppath: %s" % env['CPPPATH'])
if 'LIBPATH' in env:
print("libpath: %s" % env['LIBPATH'])
print("DEF_TARG:%s" % (map(str, DEFAULT_TARGETS)))