Add support for linux build

Change-Id: I8065ea1b5f57bd6f93d4eb70201972dad9b021db
diff --git a/164.gzip/BUILD.gn b/164.gzip/BUILD.gn
index fdb507b..db5d8b4 100644
--- a/164.gzip/BUILD.gn
+++ b/164.gzip/BUILD.gn
@@ -2,6 +2,14 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/input.graphic",
+  "data/ref/input/input.log",
+  "data/ref/input/input.program",
+  "data/ref/input/input.random",
+  "data/ref/input/input.source",
+]
+
 executable("164.gzip") {
   testonly = true
 
@@ -28,11 +36,19 @@
     "-Wno-unused-variable",
   ]
   defines = [ "SPEC_CPU2000" ]
-  data = [
-    "data/ref/input/input.graphic",
-    "data/ref/input/input.log",
-    "data/ref/input/input.program",
-    "data/ref/input/input.random",
-    "data/ref/input/input.source",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/164.gzip/{{source_file_part}}",
   ]
 }
diff --git a/175.vpr/BUILD.gn b/175.vpr/BUILD.gn
index 9fef507..beab079 100644
--- a/175.vpr/BUILD.gn
+++ b/175.vpr/BUILD.gn
@@ -2,6 +2,11 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/net.in",
+  "data/ref/input/arch.in",
+]
+
 executable("175.vpr") {
   testonly = true
 
@@ -29,8 +34,19 @@
   ]
   cflags_c = [ "-Wno-sign-compare" ]
   defines = [ "SPEC_CPU2000" ]
-  data = [
-    "data/ref/input/net.in",
-    "data/ref/input/arch.in",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/175.vpr/{{source_file_part}}",
   ]
 }
diff --git a/176.gcc/BUILD.gn b/176.gcc/BUILD.gn
index 2b2f2cc..b7b62b0 100644
--- a/176.gcc/BUILD.gn
+++ b/176.gcc/BUILD.gn
@@ -73,7 +73,10 @@
     "src/version.c",
     "src/xcoffout.c",
   ]
-  defines = [ "HOST_WORDS_LITTLE_ENDIAN" ]
+  defines = [
+    "HOST_WORDS_LITTLE_ENDIAN",
+    "SPEC_CPU2000_NEED_ALLOCA_H",
+  ]
   cflags_c = [
     "-Wno-char-subscripts",
     "-Wno-enum-conversion",
diff --git a/177.mesa/BUILD.gn b/177.mesa/BUILD.gn
index 1da5166..3cf299a 100644
--- a/177.mesa/BUILD.gn
+++ b/177.mesa/BUILD.gn
@@ -2,6 +2,10 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/mesa.mesh",
+]
+
 executable("177.mesa") {
   testonly = true
 
@@ -74,7 +78,19 @@
     "-Wno-unused-function",
     "-Wno-unused-variable",
   ]
-  data = [
-    "data/ref/input/mesa.in",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/177.mesa/{{source_file_part}}",
   ]
 }
diff --git a/179.art/BUILD.gn b/179.art/BUILD.gn
index 73cb368..f0485a1 100644
--- a/179.art/BUILD.gn
+++ b/179.art/BUILD.gn
@@ -2,6 +2,12 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/a10.img",
+  "data/ref/input/c756hel.in",
+  "data/ref/input/hc.img",
+]
+
 executable("179.art") {
   testonly = true
 
@@ -13,9 +19,19 @@
     "-Wno-format",
     "-Wno-implicit-function-declaration",
   ]
-  data = [
-    "data/ref/input/a10.img",
-    "data/ref/input/c756hel.in",
-    "data/ref/input/hc.img",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/179.art/{{source_file_part}}",
   ]
 }
diff --git a/181.mcf/BUILD.gn b/181.mcf/BUILD.gn
index 82d8899..9f04590 100644
--- a/181.mcf/BUILD.gn
+++ b/181.mcf/BUILD.gn
@@ -2,6 +2,10 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/inp.in",
+]
+
 executable("181.mcf") {
   testonly = true
 
@@ -19,7 +23,19 @@
     "src/treeup.c",
   ]
   defines = [ "WANT_STDC_PROTO" ]
-  data = [
-    "data/ref/input/inp.in",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/181.mcf/{{source_file_part}}",
   ]
 }
