2009-01-19 21:05:46 +03:00
# -------------------------------------------------------------------------- #
2019-01-16 13:27:59 +03:00
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
2009-01-19 21:05:46 +03:00
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
2008-06-17 20:27:32 +04:00
import os
import SCons
############
# BUILDERS #
############
def build_lex ( target , source , env ) :
2009-04-23 21:24:12 +04:00
cwd = os . getcwd ( )
src = SCons . Util . to_String ( source [ 0 ] )
src_dir = os . path . dirname ( src )
src_name = os . path . basename ( src )
os . chdir ( src_dir )
os . system ( " flex " + src_name )
os . chdir ( cwd )
return None
2008-06-17 20:27:32 +04:00
def emitter_lex ( target , source , env ) :
2009-04-23 21:24:12 +04:00
src = SCons . Util . to_String ( source [ 0 ] )
src_dir = os . path . dirname ( src )
( src_name , src_ext ) = os . path . splitext ( os . path . basename ( src ) )
target . append ( src_name + " .h " )
return target , source
2008-06-17 20:27:32 +04:00
def add_lex ( environment ) :
2009-04-23 21:24:12 +04:00
lex_bld = SCons . Builder . Builder ( action = build_lex ,
2018-03-18 01:31:52 +03:00
suffix = ' .cc ' ,
2009-04-23 21:24:12 +04:00
src_suffix = ' .l ' ,
emitter = emitter_lex )
environment . Append ( BUILDERS = { ' Lex ' : lex_bld } )
2008-06-17 20:27:32 +04:00
def build_bison ( target , source , env ) :
2009-04-23 21:24:12 +04:00
cwd = os . getcwd ( )
2008-06-17 20:27:32 +04:00
2009-04-23 21:24:12 +04:00
src = SCons . Util . to_String ( source [ 0 ] )
src_dir = os . path . dirname ( src )
src_name = os . path . basename ( src )
( base , ext ) = os . path . splitext ( src_name )
2008-06-17 20:27:32 +04:00
2009-04-23 21:24:12 +04:00
os . chdir ( src_dir )
os . system ( " bison " + src_name )
os . rename ( base + " .hh " , base + " .h " )
os . chdir ( cwd )
2008-06-17 20:27:32 +04:00
2009-04-23 21:24:12 +04:00
return None
2008-06-17 20:27:32 +04:00
def emitter_bison ( target , source , env ) :
2009-04-23 21:24:12 +04:00
src = SCons . Util . to_String ( source [ 0 ] )
src_dir = os . path . dirname ( src )
( src_name , src_ext ) = os . path . splitext ( os . path . basename ( src ) )
target . append ( src_name + " .h " )
return target , source
2008-06-17 20:27:32 +04:00
def add_bison ( environment ) :
2009-04-23 21:24:12 +04:00
bison_bld = SCons . Builder . Builder ( action = build_bison ,
suffix = ' .cc ' ,
src_suffix = ' .y ' ,
emitter = emitter_bison )
environment . Append ( BUILDERS = { ' Bison ' : bison_bld } )