Commit b1b51767 authored by Michael Pyne's avatar Michael Pyne

Start on port of abakus to KDE 4. Not much works right now but it at least...

Start on port of abakus to KDE 4.  Not much works right now but it at least builds (if you have flex and bison) and does not crash horribly often as long as you leave user-defined functions alone.

svn path=/trunk/playground/utils/abakus/; revision=745795
parent a7e83abf
PROJECT(abakus)
set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
FIND_PACKAGE(KDE4 REQUIRED)
include(KDE4Defaults)
INCLUDE_DIRECTORIES(${KDE4_INCLUDES} ${QT4_INCLUDES})
ADD_DEFINITIONS(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
ADD_SUBDIRECTORY(src)
abakus, by Michael Pyne <michael.pyne@kdemail.net>
Version: 0.91
Version: 0.92
This is my attempt at creating a light-calculator based on Roberto Alsina's
initial usability suggestions, and based on the ideas of a few other KDE
......@@ -10,11 +10,16 @@ This software is distributed under the terms of the GNU GPL v2.
Synopsis:
$ tar xvjf abakus-0.91.tar.bz2
$ cd abakus-0.91
$ ./configure && make && make install
$ mkdir build && cd build
$ cmake -DCMAKE_INSTALL_PREFIX=/path/to/kde ../ && make && make install
$ abakus
Type away, and press Enter to see the result.
Changes since 0.91:
* (Almost) everything is broken, it crashes quite a bit, it looks worse, lots of
previously working features are disabled, but it compiles and runs under KDE 4 now.
Changes since 0.90:
* Add ability to remove all functions and variables to the context menus of
their respective list boxes.
......
#! /usr/bin/env python
###################################################################
# LOAD THE ENVIRONMENT AND SET UP THE TOOLS
###################################################################
## Load the builders in config
tools = [ 'default', 'help', 'generic', 'kde', 'abakus' ]
toolpath = [ './', './bksys' ]
# Required as part of SCons
env = Environment(tools = tools, toolpath = toolpath)
# Pull in some default settings.
env.KDEuse("environ rpath nohelp")
#env.KDEuse("environ rpath lang_qt thread nohelp")
# If we're asking for help just go ahead and exit now.
if env['HELP']:
print env.helpText()
Exit()
if env['flex'] and env['bison']:
env['PARSER_INCLUDED'] = True
# Export the environment so that SConscript files in subdirs can access it.
Export('env')
###################################################################
# SCRIPTS FOR BUILDING THE TARGETS
###################################################################
env.subdirs('src')
env.docfolder('doc/en', 'en', 'abakus/')
env.SConscript('doc/en/SConscript')
#!/usr/bin/env python
"""
Run scons -h to display the associated help, or look below ..
"""
BOLD ="\033[1m"
RED ="\033[91m"
GREEN ="\033[92m"
YELLOW ="\033[1m" #"\033[93m" # unreadable on white backgrounds
CYAN ="\033[96m"
NORMAL ="\033[0m"
def exists(env):
return true
def printColorCoded(msg):
msg = msg.replace(']', NORMAL)
msg = msg.replace('b[', BOLD)
msg = msg.replace('g[', GREEN)
msg = msg.replace('r[', RED)
msg = msg.replace('c[', CYAN)
msg = msg.replace('y[', YELLOW)
print msg
def generate(env):
import SCons.Util, os
env.addHelpText("""b[hi]
b[*** abakus options ***
----------------------]
b[* bison=(no|yes): Enable parser support. Only needed for developers.
b[* flex=(no|yes): Enable lexer support. Only needed for developers.
b[* mpfr=(no|yes|check): Enable the MPFR library, which is faster and more
precise than abakus's high-precision code.
ie: b[scons configure]
""")
if env['HELP']:
# Don't even bother.
return env
from SCons.Options import Options, PackageOption, EnumOption
import os
def CheckFlags(context):
context.Message('Checking if ld supports --as-needed... ')
lastLINKFLAGS = context.env['LINKFLAGS']
context.env.Append(LINKFLAGS = '-Wl,--as-needed')
ret = context.TryLink("""
#include <iostream>
using namespace std;
int main()
{
cout << "Test" << endl;
}
""", ".cpp")
if not ret:
context.env.Replace(LINKFLAGS = lastLINKFLAGS)
context.Result(ret)
return ret
def CheckPath(context, prog, versionFlag = ''):
if context.env[prog] == 'yes':
context.env[prog] = prog
context.Message('Checking for %s... ' % prog)
ret = True
# If absolute path, just try this one.
if prog[0] == '/':
ret = context.TryAction('%s %s' % (context.env[prog], versionFlag))[0]
if ret:
context.Result(ret)
return True
path = context.env.WhereIs(prog)
if ret and path != None:
context.env[prog] = path
context.Result(1)
else:
context.env[prog] = False
context.Result(0)
print """
The $foo program was not found! You asked to use it so we will stop here. It
is not required, you may use $foo=no on the command line to go without it.""".replace('$foo', prog)
Exit(1)
return False
context.Result(1)
return True
cachefile = env['CACHEDIR'] + '/abakus.cache.py'
fixup = lambda x: "%s installed here (yes = search)" % x
opts = None
if env.doConfigure():
opts = Options(None, env['ARGS'])
else:
opts = Options(cachefile, env['ARGS'])
opts.AddOptions(
PackageOption('bison', fixup('use the Bison parser generator'), 'yes'),
PackageOption('flex', fixup('use the Flex scanner generator'), 'yes'),
EnumOption ('mpfr', 'use the MPFR high-precision library', 'check',
allowed_values=('yes', 'no', 'check'), map={}, ignorecase=1),
('ABAKUS_CONFIGURED', '', 0),
('HAVE_ASNEEDED', '', 0)
)
# We must manually pass the ARGS in.
opts.Update(env, env['ARGS'])
if env.doConfigure() or not env['ABAKUS_CONFIGURED']:
# Configure stuff
conf = env.Configure(custom_tests = {'CheckPath': CheckPath, 'CheckFlags' : CheckFlags})
if env['bison'] and env['bison'] != 'no':
conf.CheckPath('bison', '-V')
if env['flex'] and env['flex'] != 'no':
conf.CheckPath('flex', '-V')
if env['mpfr'] != 'no':
oldLibs = conf.env.get('LIBS', '')
conf.env.AppendUnique(LIBS = 'gmp')
if conf.CheckLibWithHeader('mpfr', 'mpfr.h', 'c++', '''
mpfr_t a;
mpfr_ptr ptr;
__mpfr_struct debug;
mpfr_init(a);
''', autoadd = True):
env['mpfr'] = 'yes'
else:
conf.env.Replace(LIBS = oldLibs)
if env['mpfr'] == 'yes':
print "Unable to find requested library mpfr!"
env.Exit(1)
else:
env['mpfr'] = 'no'
env['HAVE_ASNEEDED'] = 0
if conf.CheckFlags():
env['HAVE_ASNEEDED'] = 1
env['ABAKUS_CONFIGURED'] = 1
env = conf.Finish()
try:
f = open("config.h", "w+")
f.write("""/* config.h -- Automatically generated by abakus.py
* Any changes you make to this file will be overwritten!
*/
""")
f.write("/* HAVE_MPFR -- Defined if the MPFR library is being used. */\n")
if env['mpfr'] == 'yes':
f.write ("#define HAVE_MPFR 1\n")
else:
f.write ("/* #undef HAVE_MPFR */\n")
f.close()
except IOError:
print "Unable to write config.h!"
opts.Save(cachefile, env)
# vim: set et ts=8 sw=4:
## 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, re, types, sys, string, shutil, stat
import SCons.Defaults
import SCons.Tool
import SCons.Util
from SCons.Script.SConscript import SConsEnvironment
from SCons.Options import Options, PathOption
class genobj:
def __init__(self, val, env):
if not val in "program shlib kioslave staticlib".split():
print "unknown genobj given: "+val
env.Exit(1)
self.type = val
self.orenv = env
self.env = None
self.executed = 0
self.target=''
self.src=None
self.cxxflags=''
self.cflags=''
self.includes=''
self.linkflags=''
self.libpaths=''
self.libs=''
# vars used by shlibs
self.vnum=''
self.libprefix=''
# a directory where to install the targets (optional)
self.instdir=''
# ignore the DESTDIR (optional)
self.nodestdir=''
# change the working directory before reading the targets
self.chdir=''
# these members are private
self.chdir_lock=None
self.old_os_dir=''
self.old_fs_dir=''
self.p_local_shlibs=[]
self.p_local_staticlibs=[]
self.p_global_shlibs=[]
#if not env.has_key('USE_THE_FORCE_LUKE'): env['USE_THE_FORCE_LUKE']=[self]
#else: env['USE_THE_FORCE_LUKE'].append(self)
def lockchdir(self):
if not self.chdir: return
self.chdir_lock=1
SConfFS=SCons.Node.FS.default_fs
self.old_fs_dir=SConfFS.getcwd()
self.old_os_dir=os.getcwd()
#os.chdir(old_os_dir+'/'+self.chdir)
SConfFS.chdir( SConfFS.Dir('#/'+self.chdir), change_os_dir=1)
def unlockchdir(self):
if not self.chdir: return
if self.chdir_lock:
#os.chdir(self.old_os_dir)
SCons.Node.FS.default_fs.chdir(self.old_fs_dir, change_os_dir=0)
self.chdir_lock=None
def execute(self):
if self.orenv.has_key('DUMPCONFIG'):
print self.xml()
return
self.lockchdir()
self.env = self.orenv.Copy()
if not self.src or len(self.src) == 0:
print RED+"no source file given to object - self.src"+NORMAL
self.env.Exit(1)
if not self.env.has_key('nosmart_includes'): self.env.AppendUnique(CPPPATH=['./'])
if self.type == "kioslave": self.libprefix=''
if len(self.includes)>0: self.env.AppendUnique(CPPPATH=self.env.make_list(self.includes))
if len(self.cxxflags)>0: self.env.AppendUnique(CXXFLAGS=self.env.make_list(self.cxxflags))
if len(self.cflags)>0: self.env.AppendUnique(CCFLAGS=self.env.make_list(self.cflags))
llist=self.env.make_list(self.libs)
lext='.so .la'.split()
sext='.a'.split()
for l in llist:
sal=SCons.Util.splitext(l)
if len(sal)>1:
if sal[1] in lext: self.p_local_shlibs.append(sal[0]+'.so')
elif sal[1] in sext: self.p_local_staticlibs.append(sal[0]+'.a')
else: self.p_global_shlibs.append(l)
if len(self.p_global_shlibs)>0: self.env.AppendUnique(LIBS=self.p_global_shlibs)
if len(self.libpaths)>0: self.env.PrependUnique(LIBPATH=self.env.make_list(self.libpaths))
if len(self.linkflags)>0: self.env.PrependUnique(LINKFLAGS=self.env.make_list(self.linkflags))
# the target to return
ret=None
if self.type=='shlib' or self.type=='kioslave':
ret=self.env.bksys_shlib(self.target, self.src, self.instdir,
self.libprefix, self.vnum, nodestdir=self.nodestdir)
elif self.type=='program':
ret=self.env.Program(self.target, self.src)
if not self.env.has_key('NOAUTOINSTALL'):
self.env.bksys_install(self.instdir, ret, nodestdir=self.nodestdir)
elif self.type=='staticlib':
ret=self.env.StaticLibrary(self.target, self.src)
# we link the program against a shared library made locally, add the dependency
if len(self.p_local_shlibs)>0:
self.env.link_local_shlib(self.p_local_shlibs)
if ret: self.env.Depends( ret, self.p_local_shlibs )
if len(self.p_local_staticlibs)>0:
self.env.link_local_staticlib(self.p_local_staticlibs)
if ret: self.env.Depends( ret, self.p_local_staticlibs )
self.unlockchdir()
## Copy function that honors symlinks
def copy_bksys(dest, source, env):
if os.path.islink(source):
#print "symlinking "+source+" "+dest
if os.path.islink(dest):
os.unlink(dest)
os.symlink(os.readlink(source), dest)
else:
shutil.copy2(source, dest)
st=os.stat(source)
os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
return 0
## Return a list of things
def make_list(env, s):
if type(s) is types.ListType:
return s
else:
return s.split()
def exists(env):
return true
def generate(env):
## Bksys requires scons 0.96
env.EnsureSConsVersion(0, 96)
SConsEnvironment.make_list = make_list
def doConfigure(env):
return not env['HELP'] and (env['_CONFIGURE'] or not env.has_key('ISCONFIGURED'))
SConsEnvironment.doConfigure = doConfigure
env['HELP']=0
if '--help' in sys.argv or '-h' in sys.argv or 'help' in sys.argv:
env['HELP']=1
env.addHelpText("""
b[*** Generic options ***
-----------------------]
b[* debug ]: debug=1 (-g) or debug=full (-g3, slower), otherwise use
environment CXXFLAGS, or -O2 by default.
b[* prefix ]: the installation path
b[* extraincludes ]: a list of paths separated by ':'
ie: b[scons configure debug=full prefix=/usr/local extraincludes=/tmp/include:/usr/local]
""")
## Global cache directory
# Put all project files in it so a rm -rf cache will clean up the config
if not env.has_key('CACHEDIR'):
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
if os.getuid() != 0:
env.CacheDir(os.getcwd()+'/cache/objects')
# Avoid spreading .sconsign files everywhere - keep this line
env.SConsignFile(env['CACHEDIR']+'/scons_signatures')
def makeHashTable(args):
table = { }
for arg in args:
if len(arg) > 1:
lst=arg.split('=')
if len(lst) < 2:
continue
key=lst[0]
value=lst[1]
if len(key) > 0 and len(value) >0:
table[key] = value
return table
env['ARGS']=makeHashTable(sys.argv)
## Special trick for installing rpms ...
env['DESTDIR']=''
if 'install' in sys.argv:
dd=''
if os.environ.has_key('DESTDIR'):
dd=os.environ['DESTDIR']
if not dd:
if env['ARGS']: dd=env['ARGS']['DESTDIR']
if dd:
env['DESTDIR']=dd+'/'
print CYAN+'** Enabling DESTDIR for the project ** ' + NORMAL + env['DESTDIR']
## install symlinks for shared libraries properly
env['INSTALL'] = copy_bksys
## Use the same extension .o for all object files
env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
## load the options
cachefile=env['CACHEDIR']+'generic.cache.py'
opts = Options(cachefile)
opts.AddOptions(
( 'GENCCFLAGS', 'C flags' ),
( 'GENCXXFLAGS', 'debug level for the project : full or just anything' ),
( 'GENLINKFLAGS', '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)
# Check if the following command line arguments have been given
# and set a flag in the environment to show whether or not it was
# given.
if 'install' in sys.argv:
env['_INSTALL']=1
else:
env['_INSTALL']=0
if 'configure' in sys.argv:
env['_CONFIGURE']=1
else:
env['_CONFIGURE']=0
# Configure the environment if needed
if doConfigure(env):
# be paranoid, unset existing variables
for var in "GENCXXFLAGS GENCCFLAGS GENLINKFLAGS PREFIX EXTRAINCLUDES ISCONFIGURED EXTRAINCLUDES".split():
if env.has_key(var): env.__delitem__(var)
if env['ARGS'].get('debug', None):
debuglevel = env['ARGS'].get('debug', None)
print CYAN+'** Enabling debug for the project **' + NORMAL
if (debuglevel == "full"):
env['GENCXXFLAGS'] = ['-DDEBUG', '-g3', '-Wall']
else:
env['GENCXXFLAGS'] = ['-DDEBUG', '-g', '-Wall']
else:
if os.environ.has_key('CXXFLAGS'):
# user-defined flags (gentooers will be elighted)
env['GENCXXFLAGS'] = SCons.Util.CLVar( os.environ['CXXFLAGS'] )
env.Append( GENCXXFLAGS = ['-DNDEBUG', '-DNO_DEBUG'] )
else:
env.Append(GENCXXFLAGS = ['-O2', '-DNDEBUG', '-DNO_DEBUG'])
if os.environ.has_key('CFLAGS'):
env['GENCCFLAGS'] = SCons.Util.CLVar( os.environ['CFLAGS'] )
## FreeBSD settings (contributed by will at freebsd dot org)
if os.uname()[0] == "FreeBSD":
if os.environ.has_key('PTHREAD_LIBS'):
env.AppendUnique( GENLINKFLAGS = 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( GENLINKFLAGS = ['-pthread'])
env.AppendUnique( GENCXXFLAGS = ['-D_THREAD_SAFE'])
elif osreldate < 502102:
env.AppendUnique( GENLINKFLAGS = ['-lc_r'])
env.AppendUnique( GENCXXFLAGS = ['-D_THREAD_SAFE'])
else:
env.AppendUnique( GENLINKFLAGS = ['-pthread'])
# User-specified prefix
if env['ARGS'].has_key('prefix'):
env['PREFIX'] = os.path.abspath( env['ARGS'].get('prefix', '') )
print (CYAN+'** installation prefix for the project set to : ' +
env['PREFIX'] +' **'+ NORMAL)
# User-specified include paths
env['EXTRAINCLUDES'] = env['ARGS'].get('extraincludes', None)
if env['EXTRAINCLUDES']:
print (CYAN+'** extra include paths for the project set to: ' +
env['EXTRAINCLUDES'] +' **'+ NORMAL)
env['ISCONFIGURED']=1
# And finally save the options in the cache
opts.Save(cachefile, env)
def bksys_install(lenv, subdir, files, destfile=None, nodestdir=None):
""" Install files on "scons install"
If the DESTDIR env variable has been set, (e.g. by
"scons install DESTDIR=$CURDIR/debian) then install files to that
directory, regardless of where the configure stage showed that
files should be installed.
This feature is useful for packagers, and users of GNU stow.
NB. The DESTDIR will be ignored if NODESTDIR is also set, although
the same effect can be acheived by not setting DESTDIR in the first
place."""
if not env['_INSTALL']:
return
basedir = env['DESTDIR']
if nodestdir or env.has_key('NODESTDIR') : basedir = "/"
install_list = None
if not destfile:
install_list = env.Install(basedir+subdir+'/', files)
else:
if subdir:
install_list = env.InstallAs(basedir+subdir+'/'+destfile, files)
else:
install_list = env.InstallAs(basedir+'/'+destfile, files)
env.Alias('install', install_list)
return install_list
def build_la_file(target, source, env):
""" Action for building libtool files.