diff --git a/183.equake/BUILD.gn b/183.equake/BUILD.gn
index 00db45e..1383a43 100644
--- a/183.equake/BUILD.gn
+++ b/183.equake/BUILD.gn
@@ -2,6 +2,10 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/inp.in",
+]
+
 executable("183.equake") {
   testonly = true
 
@@ -9,7 +13,19 @@
     "src/quake.c",
   ]
   defines = [ "SPEC_CPU2000" ]
-  data = [
-    "data/ref/input/inp.in",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/183.equake/{{source_file_part}}",
   ]
 }
diff --git a/186.crafty/BUILD.gn b/186.crafty/BUILD.gn
index 2648f5e..c7018f5 100644
--- a/186.crafty/BUILD.gn
+++ b/186.crafty/BUILD.gn
@@ -2,6 +2,10 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/crafty.in",
+]
+
 executable("186.crafty") {
   testonly = true
 
@@ -50,7 +54,19 @@
     "-Wno-implicit-function-declaration",
     "-Wno-unused-variable",
   ]
-  data = [
-    "data/ref/input/crafty.in",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/186.crafty/{{source_file_part}}",
   ]
 }
diff --git a/186.crafty/fuchsia.patch b/186.crafty/fuchsia.patch
index e1254dd..ce64791 100644
--- a/186.crafty/fuchsia.patch
+++ b/186.crafty/fuchsia.patch
@@ -1,15 +1,22 @@
 diff -Nau0rbB src/chess.h src.patched/chess.h
---- src/chess.h	2016-09-01 15:33:08.697210614 -0700
-+++ src.patched/chess.h	2016-09-07 14:19:33.324383889 -0700
-@@ -157,0 +158,5 @@
+--- src/chess.h	2016-08-22 14:46:59.700060616 -0700
++++ src.patched/chess.h	2016-12-12 14:25:40.129392207 -0800
+@@ -157,0 +158,12 @@
 +#if defined(__Fuchsia__)
 +#  define  LONG_HAS_64BITS      /* the data type "long [int]" is represented in 64 bits either as the compiler's default option.*/
 +#  define HAS_LONGLONG         /* the C compilation system supports the data-type "long long"(which is an extension to ANSI C) and represents data of this type with 64 bits  */
 +#  define UNIX                 /* system is posix-based */
 +#endif
++#if defined(__unix__) && defined(__x86_64__)
++#  define  LONG_HAS_64BITS      /* the data type "long [int]" is represented in 64 bits either as the compiler's default option.*/
++#  define HAS_LONGLONG         /* the C compilation system supports the data-type "long long"(which is an extension to ANSI C) and represents data of this type with 64 bits  */
++#  define LITTLE_ENDIAN_ARCH   /* machine stores bytes in "PC" order         */
++#  define UNIX                 /* system is unix-based                      */
++#  define LINUX
++#endif
 diff -Nau0rbB src/utility.c src.patched/utility.c
---- src/utility.c	2016-09-01 15:33:08.697210614 -0700
-+++ src.patched/utility.c	2016-09-07 14:16:31.965597129 -0700
+--- src/utility.c	2016-08-22 14:46:59.700060616 -0700
++++ src.patched/utility.c	2016-12-12 14:25:40.129392207 -0800
 @@ -23 +23 @@
 -#  if !defined(LINUX) && !defined(ALPHA) && !defined(HP) && !defined(CRAY1) && !defined(FreeBSD)
 +#  if !defined(LINUX) && !defined(ALPHA) && !defined(HP) && !defined(CRAY1) && !defined(FreeBSD) && !defined(__Fuchsia__)
diff --git a/188.ammp/BUILD.gn b/188.ammp/BUILD.gn
index d49354b..806f1f4 100644
--- a/188.ammp/BUILD.gn
+++ b/188.ammp/BUILD.gn
@@ -2,6 +2,10 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/ammp.in",
+]
+
 executable("188.ammp") {
   testonly = true
 
@@ -47,7 +51,19 @@
     "-Wno-unused-label",
     "-Wno-unused-variable",
   ]
-  data = [
-    "data/ref/input/ammp.in",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/188.ammp/{{source_file_part}}",
   ]
 }
diff --git a/252.eon/BUILD.gn b/252.eon/BUILD.gn
index 5e4e4a3..28d79b2 100644
--- a/252.eon/BUILD.gn
+++ b/252.eon/BUILD.gn
@@ -2,6 +2,14 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/chair.camera",
+  "data/ref/input/chair.control.cook",
+  "data/ref/input/chair.control.kajiya",
+  "data/ref/input/chair.control.rushmeier",
+  "data/ref/input/chair.surfaces",
+]
+
 executable("252.eon") {
   testonly = true
 
@@ -149,12 +157,23 @@
     "-Wno-sometimes-uninitialized",
     "-Wno-delete-non-virtual-dtor",
   ]
