#!/usr/bin/env python
import os

env = Environment()

ooo = '/usr/lib/openoffice/program'
ooosdk = '/usr/lib/openoffice/sdk'
oooure = '/usr/lib/openoffice/ure'

ooobin = '/usr/lib/openoffice/sdk/linux/bin'

# NOTE: path to SDK tools:
# PATH="$OOoSDK/bin:$OOoURE/bin:$PATH"
# LD_LIBRARY_PATH="$OOo:$OOoURE/lib:$LD_LIBRARY_PATH"

# Create the shared library
libenv = env.Clone()
libenv.Append(
	CXXFLAGS=['-O2','-fomit-frame-pointer']
	,CPPDEFINES=['GCC','UNX','LINUX','CPPU_ENV=gcc3']
	,CPPPATH=['#',os.path.join(ooosdk,'include')]
	,LINKFLAGS=['--retain-symbols-file=symbols.txt']
	,LIBPATH=[ooo]
	,LIBS=['uno_cppuhelpergcc3']
	
)
lib = libenv.SharedLibrary('RNG',['RNG_impl.cxx'])

idlc = os.path.join(ooobin,'idlc')
env.Command('RNG.urd', 'RNG.idl', "%s -C -I%s $SOURCE" % (idlc,os.path.join(ooosdk,'idl')))

regmerge = os.path.join(ooobin,'regmerge')
db = env.Command('RNG.rdb','RNG.urd', "%s $TARGET /UCR $SOURCE" % regmerge)

regcomp = os.path.join(ooobin,'regcomp')
env.Command(None, [lib,db], "%s -register -r RNG.rdb -c %s" % (regcomp,os.path.abspath('libRNG.so')))

types1 = """
		-Tcom.sun.star.sheet.XAddIn \
		-Tcom.sun.star.lang.XServiceName \
		-Tcom.sun.star.lang.XServiceInfo \
		-Tcom.sun.star.lang.XTypeProvider \
		-Tcom.sun.star.uno.XWeak \
		-Tcom.sun.star.uno.XAggregation \
		-Tcom.sun.star.lang.XMultiServiceFactory \
		-Tcom.sun.star.uno.XComponentContext \
		-Tcom.sun.star.lang.XSingleComponentFactory \
		-Tcom.sun.star.lang.XSingleServiceFactory \
		-Tcom.sun.star.registry.XRegistryKey \
"""

types = ['com.sun.star.uno.*','com.sun.star.lang.*','com.sun.star.registry.*','com.sun.star.sheet.*']
rdbs = ['services','types','oovbaapi']

cppumaker = os.path.join(ooobin,'cppumaker')
env.Command(None, "RNG.rdb", "%s -BUCR -Torg.openoffice.sheet.addin.XRNG %s %s $SOURCE" 
		% (cppumaker," ".join(["-T%s" % t for t in types])," ".join([os.path.join(ooo,"%s.rdb"%t) for t in rdbs]))
)

