build.py
author John Abraham <john.abraham@gatech.edu>
Sat, 21 Jan 2012 01:31:29 -0500
changeset 52 56f02f06febc
parent 51 e903a1eda531
child 54 003887235ed3
permissions -rwxr-xr-x
NetAnim: missing indent
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
#! /usr/bin/env python
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
import sys
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
from optparse import OptionParser
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
import os
18
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
     5
from xml.dom import minidom as dom
43
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
     6
import shlex
0
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
import constants
28
6cbc3d534abc If NSC build fails, just ignore it and build ns-3 without it.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 23
diff changeset
     9
from util import run_command, fatal, CommandError
0
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
13
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
    12
def build_nsc():
40
e17133ac5523 Use sys.executable to run python instead of hardcoded 'python'
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 37
diff changeset
    13
    run_command([sys.executable, 'scons.py'])
13
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
    14
    
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
    15
49
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    16
def build_netanim(qmakepath):
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    17
    qmake = 'qmake'
51
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    18
    qmakeFound = False
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    19
    try:
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    20
	run_command([qmake, '-v'])
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    21
	print "qmake found"
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    22
	qmakeFound = True
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    23
    except:
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    24
	print "Could not find qmake in the default path"
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    25
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    26
    try:
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    27
	if qmakeFound == False:
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    28
		run_command(['qmake-qt4', '-v'])
52
56f02f06febc NetAnim: missing indent
John Abraham <john.abraham@gatech.edu>
parents: 51
diff changeset
    29
		qmake = 'qmake-qt4'
56f02f06febc NetAnim: missing indent
John Abraham <john.abraham@gatech.edu>
parents: 51
diff changeset
    30
		print "qmake-qt4 found"
51
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    31
    except:
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    32
	print "Could not find qmake-qt4 in the default path"
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    33
	
49
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    34
    if qmakepath:
51
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
    35
	print "Setting qmake to user provided path"
49
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    36
        qmake = qmakepath
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    37
    try:    
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    38
    	if sys.platform in ['darwin']:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    39
    		run_command([qmake, '-spec', 'macx-g++', 'NetAnim.pro'])
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    40
    	else:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    41
    		run_command([qmake, 'NetAnim.pro'])
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    42
    	run_command(['make'])
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    43
    except OSError:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    44
        print "Error building NetAnim. Ensure the path to qmake is correct"
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    45
        print "Note: Some systems use qmake-qt4 instead of qmake"
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    46
        print "Skipping NetAnim ...."
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    47
	pass
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    48
    except:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    49
        print "Error building NetAnim."
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    50
        print "Skipping NetAnim ...."
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    51
	pass
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
    52
43
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
    53
def build_ns3(config, build_examples, build_tests, args, build_options):
42
05ffdbe108d4 Pass build.py options after -- to ns-3 waf configure
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 40
diff changeset
    54
    cmd = [sys.executable, "waf", "configure"] + args
13
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
    55
37
a03889bf55b1 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 36
diff changeset
    56
    if build_examples:
a03889bf55b1 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 36
diff changeset
    57
        cmd.append("--enable-examples")
36
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
    58
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
    59
    if build_tests:
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
    60
        cmd.append("--enable-tests")
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
    61
18
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    62
    try:
33
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    63
        ns3_traces, = config.getElementsByTagName("ns-3-traces")
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    64
    except ValueError:
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    65
        # Don't print a warning message here since regression traces
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    66
        # are no longer used.
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    67
        pass
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    68
    else:
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    69
        cmd.extend([
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    70
                "--with-regression-traces", os.path.join("..", ns3_traces.getAttribute("dir")),
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    71
                ])
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    72
70764f72b46f Fix Bug 1036: download.py doesn't let user specify regression traces
Mitch Watrous <watrous@u.washington.edu>
parents: 32
diff changeset
    73
    try:
18
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    74
        pybindgen, = config.getElementsByTagName("pybindgen")
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    75
    except ValueError:
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    76
        print "Note: configuring ns-3 without pybindgen"
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    77
    else:
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    78
        cmd.extend([
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    79
                "--with-pybindgen", os.path.join("..", pybindgen.getAttribute("dir")),
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    80
        ])
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    81
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    82
    try:
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    83
        nsc, = config.getElementsByTagName("nsc")
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    84
    except ValueError:
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    85
        print "Note: configuring ns-3 without NSC"
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    86
    else:
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    87
        # Build NSC if the architecture supports it
