2009-01-19 21:05:46 +03:00
# -------------------------------------------------------------------------- #
2023-01-09 14:23:19 +03:00
# Copyright 2002-2023, 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. #
2019-09-06 14:30:23 +03:00
# -------------------------------------------------------------------------- #
2008-06-17 20:27:32 +04:00
import os
import SCons
############
# BUILDERS #
############
2019-09-06 14:30:23 +03:00
2008-06-17 20:27:32 +04:00
def build_lex ( target , source , env ) :
2019-09-06 14:30:23 +03:00
cwd = os . getcwd ( )
src = SCons . Util . to_String ( source [ 0 ] )
src_dir = os . path . dirname ( src )
src_name = os . path . basename ( src )
2009-04-23 21:24:12 +04:00
os . chdir ( src_dir )
os . system ( " flex " + src_name )
os . chdir ( cwd )
2019-09-06 14:30:23 +03:00
2009-04-23 21:24:12 +04:00
return None
2019-09-06 14:30:23 +03:00
2008-06-17 20:27:32 +04:00
def emitter_lex ( target , source , env ) :
2019-09-06 14:30:23 +03:00
src = SCons . Util . to_String ( source [ 0 ] )
( src_name , src_ext ) = os . path . splitext ( os . path . basename ( src ) )
2009-04-23 21:24:12 +04:00
target . append ( src_name + " .h " )
return target , source
2019-09-06 14:30:23 +03:00
2008-06-17 20:27:32 +04:00
def add_lex ( environment ) :
2019-09-06 14:30:23 +03:00
lex_bld = SCons . Builder . Builder ( action = build_lex ,
suffix = ' .cc ' ,
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 ) :
2019-09-06 14:30:23 +03:00
cwd = os . getcwd ( )
2008-06-17 20:27:32 +04:00
2019-09-06 14:30:23 +03: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
2019-09-06 14:30:23 +03:00
2008-06-17 20:27:32 +04:00
def emitter_bison ( target , source , env ) :
2019-09-06 14:30:23 +03:00
src = SCons . Util . to_String ( source [ 0 ] )
( src_name , src_ext ) = os . path . splitext ( os . path . basename ( src ) )
2009-04-23 21:24:12 +04:00
target . append ( src_name + " .h " )
return target , source
2008-06-17 20:27:32 +04:00
2019-09-06 14:30:23 +03:00
2008-06-17 20:27:32 +04:00
def add_bison ( environment ) :
2019-09-06 14:30:23 +03:00
bison_bld = SCons . Builder . Builder ( action = build_bison ,
suffix = ' .cc ' ,
src_suffix = ' .y ' ,
emitter = emitter_bison )
environment . Append ( BUILDERS = { ' Bison ' : bison_bld } )