-  data = [
-    "data/ref/input/chair.camera",
-    "data/ref/input/chair.control.cook",
-    "data/ref/input/chair.control.kajiya",
-    "data/ref/input/chair.control.rushmeier",
-    "data/ref/input/chair.surfaces",
-  ]
   include_dirs = [ "src" ]
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+  if (current_os == "linux") {
+    libs = [ "pthread" ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/252.eon/{{source_file_part}}",
+  ]
 }
diff --git a/255.vortex/BUILD.gn b/255.vortex/BUILD.gn
index b0a6515..91cc121 100644
--- a/255.vortex/BUILD.gn
+++ b/255.vortex/BUILD.gn
@@ -2,6 +2,12 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/lendian1.raw",
+  "data/ref/input/lendian2.raw",
+  "data/ref/input/lendian3.raw",
+]
+
 executable("255.vortex") {
   sources = [
     "src/bitvec.c",
@@ -87,9 +93,19 @@
     "-Wno-unused-variable",
     "-fno-strict-aliasing",
   ]
-  data = [
-    "data/ref/input/lendian1.raw",
-    "data/ref/input/lendian2.raw",
-    "data/ref/input/lendian3.raw",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/255.vortex/{{source_file_part}}",
   ]
 }
diff --git a/256.bzip2/BUILD.gn b/256.bzip2/BUILD.gn
index 32d9853..9c5e506 100644
--- a/256.bzip2/BUILD.gn
+++ b/256.bzip2/BUILD.gn
@@ -2,6 +2,12 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/input.source",
+  "data/ref/input/input.graphic",
+  "data/ref/input/input.program",
+]
+
 executable("256.bzip2") {
   sources = [
     "src/bzip2.c",
@@ -12,9 +18,19 @@
     "-Wno-implicit-function-declaration",
     "-Wno-tautological-pointer-compare",
   ]
-  data = [
-    "data/ref/input/input.source",
-    "data/ref/input/input.graphic",
-    "data/ref/input/input.program",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/256.bzip2/{{source_file_part}}",
   ]
 }
diff --git a/300.twolf/BUILD.gn b/300.twolf/BUILD.gn
index a34fdc4..6d39baa 100644
--- a/300.twolf/BUILD.gn
+++ b/300.twolf/BUILD.gn
@@ -2,6 +2,13 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+inputs = [
+  "data/ref/input/ref.blk",
+  "data/ref/input/ref.cel",
+  "data/ref/input/ref.net",
+  "data/ref/input/ref.par",
+]
+
 executable("300.twolf") {
   sources = [
     "src/acceptt.c",
@@ -95,10 +102,19 @@
     "-Wno-sign-compare",
     "-Wno-unused-variable",
   ]
-  data = [
-    "data/ref/input/ref.blk",
-    "data/ref/input/ref.cel",
-    "data/ref/input/ref.net",
-    "data/ref/input/ref.par",
+  if (current_os == "fuchsia") {
+    data = inputs
+  } else {
+    data_deps = [
+      ":copy_inputs",
+    ]
+  }
+}
+
+copy("copy_inputs") {
+  visibility = [ ":*" ]
+  sources = inputs
+  outputs = [
+    "$root_out_dir/data/300.twolf/{{source_file_part}}",
   ]
 }
diff --git a/BUILD.gn b/BUILD.gn
index aa1418e..6889b90 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -6,7 +6,6 @@
   testonly = true
 
   deps = [
-    "benchmarks:speccpu2000_benchmark",
     "164.gzip",
     "175.vpr",
     "176.gcc",
@@ -20,5 +19,6 @@
     "255.vortex",
     "256.bzip2",
     "300.twolf",
+    "benchmarks:speccpu2000_benchmark",
   ]
 }
diff --git a/benchmarks/BUILD.gn b/benchmarks/BUILD.gn
index e6ec77e..01c729f 100644
--- a/benchmarks/BUILD.gn
+++ b/benchmarks/BUILD.gn
@@ -34,9 +34,15 @@
     "//third_party/glog",
   ]
 
-  libs = [
-    "launchpad",
-    "magenta",
-  ]
+  if (current_os == "linux") {
+    libs = [ "pthread" ]
+  }
+
+  if (current_os == "fuchsia") {
+    libs = [
+      "launchpad",
+      "magenta",
+    ]
+  }
   public_configs = [ ":util_config" ]
 }
