1 # -*- coding: utf-8 -*-
\r
3 # *********************************************************************
\r
5 # Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
\r
7 # *********************************************************************
\r
9 # Licensed under the Apache License, Version 2.0 (the "License");
\r
10 # you may not use this file except in compliance with the License.
\r
11 # You may obtain a copy of the License at
\r
13 # http:#www.apache.org/licenses/LICENSE-2.0
\r
15 # Unless required by applicable law or agreed to in writing, software
\r
16 # distributed under the License is distributed on an "AS IS" BASIS,
\r
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
18 # See the License for the specific language governing permissions and
\r
19 # limitations under the License.
\r
21 # *********************************************************************
\r
23 # This builder executes configure
\r
25 import os, subprocess
\r
26 import SCons.Builder, SCons.Node, SCons.Errors
\r
28 # Create the output message
\r
30 # @param s original message
\r
31 # @param target target name
\r
32 # @param source source name
\r
33 # @param env environment object
\r
34 def __message( s, target, source, env ) :
\r
35 print "Configuring using [%s] ..." % (source[0])
\r
39 # @param target target file on the local drive
\r
40 # @param source URL for download
\r
41 # @@param env environment object
\r
42 def __action( target, source, env ) :
\r
46 if env["PLATFORM"] in ["win32"] :
\r
47 if env.WhereIs("cmd") :
\r
48 # TODO: Add Windows Support
\r
51 # read the tools on *nix systems and sets the default parameters
\r
52 elif env["PLATFORM"] in ["darwin", "linux", "posix"] :
\r
53 if env.WhereIs("sh") :
\r
57 raise SCons.Errors.StopError("Configure shell on this platform [%s] unkown" % (env["PLATFORM"]))
\r
59 # We need to be in the target's directory
\r
60 cwd = os.path.dirname(os.path.realpath(target[0].path))
\r
62 # build it now (we need the shell, because some programs need it)
\r
63 devnull = open(os.devnull, "wb")
\r
64 handle = subprocess.Popen( cmd, shell=True, cwd=cwd, stdout=devnull )
\r
66 if handle.wait() <> 0 :
\r
67 raise SCons.Errors.BuildError( "Configuring script [%s] on the source [%s]" % (cmd, source[0]) )
\r
69 # Define the builder's emitter
\r
71 # @param target target file on the local drive
\r
73 # @param env environment object
\r
74 def __emitter( target, source, env ) :
\r
75 return target, source
\r
77 # Generate function which adds the builder to the environment,
\r
79 # @param env environment object
\r
80 def generate( env ) :
\r
81 env["BUILDERS"]["Configure"] = SCons.Builder.Builder( action = __action, emitter = __emitter, target_factory = SCons.Node.FS.File, source_factory = SCons.Node.FS.File, single_source = True, PRINT_CMD_LINE_FUNC = __message )
\r
83 # Exist function for the builder
\r
85 # @param env environment object
\r