Testcases: allow specifying build directory name
diff --git a/tests/SConstruct b/tests/SConstruct
index af97188..fb578fd 100644
--- a/tests/SConstruct
+++ b/tests/SConstruct
@@ -4,6 +4,7 @@
 build appropriately.
 
 You can modify the behavious using following options:
+BUILDDIR    Directory to build into (default "build")
 CC          Name of C compiler
 CXX         Name of C++ compiler
 CCFLAGS     Flags to pass to the C compiler
@@ -23,8 +24,6 @@
 import os
 import platform
 env = Environment(ENV = os.environ)
-env.SConsignFile("build/sconsign")
-env.Replace(CONFIGUREDIR = "build/config")
 
 # Allow giving environment flags on command line.
 list_vars = ['CCFLAGS', 'CXXFLAGS', 'LINKFLAGS', 'LINKLIBS', 'PROTOCFLAGS']
@@ -34,6 +33,10 @@
     else:
         env.Replace(**{var: val})
 
+env.SetDefault(BUILDDIR = "build")
+env.SConsignFile(env['BUILDDIR'] + "/sconsign")
+env.Replace(CONFIGUREDIR = env['BUILDDIR'] + "/config")
+
 # If a cross compilation platform is given, apply the environment settings
 # from site_scons/platforms/X/X.py
 if ARGUMENTS.get('PLATFORM'):
@@ -215,7 +218,7 @@
 
 # Place build files under separate folder
 import os.path
-env['VARIANT_DIR'] = 'build'
+env['VARIANT_DIR'] = env['BUILDDIR']
 env['BUILD'] = '#' + env['VARIANT_DIR']
 env['COMMON'] = '#' + env['VARIANT_DIR'] + '/common'
 
diff --git a/tests/generator_relative_paths/SConscript b/tests/generator_relative_paths/SConscript
index 277a083..f7a4f52 100644
--- a/tests/generator_relative_paths/SConscript
+++ b/tests/generator_relative_paths/SConscript
@@ -26,9 +26,9 @@
 env.Command(["build/protobuf/any.pb.h", "build/simple.pb.h", "build/protobuf/any.pb.c", "build/simple.pb.c",],
             ["proto/protobuf/any.proto", "proto/simple.proto"],
 [
-    Delete("build/generator_relative_paths/build"),
-    Mkdir("build/generator_relative_paths/build"),
-    env['NANOPB_GENERATOR'] + " -Dbuild/generator_relative_paths/build -Ibuild/generator_relative_paths/proto $SOURCES"
+    Delete("$BUILDDIR/generator_relative_paths/build"),
+    Mkdir("$BUILDDIR/generator_relative_paths/build"),
+    env['NANOPB_GENERATOR'] + " -D$BUILDDIR/generator_relative_paths/build -I$BUILDDIR/generator_relative_paths/proto $SOURCES"
 ])
 
 env.Match("simple_pb_h_ok", ["build/simple.pb.h", "simple.expected"])
diff --git a/tests/regression/issue_494/SConscript b/tests/regression/issue_494/SConscript
index 84f4130..343f71f 100644
--- a/tests/regression/issue_494/SConscript
+++ b/tests/regression/issue_494/SConscript
@@ -7,8 +7,8 @@
 # The build rules here are a bit tricky to make the normal dependency
 # resolution intentionally fail. This causes the generator to use the fallback
 # define which had the problem with C++.
-env.Command("oneof.pb", "oneof.proto", "$PROTOC $PROTOCFLAGS -Ibuild/regression/issue_494 -o$TARGETS $SOURCES")
-env.Command(["oneof.pb.c", "oneof.pb.h"], "oneof.pb", env['NANOPB_GENERATOR'] + " -Dbuild/regression/issue_494 $SOURCES")
+env.Command("oneof.pb", "oneof.proto", "$PROTOC $PROTOCFLAGS -I$BUILDDIR/regression/issue_494 -o$TARGETS $SOURCES")
+env.Command(["oneof.pb.c", "oneof.pb.h"], "oneof.pb", env['NANOPB_GENERATOR'] + " -D$BUILDDIR/regression/issue_494 $SOURCES")
 env.NanopbProto("submessage.proto")
 env.Depends("oneof.pb", "submessage.proto")