Lumiera  0.pre.03
»edit your freedom«
Setup.py
1 # -*- python -*-
2 
5 
6 # Copyright (C) Lumiera.org
7 # 2012, Hermann Vosseler <Ichthyostega@web.de>
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of
12 # the License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 
23 
24 from SCons.Script import EnsurePythonVersion, EnsureSConsVersion, Variables, Decider
25 
26 from LumieraEnvironment import *
27 from Buildhelper import *
28 import Options
29 
30 
31 
32 #-------------------------------------------------------Configuration
33 TARGDIR = 'target'
34 VERSION = '0.pre.03'
35 TOOLDIR = './admin/scons' # SCons plugins
36 OPTCACHE = 'optcache'
37 CUSTOPTFILE = 'custom-options'
38 
39 # these are accessible via env.path.xxxx
40 buildExe = '#$TARGDIR'
41 buildLib = '#$TARGDIR/modules'
42 buildPlug = '#$TARGDIR/modules'
43 buildIcon = '#$TARGDIR/gui/icons' # for IconResource() and IconRender()
44 buildUIRes = '#$TARGDIR/gui/' # for GuiResource()
45 buildConf = '#$TARGDIR/config' # for ConfigData()
46 installExe = '#$DESTDIR/lib/lumiera'
47 installLib = '#$DESTDIR/lib/lumiera/modules'
48 installPlug = '#$DESTDIR/lib/lumiera/modules'
49 installIcon = '#$DESTDIR/share/lumiera/icons'
50 installUIRes = '#$DESTDIR/share/lumiera/'
51 installConf = '#$DESTDIR/lib/lumiera/config'
52 
53 #-------------------------------------------------------Configuration
54 buildSetup = Record(locals())
55 
56 
57 
58 
59 
60 def defineBuildEnvironment():
61  """ create a custom build environment,
62  define the basic compiler and linker flags,
63  define locations in source and target tree,
64  parse the commandline and pick up options
65  """
66  EnsureSConsVersion(2,0)
67  EnsurePythonVersion(2,6)
68  Decider('MD5-timestamp') # detect changed files by timestamp, then do a MD5
69 
70  buildVars = Variables([OPTCACHE, CUSTOPTFILE])
72  env = LumieraEnvironment(buildSetup, buildVars)
73 
74  env.Replace( CPPPATH =["#src"] # used to find includes, "#" means always absolute to build-root
75  , CPPDEFINES=['LUMIERA_VERSION='+VERSION ] # note: it's a list to append further defines
76  , CCFLAGS='-Wall -Wextra -Wformat-security'
77  , CXXFLAGS='-std=gnu++17 -Wno-enum-compare'
78  , CFLAGS='-std=gnu99'
79  )
80  env.Append(LINKFLAGS='-Wl,--no-undefined') # require every dependency is given on link, in the right order
81  env.Append(LINKFLAGS='-Wl,--as-needed') # by default only link against dependencies actually needed to resolve symbols
82  handleVerboseMessages(env)
83  handleNoBugSwitches(env)
84 
85  env.Append(CPPDEFINES = '_GNU_SOURCE')
86  appendCppDefine(env,'DEBUG','DEBUG', 'NDEBUG')
87 # appendCppDefine(env,'OPENGL','USE_OPENGL')
88  appendVal(env,'ARCHFLAGS','CCFLAGS') # for both C and C++
89  appendVal(env,'OPTIMIZE', 'CCFLAGS', val=' -O3')
90  appendVal(env,'DEBUG', 'CCFLAGS', val=' -ggdb')
91 
92  # setup search path for Lumiera plugins
93  appendCppDefine(env,'PKGLIBDIR','LUMIERA_PLUGIN_PATH=\\"$PKGLIBDIR/:ORIGIN/modules\\"'
94  ,'LUMIERA_PLUGIN_PATH=\\"ORIGIN/modules\\"')
95  appendCppDefine(env,'PKGDATADIR','LUMIERA_CONFIG_PATH=\\"$PKGLIBDIR/:.\\"'
96  ,'LUMIERA_CONFIG_PATH=\\"$DESTDIR/share/lumiera/:.\\"')
97 
98  Options.prepareOptionsHelp(buildVars,env)
99  buildVars.Save(OPTCACHE, env)
100  return env
101 
102 
103 
104 def appendCppDefine(env,var,cppVar, elseVal=''):
105  if env[var]:
106  env.Append(CPPDEFINES = env.subst(cppVar) )
107  elif elseVal:
108  env.Append(CPPDEFINES = env.subst(elseVal))
109 
110 def appendVal(env,var,targetVar,val=None):
111  if env[var]:
112  env.Append( **{targetVar: env.subst(val) or env[var]})
113 
114 
115 def handleNoBugSwitches(env):
116  """ set the build level for NoBug.
117  Release builds imply no DEBUG
118  whereas ALPHA and BETA require DEBUG
119  """
120  level = env['BUILDLEVEL']
121  if level in ['ALPHA', 'BETA']:
122  if not env['DEBUG']:
123  print 'Warning: NoBug ALPHA or BETA builds requires DEBUG=yes, switching DEBUG on!'
124  env.Replace( DEBUG = 1 )
125  env.Append(CPPDEFINES = 'EBUG_'+level)
126  elif level == 'RELEASE':
127  env.Replace( DEBUG = 0 )
128 
129 
130 def handleVerboseMessages(env):
131  """ toggle verbose build output """
132  if not env['VERBOSE']:
133  # SetOption('silent', True)
134  env['CCCOMSTR'] = env['SHCCCOMSTR'] = " Compiling $SOURCE"
135  env['CXXCOMSTR'] = env['SHCXXCOMSTR'] = " Compiling++ $SOURCE"
136  env['LINKCOMSTR'] = " Linking --> $TARGET"
137  env['LDMODULECOMSTR'] = " creating module [ $TARGET ]"
138 
139 
140 
def defineCmdlineVariables(buildVars)
Definition: Options.py:31
def prepareOptionsHelp(buildVars, env)
Definition: Options.py:61