You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kstreamripper/admin/generic.py

162 lines
5.5 KiB

## 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[1m" #"\033[93m" # unreadable on white backgrounds
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)
## Bksys requires scons 0.96
env.EnsureSConsVersion(0, 96)
## Global cache directory
## Put all project files in it so a rm -rf cache will clean up the config
if not 'CACHEDIR' in env:
env['CACHEDIR'] = os.getcwd()+'/cache/'
if not os.path.isdir(env['CACHEDIR']):
os.mkdir(env['CACHEDIR'])
## SCons cache directory
## this avoids recompiling the same files over and over again: very handy when working with cvs
env.CacheDir(os.getcwd()+'/cache/objects')
## Avoid spreading .sconsign files everywhere - keep this line
env.SConsignFile(env['CACHEDIR']+'/scons_signatures')
# Special trick for installing rpms ...
env['DESTDIR']=''
if 'install' in env['TARGS'] and 'DESTDIR' in os.environ:
env['DESTDIR']=os.environ['DESTDIR']+'/'
print(CYAN+'** Enabling DESTDIR for the project ** ' + NORMAL + env['DESTDIR'])
# load the options
from SCons.Variables import Variables
cachefile=env['CACHEDIR']+'generic.cache.py'
opts = Variables(cachefile)
opts.AddVariables(
( 'KDECCFLAGS', 'C flags' ),
( 'KDECXXFLAGS', 'debug level for the project : full or just anything' ),
( 'KDELINKFLAGS', 'additional link flags' ),
( 'PREFIX', 'prefix for installation' ),
( 'EXTRAINCLUDES', 'extra include paths for the project' ),
( 'ISCONFIGURED', 'is the project configured' ),
)
opts.Update(env)
# use this to avoid an error message 'how to make target configure ?'
env.Alias('configure', None)
import SCons.Util
# configure the environment if needed
if 'configure' in env['TARGS'] or not 'ISCONFIGURED' in env:
# be paranoid, unset existing variables
if 'KDECXXFLAGS' in env:
env.__delitem__('KDECXXFLAGS')
if 'KDECCFLAGS' in env:
env.__delitem__('KDECCFLAGS')
if 'KDELINKFLAGS' in env:
env.__delitem__('KDELINKFLAGS')
if 'PREFIX' in env:
env.__delitem__('PREFIX')
if 'EXTRAINCLUDES' in env:
env.__delitem__('EXTRAINCLUDES')
if 'ISCONFIGURED' in env:
env.__delitem__('ISCONFIGURED')
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', '-g3']
else:
env['KDECXXFLAGS'] = ['-DDEBUG', '-g']
else:
if 'CXXFLAGS' in os.environ:
# user-defined flags (gentooers will be elighted)
env['KDECXXFLAGS'] = SCons.Util.CLVar( os.environ['CXXFLAGS'] )
env.Append( KDECXXFLAGS = ['-DNDEBUG', '-DNO_DEBUG'] )
else:
env.Append(KDECXXFLAGS = ['-O2', '-DNDEBUG', '-DNO_DEBUG'])
if 'CFLAGS' in os.environ:
env['KDECCFLAGS'] = SCons.Util.CLVar( os.environ['CFLAGS'] )
## FreeBSD settings (contributed by will at freebsd dot org)
if os.uname()[0] == "FreeBSD":
if 'PTHREAD_LIBS' in os.environ:
env.AppendUnique( KDELINKFLAGS = SCons.Util.CLVar( os.environ['PTHREAD_LIBS'] ) )
else:
syspf = os.popen('/sbin/sysctl kern.osreldate')
osreldate = int(syspf.read().split()[1])
syspf.close()
if osreldate < 500016:
env.AppendUnique( KDELINKFLAGS = ['-pthread'])
env.AppendUnique( KDECXXFLAGS = ['-D_THREAD_SAFE'])
elif osreldate < 502102:
env.AppendUnique( KDELINKFLAGS = ['-lc_r'])
env.AppendUnique( KDECXXFLAGS = ['-D_THREAD_SAFE'])
else:
env.AppendUnique( KDELINKFLAGS = ['-pthread'])
# 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 'PREFIX' in env:
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 'EXTRAINCLUDES' in env:
env.__delitem__('EXTRAINCLUDES')
env['ISCONFIGURED']=1
# And finally save the options in the cache
opts.Save(cachefile, env)
if 'KDECXXFLAGS' in env:
env.AppendUnique( CPPFLAGS = env['KDECXXFLAGS'] )
if 'KDECCFLAGS' in env:
env.AppendUnique( CCFLAGS = env['KDECCFLAGS'] )
if 'KDELINKFLAGS' in env:
env.AppendUnique( LINKFLAGS = env['KDELINKFLAGS'] )
if 'EXTRAINCLUDES' in env:
incpaths = []
for dir in str(env['EXTRAINCLUDES']).split(':'):
incpaths.append( dir )
env.Append(CPPPATH = incpaths)