summaryrefslogtreecommitdiffstats
path: root/scons/generic.py
blob: 3249df700dbc02fd893ea4cf63c20d0b9799921d (plain)
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
## Thomas Nagy, 2005

"""
Detect and store the most common options
* kdecxxflags  : debug=1 (-g) or debug=full (-g3, slower)
  else use the user CXXFLAGS if any, - or -O2 by default
* prefix : the installation path
* extraincludes : a list of paths separated by ':'
ie: scons configure debug=full prefix=/usr/local extraincludes=/tmp/include:/usr/local
"""

BOLD   ="\033[1m"
RED    ="\033[91m"
GREEN  ="\033[92m"
YELLOW ="\033[93m"
CYAN   ="\033[96m"
NORMAL ="\033[0m"

import os

def exists(env):
	return true

def generate(env):
	env.Help("""
"""+BOLD+
"""*** Generic options ***
-----------------------"""+NORMAL+"""
"""+BOLD+"""* debug  """+NORMAL+""": debug=1 (-g) or debug=full (-g3, slower) else use environment CXXFLAGS, or -O2 by default
"""+BOLD+"""* prefix """+NORMAL+""": the installation path
"""+BOLD+"""* extraincludes """+NORMAL+""": a list of paths separated by ':'
ie: """+BOLD+"""scons configure debug=full prefix=/usr/local extraincludes=/tmp/include:/usr/local
"""+NORMAL)

	# load the options
	from SCons.Options import Options, PathOption
	opts = Options('generic.cache.py')
	opts.AddOptions(
		( 'KDECXXFLAGS', 'debug level for the project : full or just anything' ),
		( 'PREFIX', 'prefix for installation' ),
		( 'EXTRAINCLUDES', 'extra include paths for the project' ),
	)
	opts.Update(env)

	# use this to avoid an error message 'how to make target configure ?'
	env.Alias('configure', None)

	# configure the environment if needed
	if 'configure' in env['TARGS'] or not env.has_key('KDECXXFLAGS'):
		# need debugging ?
		if env.has_key('KDECXXFLAGS'):
			env.__delitem__('KDECXXFLAGS')
		if env['ARGS'].get('debug', None):
			debuglevel = env['ARGS'].get('debug', None)
			print CYAN+'** Enabling debug for the project **' + NORMAL
			if (debuglevel == "full"):
				env['KDECXXFLAGS'] = ['-DDEBUG', '-ggdb', '-pipe', '-Wall']
			else:
				env['KDECXXFLAGS'] = ['-DDEBUG', '-g']
		else:
			if os.environ.has_key('CXXFLAGS'):
				# user-defined flags (gentooers will be delighted)
				import SCons.Util
				env['KDECXXFLAGS'] = SCons.Util.CLVar( os.environ['CXXFLAGS'] )
				env.Append( KDECXXFLAGS = ['-DNDEBUG', '-DNO_DEBUG'] )
			else:
				env.Append(KDECXXFLAGS = ['-O2', '-DNDEBUG', '-DNO_DEBUG'])

		# user-specified prefix
		if env['ARGS'].get('prefix', None):
			env['PREFIX'] = env['ARGS'].get('prefix', None)
			print CYAN+'** set the installation prefix for the project : ' + env['PREFIX'] +' **'+ NORMAL
		elif env.has_key('PREFIX'):
			env.__delitem__('PREFIX')

		# user-specified include paths
		env['EXTRAINCLUDES'] = env['ARGS'].get('extraincludes', None)
		if env['ARGS'].get('extraincludes', None):
			print CYAN+'** set extra include paths for the project : ' + env['EXTRAINCLUDES'] +' **'+ NORMAL
		elif env.has_key('EXTRAINCLUDES'):
			env.__delitem__('EXTRAINCLUDES')

		# and finally save the options in a cache
		opts.Save('generic.cache.py', env)

	if env.has_key('KDECXXFLAGS'):
		# load the flags
                env.AppendUnique( CPPFLAGS = env['KDECXXFLAGS'] )

	if env.has_key('EXTRAINCLUDES'):
		incpaths = []
		for dir in str(env['EXTRAINCLUDES']).split(':'):
			incpaths.append( dir )
		env.Append(CPPPATH = incpaths)