1. binet
  2. mana-ext

Source

mana-ext / pkg / builders / clhep / wscript

# -*- python -*-

import os

import waflib.Logs as msg
import waflib.Options
import waflib.Utils
from waflib.Utils import subst_vars

import wafflelib.waffle_utils as waffle_utils

PACKAGE = {
    'name': 'clhep',
    'author': ['mana collaboration'],
}

def pkg_deps(ctx):
    ctx.use_pkg('builders/settings')
    return

def options(ctx):
    return

def configure(ctx):
    msg.debug ('[configure] package name: '+PACKAGE['name'])

    if not ctx.env.CXX:
        msg.fatal('load a c++ compiler first')
        pass

    clhep_config_bin = 'clhep-config'
    common_cfg = {
        'mandatory': True,
        }
    
    msg.warn('building clhep from sources...')
    ctx.env['PACKAGE_REPO'] = [
        'http://proj-clhep.web.cern.ch/proj-clhep/DISTRIBUTION/tarFiles'
        ]
    ctx.env['EXT_BUNDLED_CLHEP_VERSION'] = '1.9.4.7'
    ctx.env['EXT_BUNDLED_CLHEP_PREFIX'] = subst_vars(
        '${EXTERNAL_AREA}/clhep/${EXT_BUNDLED_CLHEP_VERSION}/${CMTCFG}',
        ctx.env)

    ctx.env['CLHEP_HOME'] = ctx.env['EXT_BUNDLED_CLHEP_PREFIX']
    ctx.env['CLHEP_VERSION'] = ctx.env['EXT_BUNDLED_CLHEP_VERSION']
        
    env = waffle_utils._get_env_for_subproc(ctx)
    env['MY_SHFLAGS'] = ctx.env.get_flat('LINKFLAGS_cshlib')
    env['MY_SHNAME'] = env['SONAME_ST'].replace('%s','')
    if waffle_utils._is_darwin(ctx):
        # hack for darwin, which doesn't understand "-Wl,-install_name,"
        env['MY_SHNAME'] = '-soname='
        pass
    env['MY_SHLINK'] = env['SHLINKFLAGS']
    
    ctx.declare_build_external(
        name='clhep',
        url = 'clhep-${EXT_BUNDLED_CLHEP_VERSION}.tgz',
        url_md5 = '1702822f6236493c60f9f4ecdbcd19b6',
        install_dir = 'clhep-install',
        configure_cmd = '../clhep/CLHEP/configure --prefix=${EXT_BUNDLED_CLHEP_PREFIX}',
        # it seems the makefiles for clhep-1.9.4.7 are not parallel-safe...
        #build_cmd = 'make -j%s' % waflib.Options.options.jobs,
        build_cmd = 'make',
        install_cmd = 'make install',
        env=env,
        )
    msg.warn('building clhep from sources... [done]')
    ctx.env['BUNDLED_CLHEP'] = 1
    clhep_config_bin=subst_vars(
        '${EXT_BUNDLED_CLHEP_PREFIX}/bin/clhep-config',
        ctx.env)


    ctx.find_program(
        clhep_config_bin,
        var='CLHEP-CONFIG',
        **common_cfg)

    ctx.check_cfg(
        path=clhep_config_bin,
        args='--include --libs --ldflags',
        package='',
        uselib_store='CLHEP',
        )

    clhep_libs = '''\
    CLHEP-Cast
    CLHEP-Evaluator
    CLHEP-Exceptions
    CLHEP-GenericFunctions
    CLHEP-Geometry
    CLHEP-Matrix
    CLHEP-Random
    CLHEP-RandomObjects
    CLHEP-RefCount
    CLHEP-Vector
    '''

    for lib in clhep_libs.split():
        libname = lib.strip()
        for n in ('INCLUDES',
                  'LIBPATH',
                  'LINKFLAGS'):
            ctx.env['%s_%s'%(n,libname)] = ctx.env['%s_CLHEP'%n][:]
        # massage -lCLHEP-$(version)
        # into -lCLHEP-$(sublib)-$(version)
        ctx.env['LIB_%s'%libname] = [l.replace('CLHEP',libname)
                                     for l in ctx.env['LIB_CLHEP']]
        
    return

def build(ctx):

    root = subst_vars('${EXT_BUNDLED_CLHEP_PREFIX}', ctx.env)
    clhep_lib_root = os.path.join(root, 'lib')
    clhep_lib_root = ctx.root.find_dir(clhep_lib_root)
    libs = clhep_lib_root.ant_glob('**/*')
    for o in libs:
        o.sig = waflib.Utils.h_file(o.abspath())
        ctx.symlink_as(
            '${INSTALL_AREA}/lib/%s' % o,
            #src,
            o.abspath(),
            )
        pass
    ## ctx.install_files(
    ##     '${EXT_BUNDLED_CLHEP_PREFIX}/lib',
    ##     clhep_lib_root.ant_glob('**/*'),
    ##     #relative_trick=True,
    ##     chmod=waflib.Utils.O755,
    ##     )
        
    clhep_hdr_root = os.path.join(root, 'include')
    clhep_hdr_root = ctx.root.find_dir(clhep_hdr_root)
    hdrs = clhep_hdr_root.ant_glob('**/*')
    for o in hdrs:
        o.sig = waflib.Utils.h_file(o.abspath())
        ## ctx.symlink_as(
        ##     '${INSTALL_AREA}/include/%s' % o,
        ##     #src,
        ##     o.abspath(),
        ##     )
    ctx.install_files(
        '${EXT_BUNDLED_CLHEP_PREFIX}/include',
        hdrs,
        relative_trick=True,
        cwd=clhep_hdr_root,
        #chmod=waflib.Utils.O755,
        )
    return