diff --git a/benchmarks/main.cc b/benchmarks/main.cc
index 56e4b3a..8286adc 100644
--- a/benchmarks/main.cc
+++ b/benchmarks/main.cc
@@ -94,7 +94,7 @@
   CHECK_NOTNULL(c);
   tmpDir = c;
 
-  CHECK_EQ(mkdir(tmpDir.c_str(), 0600), 0)
+  CHECK_EQ(mkdir(tmpDir.c_str(), 0700), 0)
       << "Error while creating tmp dir: " << tmpDir.c_str()
       << ", error:" << strerror(errno);
 
diff --git a/benchmarks/spec_fixture.cc b/benchmarks/spec_fixture.cc
index befc417..c24eec5 100644
--- a/benchmarks/spec_fixture.cc
+++ b/benchmarks/spec_fixture.cc
@@ -9,11 +9,19 @@
 #include <fcntl.h>
 #include <fstream>
 #include <glog/logging.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#ifdef __unix__
+#include <spawn.h>
+#include <sys/wait.h>
+#endif
+
+#ifdef __Fuchsia__
 #include <launchpad/launchpad.h>
 #include <magenta/syscalls.h>
 #include <magenta/syscalls/object.h>
-#include <sys/stat.h>
-#include <unistd.h>
+#endif
 
 extern std::string executableDir;
 extern std::string tmpDir;
@@ -41,8 +49,7 @@
   DLOG(INFO) << "Changing dir to: " << executableDir.c_str();
   CHECK_EQ(chdir(executableDir.c_str()), 0) << "Not able to change dir to "
                                             << executableDir;
-
-  CHECK_EQ(mkdir(run_dir_name.c_str(), 0600), 0)
+  CHECK_EQ(mkdir(run_dir_name.c_str(), 0700), 0)
       << "Not able to create dir: " << run_dir_name
       << ", Error: " << strerror(errno);
 
@@ -50,8 +57,12 @@
       << "Error copying dir: " << run_dir_name
       << ", Error: " << strerror(errno);
 
-  CHECK_EQ(CopyFile(run_dir_name + "/" + benchmark_name, benchmark_name), 0)
+  std::string binary = run_dir_name + "/" + benchmark_name;
+  CHECK_EQ(CopyFile(binary, benchmark_name), 0)
       << "Error copying binary, Error: " << strerror(errno);
+
+  CHECK_EQ(chmod(binary.c_str(), 0700), 0)
+      << "Error changing file permission for binary: " << strerror(errno);
 }
 
 void SpecFixture::TearDown(benchmark::State& st) {
@@ -61,6 +72,7 @@
 }
 
 int SpecFixture::RunSpec(const char* args[], int args_length) {
+  int page_size = getpagesize();
   char** argv = new char*[args_length + 1];
   argv[0] = (char*)(benchmark_name.c_str());
   if (args_length > 0) {
@@ -76,7 +88,7 @@
   DLOG(INFO) << "Running benchmark";
 
   // Capture output
-  char buffer[PAGE_SIZE];
+  char buffer[page_size];
   int out_p[2];
   int old_stdout = dup(STDOUT_FILENO);
   if (pipe2(out_p, O_NONBLOCK) != 0) {
@@ -102,20 +114,19 @@
     LOG(ERROR) << "Error while running benchmark";
     ssize_t len;
     do {
-      len = read(out_p[0], buffer, PAGE_SIZE);
+      len = read(out_p[0], buffer, page_size);
       if (len == -1) {
         LOG(ERROR) << "Error reading from pipe, Error: " << strerror(errno);
         return errno;
       }
       fwrite(buffer, sizeof(char), len, stderr);
-    } while (len == PAGE_SIZE);
+    } while (len == page_size);
     fprintf(stderr, "\n");
     return 1;
   }
   return 0;
 }
 
-// TODO: This is for fuchsia, need to write linux specific
 #ifdef __Fuchsia__
 int SpecFixture::LaunchProcess(char** args, int args_length) {
   mx_handle_t handle = launchpad_launch_mxio(args[0], args_length, args);
@@ -145,3 +156,28 @@
   return proc_info.return_code;
 }
 #endif
