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