23
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
    88
        if sys.platform not in ['linux2']:
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
    89
            arch = None
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
    90
        else:
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
    91
            arch = os.uname()[4]
18
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    92
        if arch == 'x86_64' or arch == 'i686' or arch == 'i586' or arch == 'i486' or arch == 'i386':
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    93
            cmd.extend(["--with-nsc", os.path.join("..", nsc.getAttribute("dir"))])
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    94
        else:
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
    95
            print "Note: configuring ns-3 without NSC (architecture not supported)"
13
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
    96
43
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
    97
    run_command(cmd) # waf configure ...
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
    98
    run_command([sys.executable, "waf", "build"] + build_options)
13
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
    99
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
   100
0
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   101
def main(argv):
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
    parser = OptionParser()
29
20922476c714 Add a --disable-nsc option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 28
diff changeset
   103
    parser.add_option('--disable-nsc',
50
bda5b48f0834 clarify NSC default build is on Linux
Tom Henderson <tomh@tomh.org>
parents: 49
diff changeset
   104
                      help=("Don't try to build NSC (built by default on Linux)"), action="store_true", default=False,
29
20922476c714 Add a --disable-nsc option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 28
diff changeset
   105
                      dest='disable_nsc')
49
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   106
    parser.add_option('--disable-netanim',
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   107
                      help=("Don't try to build NetAnim (built by default)"), action="store_true", default=False,
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   108
                      dest='disable_netanim')
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   109
    parser.add_option('--qmake-path',
51
e903a1eda531 NetAnim: build.py Try alternative qmake before giving up
John Abraham <john.abraham@gatech.edu>
parents: 50
diff changeset
   110
                      help=("Provide absolute path to qmake executable for NetAnim"), action="store",
49
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   111
                      dest='qmake_path')
37
a03889bf55b1 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 36
diff changeset
   112
    parser.add_option('--enable-examples',
a03889bf55b1 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 36
diff changeset
   113
                      help=("Do try to build examples (not built by default)"), action="store_true", default=False,
a03889bf55b1 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 36
diff changeset
   114
                      dest='enable_examples')
36
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
   115
    parser.add_option('--enable-tests',
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
   116
                      help=("Do try to build tests (not built by default)"), action="store_true", default=False,
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
   117
                      dest='enable_tests')
43
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
   118
    parser.add_option('--build-options',
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
   119
                      help=("Add these options to ns-3's \"waf build\" command"),
44
063172887f48 Fix build.py when --build-options default value
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 43
diff changeset
   120
                      default='', dest='build_options')
0
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
    (options, args) = parser.parse_args()
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
23
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   123
    cwd = os.getcwd()
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   124
18
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
   125
    try:
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
   126
        dot_config = open(".config", "rt")
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
   127
    except IOError:
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
   128
        print >> sys.stderr, "** ERROR: missing .config file; you probably need to run the download.py script first."
19
59bfecde0bb1 A couple of bug fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 18
diff changeset
   129
        sys.exit(2)
59bfecde0bb1 A couple of bug fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 18
diff changeset
   130
18
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
   131
    config = dom.parse(dot_config)
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
   132
    dot_config.close()
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
   133
29
20922476c714 Add a --disable-nsc option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 28
diff changeset
   134
    if options.disable_nsc:
20922476c714 Add a --disable-nsc option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 28
diff changeset
   135
        print "# Skip NSC (by user request)"
20922476c714 Add a --disable-nsc option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 28
diff changeset
   136
        for node in config.getElementsByTagName("nsc"):
20922476c714 Add a --disable-nsc option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 28
diff changeset
   137
            config.documentElement.removeChild(node)
20922476c714 Add a --disable-nsc option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 28
diff changeset
   138
    elif sys.platform in ['darwin', 'win32']:
23
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   139
        print "# Skip NSC (platform not supported)"
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   140
    else:
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   141
        nsc_config_elems = config.getElementsByTagName("nsc")
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   142
        if nsc_config_elems:
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   143
            nsc_config, = nsc_config_elems
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   144
            nsc_dir = nsc_config.getAttribute("dir")
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   145
            print "# Build NSC"
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   146
            os.chdir(nsc_dir)
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   147
            print "Entering directory `%s'" % nsc_dir
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   148
            try:
