#!/usr/bin/python
-# Copyright (c) 2013 Nicira, Inc.
+# Copyright (c) 2013, 2014 Nicira, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
HOME = ENV["HOME"]
OVS_SRC = HOME + "/ovs"
ROOT = HOME + "/root"
-PATH = "%(ovs)s/utilities:%(ovs)s/ovsdb:%(ovs)s/vswitchd" % {"ovs": OVS_SRC}
+BUILD_GCC = OVS_SRC + "/_build-gcc"
+BUILD_CLANG = OVS_SRC + "/_build-clang"
+PATH = "%(ovs)s/utilities:%(ovs)s/ovsdb:%(ovs)s/vswitchd" % {"ovs": BUILD_GCC}
-ENV["CFLAGS"] = "-g -O0 -Wall -Wextra -Wno-deprecated-declarations"
+ENV["CFLAGS"] = "-g -fno-omit-frame-pointer"
ENV["PATH"] = PATH + ":" + ENV["PATH"]
options = None
def conf():
tag()
- configure = ["./configure", "--prefix=" + ROOT, "--localstatedir=" + ROOT,
+
+ try:
+ os.remove(OVS_SRC + "/Makefile")
+ except OSError:
+ pass
+
+ configure = ["../configure", "--prefix=" + ROOT, "--localstatedir=" + ROOT,
"--with-logdir=%s/log" % ROOT, "--with-rundir=%s/run" % ROOT,
- "--with-linux=/lib/modules/%s/build" % uname(),
- "--with-dbdir=" + ROOT]
+ "--enable-silent-rules", "--with-dbdir=" + ROOT, "--silent"]
if options.werror:
configure.append("--enable-Werror")
if options.mandir:
configure.append("--mandir=" + options.mandir)
+ if options.optimize is None:
+ options.optimize = 0
+ ENV["CFLAGS"] = "%s -O%d" % (ENV["CFLAGS"], options.optimize)
+
_sh("./boot.sh")
- _sh(*configure)
+
+ try:
+ os.mkdir(BUILD_GCC)
+ except OSError:
+ pass # Directory exists.
+
+ os.chdir(BUILD_GCC)
+ _sh(*(configure + ["--with-linux=/lib/modules/%s/build" % uname()]))
+
+ try:
+ _sh("clang --version", check=True)
+ clang = True
+ except subprocess.CalledProcessError:
+ clang = False
+
+ try:
+ _sh("sparse --version", check=True)
+ sparse = True
+ except subprocess.CalledProcessError:
+ sparse = False
+
+ if clang:
+ try:
+ os.mkdir(BUILD_CLANG)
+ except OSError:
+ pass # Directory exists.
+
+ ENV["CC"] = "clang"
+ os.chdir(BUILD_CLANG)
+ _sh(*configure)
+
+ if sparse:
+ c1 = "C=1"
+ else:
+ c1 = ""
+
+ os.chdir(OVS_SRC)
+
+ make_str = "\t$(MAKE) -C %s $@\n"
+
+ mf = open(OVS_SRC + "/Makefile", "w")
+ mf.write("all:\n%:\n")
+ if clang:
+ mf.write(make_str % BUILD_CLANG)
+ mf.write("\t$(MAKE) -C %s %s $@\n" % (BUILD_GCC, c1))
+ mf.write("\ncheck:\n")
+ mf.write(make_str % BUILD_GCC)
+ mf.close()
commands.append(conf)
def make(args=""):
make = "make -s -j 8 " + args
- try:
- _sh("cgcc", "--version", capture=True)
- make += " C=1"
- except OSError:
- pass
_sh(make)
commands.append(make)
_sh("ovs-vsctl --no-wait set Open_vSwitch %s ovs_version=%s"
% (root_uuid, version))
- cmd = [OVS_SRC + "/vswitchd/ovs-vswitchd"]
+ cmd = [BUILD_GCC + "/vswitchd/ovs-vswitchd"]
if options.gdb:
cmd = ["gdb", "--args"] + cmd
elif options.valgrind:
- cmd = ["valgrind", "--track-origins=yes"] + cmd
+ cmd = ["valgrind", "--track-origins=yes", "--leak-check=full",
+ "--suppressions=%s/tests/glibc.supp" % OVS_SRC,
+ "--suppressions=%s/tests/openssl.supp" % OVS_SRC] + cmd
else:
cmd = ["sudo"] + cmd
opts = opts + ["-vconsole:off", "--detach"]
# First install the basic requirements needed to build Open vSwitch.
sudo apt-get install git build-essential libtool autoconf pkg-config \\
- libssl-dev pkg-config gdb linux-headers-`uname -r`
+ libssl-dev gdb linux-headers-`uname -r`
# Next clone the Open vSwitch source.
- git clone git://git.openvswitch.org/openvswitch %(ovs)s
+ git clone https://github.com/openvswitch/ovs.git %(ovs)s
# Setup environment variables.
`%(v)s env`
action="store_true", help="configure with cached timing")
group.add_option("--mandir", dest="mandir", metavar="MANDIR",
help="configure the man documentation install directory")
+
+ for i in range(4):
+ group.add_option("--O%d" % i, dest="optimize", action="store_const",
+ const=i, help="compile with -O%d" % i)
parser.add_option_group(group)
group = optparse.OptionGroup(parser, "run")