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