+
+#ifdef __unix__
+int SpecFixture::LaunchProcess(char** args, int args_length) {
+  run_dir_name = tmpDir + "/" + benchmark_name + "/";
+  std::string command = run_dir_name + args[0];
+  char** argv = new char*[args_length + 1];
+  ScopedGuard guard([&]() { delete[] argv; });
+  for (int i = 0; i < args_length; i++) {
+    argv[i] = args[i];
+  }
+  argv[args_length] = NULL;
+  pid_t pid;
+  int status = posix_spawn(&pid, command.c_str(), NULL, NULL, argv, environ);
+  if (status == 0) {
+    if (waitpid(pid, &status, 0) != -1) {
+      return status;
+    } else {
+      LOG(ERROR) << "waitpid error: " << strerror(errno);
+    }
+  } else {
+    LOG(ERROR) << "posix_spawn error: " << strerror(status);
+  }
+  return -1;
+}
+#endif
diff --git a/benchmarks/spec_utils.cc b/benchmarks/spec_utils.cc
index 945761a..31371c1 100644
--- a/benchmarks/spec_utils.cc
+++ b/benchmarks/spec_utils.cc
@@ -6,9 +6,7 @@
 #include <dirent.h>
 #include <errno.h>
 #include <glog/logging.h>
-#include <launchpad/launchpad.h>
 #include <limits.h>
-#include <magenta/syscalls.h>
 #include <string>
 #include <sys/stat.h>
 #include <sys/stat.h>
@@ -91,7 +89,8 @@
 }
 
 int CopyFile(std::string dest, std::string src) {
-  char buf[PAGE_SIZE];
+  int page_size = getpagesize();
+  char buf[page_size];
   size_t size;
   DLOG(INFO) << "Copy " << src << " to " << dest;
   FILE* srcfile = fopen(src.c_str(), "rb");
@@ -103,7 +102,7 @@
     return errno;
   }
 
-  while ((size = fread(buf, 1, PAGE_SIZE, srcfile))) {
+  while ((size = fread(buf, 1, page_size, srcfile))) {
     if (fwrite(buf, 1, size, destfile) != size) {
       return errno;
     }
diff --git a/patch.sh b/patch.sh
index a18a70d..488a775 100755
--- a/patch.sh
+++ b/patch.sh
@@ -39,24 +39,24 @@
   local benchmark_dir=$1
   shift
   for i in $@; do
-    local benchmark="$benchmark_dir/$i"
-    if [[ -d "$benchmark" ]]; then
+    local benchmark="${benchmark_dir}/${i}"
+    if [[ -d "${benchmark}" ]]; then
       # check if we support that benchmark
-      if [[ -e "$SCRIPT_DIR/$i" ]]; then
-        echo "Copying src for $i....."
-        cp -r  -- "$benchmark/src" "$SCRIPT_DIR/$i/"
+      if [[ -e "${SCRIPT_DIR}/${i}" ]]; then
+        echo "Copying src for ${i}....."
+        cp -r  -- "${benchmark}/src" "${SCRIPT_DIR}/${i}/"
         # Some src have only read permission, so if script is
         # executed again source are not replaced
-        chmod -R u+w -- "$SCRIPT_DIR/$i/src"
+        chmod -R u+w -- "${SCRIPT_DIR}/${i}/src"
 
-        echo "Copying data for $i....."
-        cp -r -- "$benchmark/data" "$SCRIPT_DIR/$i/"
-        chmod -R u+w -- "$SCRIPT_DIR/$i/data"
+        echo "Copying data for ${i}....."
+        cp -r -- "${benchmark}/data" "${SCRIPT_DIR}/${i}/"
+        chmod -R u+w -- "${SCRIPT_DIR}/${i}/data"
 
         # check if we have a diff
-        if [[ -e "$SCRIPT_DIR/$i/fuchsia.patch" ]] ; then
-          echo "Patching $i.........."
-          patch -d "$SCRIPT_DIR/$i" --verbose -p0 < "$SCRIPT_DIR/$i/fuchsia.patch"
+        if [[ -e "${SCRIPT_DIR}/${i}/fuchsia.patch" ]] ; then
+          echo "Patching ${i}.........."
+          patch -d "${SCRIPT_DIR}/${i}" --verbose -p0 < "${SCRIPT_DIR}/${i}/fuchsia.patch"
         fi
         echo
       fi
@@ -71,3 +71,5 @@
 
 copynpatch "$1/benchspec/CINT2000" ${CINT_BLIST[*]}
 copynpatch "$1/benchspec/CFP2000" ${CFP_BLIST[*]}
+
+mv ${SCRIPT_DIR}/177.mesa/data/ref/input/mesa.in ${SCRIPT_DIR}/177.mesa/data/ref/input/mesa.mesh