30
a27797fe2367 bug 616: python problems with ns3.4 on RH family
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 29
diff changeset
   149
                try:
a27797fe2367 bug 616: python problems with ns3.4 on RH family
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 29
diff changeset
   150
                    build_nsc()
a27797fe2367 bug 616: python problems with ns3.4 on RH family
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 29
diff changeset
   151
                except CommandError:
a27797fe2367 bug 616: python problems with ns3.4 on RH family
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 29
diff changeset
   152
                    print "# Build NSC: failure (ignoring NSC)"
a27797fe2367 bug 616: python problems with ns3.4 on RH family
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 29
diff changeset
   153
                    config.documentElement.removeChild(nsc_config)
23
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   154
            finally:
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   155
                os.chdir(cwd)
f8b0a9e91570 win32 fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 19
diff changeset
   156
            print "Leaving directory `%s'" % nsc_dir
13
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
   157
49
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   158
    if options.disable_netanim:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   159
        print "# Skip NetAnimC (by user request)"
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   160
        for node in config.getElementsByTagName("netanim"):
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   161
            config.documentElement.removeChild(node)
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   162
    elif sys.platform in ['cygwin', 'win32']:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   163
        print "# Skip NetAnim (platform not supported)"
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   164
    else:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   165
        netanim_config_elems = config.getElementsByTagName("netanim")
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   166
        if netanim_config_elems:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   167
            netanim_config, = netanim_config_elems
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   168
            netanim_dir = netanim_config.getAttribute("dir")
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   169
            print "# Build NetAnim"
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   170
            os.chdir(netanim_dir)
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   171
            print "Entering directory `%s'" % netanim_dir
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   172
            try:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   173
                try:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   174
                    build_netanim(options.qmake_path)
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   175
                except CommandError:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   176
                    print "# Build NetAnim: failure (ignoring NetAnim)"
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   177
                    config.documentElement.removeChild(netanim_config)
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   178
            finally:
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   179
                os.chdir(cwd)
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   180
            print "Leaving directory `%s'" % netanim_dir
a87aaf87bba6 Add netanim to ns-3-allinone
Tom Henderson <tomh@tomh.org>
parents: 44
diff changeset
   181
37
a03889bf55b1 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 36
diff changeset
   182
    if options.enable_examples:
a03889bf55b1 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 36
diff changeset
   183
        print "# Building examples (by user request)"
a03889bf55b1 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 36
diff changeset
   184
        build_examples = True
a03889bf55b1 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 36
diff changeset
   185
    else:
36
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
   186
        build_examples = False
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
   187
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
   188
    if options.enable_tests:
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
   189
        print "# Building tests (by user request)"
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
   190
        build_tests = True
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
   191
    else:
456034b854e1 Make build.py allow tests to be enabled
Mitch Watrous <watrous@u.washington.edu>
parents: 35
diff changeset
   192
        build_tests = False
13
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
   193
43
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
   194
    if options.build_options is None:
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
   195
        build_options = None
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
   196
    else:
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
   197
        build_options = shlex.split(options.build_options)
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
   198
13
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
   199
    print "# Build NS-3"
18
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
   200
    ns3_config, = config.getElementsByTagName("ns-3")
32ed689ba78d Switch to a single .config XML file, instead of BRANCH and REPO-BRANCH files. Save more state between download.py and build.py.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 17
diff changeset
   201
    d = os.path.join(os.path.dirname(__file__), ns3_config.getAttribute("dir"))
0
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   202
    print "Entering directory `%s'" % d
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   203
    os.chdir(d)
13
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
   204
    try:
43
586b5fcd78b1 Add a --build-options option to build.py
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 42
diff changeset
   205
        build_ns3(config, build_examples, build_tests, args, build_options)
13
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
   206
    finally:
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
   207
        os.chdir(cwd)
0e5fbb71b791 Also build NSC if the architecture supports it
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8
diff changeset
   208
    print "Leaving directory `%s'" % d
0
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   209
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   210
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   211
    return 0
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   212
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   213
if __name__ == '__main__':
b3cf4a666ff5 initial draft of the 'all-in-one' build system
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   214
    sys.exit(main(sys.argv))