1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
#! /usr/bin/env python
from __future__ import print_function
import sys
from optparse import OptionParser
import os
from xml.dom import minidom as dom
import shlex
import constants
from util import run_command, fatal, CommandError
def build_netanim(qmakepath):
qmake = 'qmake'
qmakeFound = False
try:
run_command([qmake, '-v'])
print("qmake found")
qmakeFound = True
except:
print("Could not find qmake in the default path")
try:
if qmakeFound == False:
run_command(['qmake-qt4', '-v'])
qmake = 'qmake-qt4'
print("qmake-qt4 found")
except:
print("Could not find qmake-qt4 in the default path")
if qmakepath:
print("Setting qmake to user provided path")
qmake = qmakepath
try:
if sys.platform in ['darwin']:
run_command([qmake, '-spec', 'macx-g++', 'NetAnim.pro'])
else:
run_command([qmake, 'NetAnim.pro'])
run_command(['make'])
except OSError:
print("Error building NetAnim. Ensure the path to qmake is correct.")
print("Could not find qmake or qmake-qt4 in the default PATH.")
print("Use ./build.py --qmake-path <Path-to-qmake>, if qmake is installed in a non-standard location")
print("Note: Some systems use qmake-qt4 instead of qmake")
print("Skipping NetAnim ....")
pass
except:
print("Error building NetAnim.")
print("Skipping NetAnim ....")
pass
def build_ns3(config, build_examples, build_tests, args, build_options):
cmd = [sys.executable, "waf", "configure"] + args
if build_examples:
cmd.append("--enable-examples")
if build_tests:
cmd.append("--enable-tests")
try:
ns3_traces, = config.getElementsByTagName("ns-3-traces")
except ValueError:
# Don't print a warning message here since regression traces
# are no longer used.
pass
else:
cmd.extend([
"--with-regression-traces", os.path.join("..", ns3_traces.getAttribute("dir")),
])
try:
pybindgen, = config.getElementsByTagName("pybindgen")
except ValueError:
print("Note: configuring ns-3 without pybindgen")
else:
cmd.extend([
"--with-pybindgen", os.path.join("..", pybindgen.getAttribute("dir")),
])
run_command(cmd) # waf configure ...
run_command([sys.executable, "waf", "build"] + build_options)
def main(argv):
parser = OptionParser()
parser.add_option('--disable-netanim',
help=("Don't try to build NetAnim (built by default)"), action="store_true", default=False,
dest='disable_netanim')
parser.add_option('--qmake-path',
help=("Provide absolute path to qmake executable for NetAnim"), action="store",
dest='qmake_path')
parser.add_option('--enable-examples',
help=("Do try to build examples (not built by default)"), action="store_true", default=False,
dest='enable_examples')
parser.add_option('--enable-tests',
help=("Do try to build tests (not built by default)"), action="store_true", default=False,
dest='enable_tests')
parser.add_option('--build-options',
help=("Add these options to ns-3's \"waf build\" command"),
default='', dest='build_options')
(options, args) = parser.parse_args()
cwd = os.getcwd()
try:
dot_config = open(".config", "rt")
except IOError:
print("** ERROR: missing .config file; you probably need to run the download.py script first.", file=sys.stderr)
sys.exit(2)
config = dom.parse(dot_config)
dot_config.close()
if options.disable_netanim:
print("# Skip NetAnimC (by user request)")
for node in config.getElementsByTagName("netanim"):
config.documentElement.removeChild(node)
elif sys.platform in ['cygwin', 'win32']:
print("# Skip NetAnim (platform not supported)")
else:
netanim_config_elems = config.getElementsByTagName("netanim")
if netanim_config_elems:
netanim_config, = netanim_config_elems
netanim_dir = netanim_config.getAttribute("dir")
print("# Build NetAnim")
os.chdir(netanim_dir)
print("Entering directory `%s'" % netanim_dir)
try:
try:
build_netanim(options.qmake_path)
except CommandError:
print("# Build NetAnim: failure (ignoring NetAnim)")
config.documentElement.removeChild(netanim_config)
finally:
os.chdir(cwd)
print("Leaving directory `%s'" % netanim_dir)
if options.enable_examples:
print("# Building examples (by user request)")
build_examples = True
else:
build_examples = False
if options.enable_tests:
print("# Building tests (by user request)")
build_tests = True
else:
build_tests = False
if options.build_options is None:
build_options = None
else:
build_options = shlex.split(options.build_options)
print("# Build NS-3")
ns3_config, = config.getElementsByTagName("ns-3")
d = os.path.join(os.path.dirname(__file__), ns3_config.getAttribute("dir"))
print("Entering directory `%s'" % d)
os.chdir(d)
try:
build_ns3(config, build_examples, build_tests, args, build_options)
finally:
os.chdir(cwd)
print("Leaving directory `%s'" % d)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))
|