Download patch instead of requiring it to be installed

Part of work to make the code build on a clean Stretch machine.

Change-Id: I1f7b9b51a84a98bc178b05e575ae4b314cf69c1c
diff --git a/WORKSPACE b/WORKSPACE
index 3e6145d..21b41f3 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1,44 +1,57 @@
-workspace(name = 'org_frc971')
+workspace(name = "org_frc971")
 
-load("//debian:python.bzl", python_debs="files")
-load("//debian:clang.bzl", clang_debs="files")
+load(
+    "//debian:python.bzl",
+    python_debs = "files",
+)
+load(
+    "//debian:clang.bzl",
+    clang_debs = "files",
+)
+load(
+    "//debian:patch.bzl",
+    patch_debs = "files",
+)
 load("//debian:packages.bzl", "generate_repositories_for_debs")
 
 generate_repositories_for_debs(python_debs)
+
 generate_repositories_for_debs(clang_debs)
 
+generate_repositories_for_debs(patch_debs)
+
 new_http_archive(
-  name = 'python_repo',
-  build_file = 'debian/python.BUILD',
-  sha256 = '21214b6386273698b6aa1b64bccf1bc8c5ef4ef44563871bac5cd85383575af5',
-  url = 'http://frc971.org/Build-Dependencies/python.tar.gz',
+    name = "python_repo",
+    build_file = "debian/python.BUILD",
+    sha256 = "21214b6386273698b6aa1b64bccf1bc8c5ef4ef44563871bac5cd85383575af5",
+    url = "http://frc971.org/Build-Dependencies/python.tar.gz",
 )
 
 new_http_archive(
-  name = 'clang_3p6_repo',
-  build_file = 'tools/cpp/clang_3p6/clang_3p6.BUILD',
-  sha256 = '5ee9e04c55c2c99d0c0f83722102a49e98f485fc274f73111b33a7ac4e34e03e',
-  url = 'http://frc971.org/Build-Dependencies/clang_3p6.tar.gz',
+    name = "clang_3p6_repo",
+    build_file = "tools/cpp/clang_3p6/clang_3p6.BUILD",
+    sha256 = "5ee9e04c55c2c99d0c0f83722102a49e98f485fc274f73111b33a7ac4e34e03e",
+    url = "http://frc971.org/Build-Dependencies/clang_3p6.tar.gz",
 )
 
 new_local_repository(
-  name = 'usr_repo',
-  path = '/usr',
-  build_file = 'debian/usr.BUILD',
+    name = "usr_repo",
+    build_file = "debian/usr.BUILD",
+    path = "/usr",
 )
 
 new_git_repository(
-  name = 'slycot_repo',
-  remote = 'https://github.com/avventi/Slycot.git',
-  build_file = 'debian/slycot.BUILD',
-  commit = '5af5f283cb23cbe23c4dfea4d5e56071bdbd6e70',
+    name = "slycot_repo",
+    build_file = "debian/slycot.BUILD",
+    commit = "5af5f283cb23cbe23c4dfea4d5e56071bdbd6e70",
+    remote = "https://github.com/avventi/Slycot.git",
 )
 
 new_http_archive(
-  name = 'arm_frc_linux_gnueabi_repo',
-  build_file = 'tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi.BUILD',
-  sha256 = '875b23bec5138e09e3d21cc1ff2727ea3ecbec57509c37589514ba50f92979c7',
-  url = 'http://frc971.org/Build-Dependencies/roborio-compiler-2018.tar.xz',
+    name = "arm_frc_linux_gnueabi_repo",
+    build_file = "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi.BUILD",
+    sha256 = "875b23bec5138e09e3d21cc1ff2727ea3ecbec57509c37589514ba50f92979c7",
+    url = "http://frc971.org/Build-Dependencies/roborio-compiler-2018.tar.xz",
 )
 
 # Recompressed version of the one downloaded from Linaro at
@@ -46,119 +59,128 @@
 # with workarounds for <https://github.com/bazelbuild/bazel/issues/574> and the
 # top-level folder stripped off.
 new_http_archive(
-  name = 'linaro_linux_gcc_4_9_repo',
-  build_file = 'compilers/linaro_linux_gcc_4.9.BUILD',
-  sha256 = '25e97bcb0af4fd7cd626d5bb1b303c7d2cb13acf2474e335e3d431d1a53fbb52',
-  url = 'http://frc971.org/Build-Dependencies/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf.tar.gz',
+    name = "linaro_linux_gcc_4_9_repo",
+    build_file = "compilers/linaro_linux_gcc_4.9.BUILD",
+    sha256 = "25e97bcb0af4fd7cd626d5bb1b303c7d2cb13acf2474e335e3d431d1a53fbb52",
+    url = "http://frc971.org/Build-Dependencies/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf.tar.gz",
 )
 
 new_git_repository(
-  name = 'python_gflags_repo',
-  remote = 'https://github.com/gflags/python-gflags.git',
-  build_file = 'debian/gflags.BUILD',
-  commit = '41c4571864f0db5823e07715317e7388e94faabc',
+    name = "python_gflags_repo",
+    build_file = "debian/gflags.BUILD",
+    commit = "41c4571864f0db5823e07715317e7388e94faabc",
+    remote = "https://github.com/gflags/python-gflags.git",
 )
 
 bind(
-  name = 'python-gflags',
-  actual = '@python_gflags_repo//:gflags',
+    name = "python-gflags",
+    actual = "@python_gflags_repo//:gflags",
 )
 
 new_http_archive(
-  name = 'python_glog_repo',
-  build_file = 'debian/glog.BUILD',
-  sha256 = '953fd80122c48023d1148e6d1bda2763fcab59c8a81682bb298238a5935547b0',
-  url = 'https://pypi.python.org/packages/source/g/glog/glog-0.1.tar.gz',
-  strip_prefix = 'glog-0.1',
+    name = "python_glog_repo",
+    build_file = "debian/glog.BUILD",
+    sha256 = "953fd80122c48023d1148e6d1bda2763fcab59c8a81682bb298238a5935547b0",
+    strip_prefix = "glog-0.1",
+    url = "https://pypi.python.org/packages/source/g/glog/glog-0.1.tar.gz",
 )
 
 bind(
-  name = 'python-glog',
-  actual = '@python_glog_repo//:glog',
+    name = "python-glog",
+    actual = "@python_glog_repo//:glog",
 )
 
 new_http_archive(
-  name = 'allwpilib_ni_libraries_repo_2018',
-  build_file = 'debian/ni-libraries-2018.BUILD',
-  sha256 = '05ef6701c77b83163b443aa956d151028861cc3fa29fdf2b6b77431b4a91bfb9',
-  url = 'http://frc971.org/Build-Dependencies/allwpilib_ni-libraries_57e9fb3.tar.gz',
-  strip_prefix = 'ni-libraries',
+    name = "allwpilib_ni_libraries_repo_2018",
+    build_file = "debian/ni-libraries-2018.BUILD",
+    sha256 = "05ef6701c77b83163b443aa956d151028861cc3fa29fdf2b6b77431b4a91bfb9",
+    strip_prefix = "ni-libraries",
+    url = "http://frc971.org/Build-Dependencies/allwpilib_ni-libraries_57e9fb3.tar.gz",
 )
 
 new_http_archive(
-  name = 'allwpilib_ni_libraries_repo_2017',
-  build_file = 'debian/ni-libraries-2017.BUILD',
-  sha256 = '67c1ad365fb712cc0acb0bf43465b831030523dc6f88daa02626994f644d91eb',
-  url = 'http://frc971.org/Build-Dependencies/allwpilib_ni-libraries_e375b4a.tar.gz',
-  strip_prefix = 'ni-libraries',
+    name = "allwpilib_ni_libraries_repo_2017",
+    build_file = "debian/ni-libraries-2017.BUILD",
+    sha256 = "67c1ad365fb712cc0acb0bf43465b831030523dc6f88daa02626994f644d91eb",
+    strip_prefix = "ni-libraries",
+    url = "http://frc971.org/Build-Dependencies/allwpilib_ni-libraries_e375b4a.tar.gz",
 )
 
 # Downloaded from:
 # https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz
 new_http_archive(
-  name = 'six_repo',
-  build_file = 'debian/six.BUILD',
-  sha256 = '105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a',
-  url = 'http://frc971.org/Build-Dependencies/six-1.10.0.tar.gz',
-  strip_prefix = 'six-1.10.0',
+    name = "six_repo",
+    build_file = "debian/six.BUILD",
+    sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",
+    strip_prefix = "six-1.10.0",
+    url = "http://frc971.org/Build-Dependencies/six-1.10.0.tar.gz",
 )
 
 # For protobuf. Don't use these.
 bind(
-  name = 'six',
-  actual = '@six_repo//:six',
+    name = "six",
+    actual = "@six_repo//:six",
 )
+
 bind(
-  name = 'gtest',
-  actual = '//third_party/googletest:googlemock',
+    name = "gtest",
+    actual = "//third_party/googletest:googlemock",
 )
+
 bind(
-  name = 'gtest_main',
-  actual = '//third_party/googletest:googlemock_main',
+    name = "gtest_main",
+    actual = "//third_party/googletest:googlemock_main",
 )
 
 new_http_archive(
-  name = 'python_import_helpers',
-  build_file = 'third_party/python_import_helpers.BUILD',
-  url = 'http://frc971.org/Build-Dependencies/empty.tar.gz',
-  sha256 = '71939a7d75585a57d2e99a33d39f391764d8f930f9a16acf32e00c5d3f432aa0',
+    name = "python_import_helpers",
+    build_file = "third_party/python_import_helpers.BUILD",
+    sha256 = "71939a7d75585a57d2e99a33d39f391764d8f930f9a16acf32e00c5d3f432aa0",
+    url = "http://frc971.org/Build-Dependencies/empty.tar.gz",
 )
 
 new_local_repository(
-  name = 'libusb',
-  path = '/usr',
-  build_file = 'debian/libusb.BUILD',
+    name = "libusb",
+    build_file = "debian/libusb.BUILD",
+    path = "/usr",
 )
 
 # Created by combining libusb-1.0-0_2%3a1.0.19-1_amd64,
 # libusb-1.0-0-dev_2%3a1.0.19-1, and libudev1_215-17+deb8u7.
 new_http_archive(
-  name = 'libusb_1_0',
-  build_file = 'debian/libusb-1.0.BUILD',
-  url = 'http://frc971.org/Build-Dependencies/libusb-1.0-1.0.19.tar.xz',
-  sha256 = '12acb30faacd10e9aa7f3a5e074701e167ce9bbd45694db37d13d55de5398816',
+    name = "libusb_1_0",
+    build_file = "debian/libusb-1.0.BUILD",
+    sha256 = "12acb30faacd10e9aa7f3a5e074701e167ce9bbd45694db37d13d55de5398816",
+    url = "http://frc971.org/Build-Dependencies/libusb-1.0-1.0.19.tar.xz",
 )
 
 # Recompressed from libusb-1.0.21.7z.
 http_file(
-  name = 'libusb_1_0_windows',
-  url = 'http://frc971.org/Build-Dependencies/libusb-1.0.21-windows.tar.xz',
-  sha256 = 'fc2ba03992f343aabbaf9eb90559c6e00cdc6a2bd914d7cebea85857d5244015',
+    name = "libusb_1_0_windows",
+    sha256 = "fc2ba03992f343aabbaf9eb90559c6e00cdc6a2bd914d7cebea85857d5244015",
+    url = "http://frc971.org/Build-Dependencies/libusb-1.0.21-windows.tar.xz",
 )
 
 # The data tarball of the same-named Debian package.
 new_http_archive(
     name = "f2c",
+    build_file = "debian/f2c.BUILD",
     sha256 = "2c677437f8217a2e2b23e41b33995d0571644fc1bea46de858f8913a5053e3f4",
     url = "http://frc971.org/Build-Dependencies/f2c_20100827-1_amd64.xz.tar.xz",
-    build_file = "debian/f2c.BUILD",
 )
 
 # Downloaded from http://www.netlib.org/clapack/.
 new_http_archive(
-  name = 'clapack',
-  url = "http://frc971.org/Build-Dependencies/clapack-3.2.1.tgz",
-  build_file = 'debian/clapack.BUILD',
-  sha256 = '6dc4c382164beec8aaed8fd2acc36ad24232c406eda6db462bd4c41d5e455fac',
-  strip_prefix = 'CLAPACK-3.2.1/',
+    name = "clapack",
+    build_file = "debian/clapack.BUILD",
+    sha256 = "6dc4c382164beec8aaed8fd2acc36ad24232c406eda6db462bd4c41d5e455fac",
+    strip_prefix = "CLAPACK-3.2.1/",
+    url = "http://frc971.org/Build-Dependencies/clapack-3.2.1.tgz",
+)
+
+new_http_archive(
+    name = "patch",
+    build_file = "debian/patch.BUILD",
+    sha256 = "b5ce139648a2e04f5585948ddad2fdae24dd4ee7976ac5a22d6ae7bd5674631e",
+    url = "http://frc971.org/Build-Dependencies/patch.tar.gz",
 )
diff --git a/debian/BUILD b/debian/BUILD
index 9b5ce9e..e9d3823 100644
--- a/debian/BUILD
+++ b/debian/BUILD
@@ -8,6 +8,10 @@
     "//debian:clang.bzl",
     clang_debs = "files",
 )
+load(
+    ":patch.bzl",
+    patch_debs = "files",
+)
 load("//debian:packages.bzl", "download_packages", "generate_deb_tarball")
 
 py_binary(
@@ -51,6 +55,13 @@
     ],
 )
 
+download_packages(
+    name = "download_patch_deps",
+    packages = [
+        "patch",
+    ],
+)
+
 generate_deb_tarball(
     name = "python",
     files = python_debs,
@@ -60,3 +71,8 @@
     name = "clang_3p6",
     files = clang_debs,
 )
+
+generate_deb_tarball(
+    name = "patch",
+    files = patch_debs,
+)
diff --git a/debian/clapack.BUILD b/debian/clapack.BUILD
index 0acad74..9648bab 100644
--- a/debian/clapack.BUILD
+++ b/debian/clapack.BUILD
@@ -1,15 +1,15 @@
-licenses(['notice'])
+licenses(["notice"])
 
-load('@//tools/build_rules:fortran.bzl', 'f2c_copts')
+load("@//tools/build_rules:fortran.bzl", "f2c_copts")
 
 genrule(
-  name = 'create_sysdep1',
-  outs = ['extra_includes/sysdep1.h'],
-  srcs = ['F2CLIBS/libf2c/sysdep1.h0'],
-  cmd = 'cp $< $@',
+    name = "create_sysdep1",
+    srcs = ["F2CLIBS/libf2c/sysdep1.h0"],
+    outs = ["extra_includes/sysdep1.h"],
+    cmd = "cp $< $@",
 )
 
-_xerbla_patch = '''
+_xerbla_patch = """
 --- xerbla.c   2018-02-19 19:58:03.685420156 -0500
 +++ xerbla.c   2018-02-19 19:59:02.993259128 -0500
 @@ -55,7 +55,7 @@ static integer c__1 = 1;
@@ -21,20 +21,22 @@
 \t\tsrname, *info);
  
  
-'''
+"""
+
 genrule(
-  name = 'patch_xerbla',
-  srcs = ['SRC/xerbla.c'],
-  outs = ['patched_xerbla.c'],
-  cmd = '\n'.join([
-    'cp $< $@',
-    'patch $@ - <<END',
-    _xerbla_patch,
-    'END',
-  ]),
+    name = "patch_xerbla",
+    srcs = ["SRC/xerbla.c"],
+    outs = ["patched_xerbla.c"],
+    cmd = "\n".join([
+        "cp $< $@",
+        "$(location @patch) $@ - <<END",
+        _xerbla_patch,
+        "END",
+    ]),
+    tools = ["@patch"],
 )
 
-_err_patch = '''
+_err_patch = """
 --- err.c  2018-02-19 20:06:40.532033141 -0500
 +++ err.c  2018-02-19 20:10:25.907439219 -0500
 @@ -164,8 +164,10 @@ f__fatal(int n, const char *s)
@@ -50,245 +52,251 @@
  \t\t}
  \telse
  \t\tfprintf(stderr,"apparent state: internal I/O\\n");
-'''
+"""
+
 genrule(
-  name = 'patch_err',
-  srcs = ['F2CLIBS/libf2c/err.c'],
-  outs = ['patched_err.c'],
-  cmd = '\n'.join([
-    'cp $< $@',
-    'patch $@ - <<END',
-    _err_patch,
-    'END',
-  ]),
+    name = "patch_err",
+    srcs = ["F2CLIBS/libf2c/err.c"],
+    outs = ["patched_err.c"],
+    cmd = "\n".join([
+        "cp $< $@",
+        "$(location @patch) $@ - <<END",
+        _err_patch,
+        "END",
+    ]),
+    tools = ["@patch"],
 )
 
 cc_library(
-  name = 'clapack',
-  visibility = ['//visibility:public'],
-  srcs = glob(include = [
-    'SRC/*.c',
-    'BLAS/SRC/*.c',
-  ], exclude = [
-    # These are duplicated in SRC (with the ones in SRC a bit more cleaned up).
-    'BLAS/SRC/xerbla.c',
-    'BLAS/SRC/xerbla_array.c',
+    name = "clapack",
+    srcs = glob(
+        include = [
+            "SRC/*.c",
+            "BLAS/SRC/*.c",
+        ],
+        exclude = [
+            # These are duplicated in SRC (with the ones in SRC a bit more cleaned up).
+            "BLAS/SRC/xerbla.c",
+            "BLAS/SRC/xerbla_array.c",
 
-    # We need to use a patched version of this.
-    'SRC/xerbla.c',
+            # We need to use a patched version of this.
+            "SRC/xerbla.c",
 
-    # Files requiring XBLAS (extended precision), which we don't have.
-    'SRC/sgesvxx.c',
-    'SRC/sgerfsx.c',
-    'SRC/sla_gerfsx_extended.c',
-    'SRC/sla_geamv.c',
-    'SRC/sla_gercond.c',
-    'SRC/sla_gerpvgrw.c',
-    'SRC/ssysvxx.c',
-    'SRC/ssyrfsx.c',
-    'SRC/sla_syrfsx_extended.c',
-    'SRC/sla_syamv.c',
-    'SRC/sla_syrcond.c',
-    'SRC/sla_syrpvgrw.c',
-    'SRC/sposvxx.c',
-    'SRC/sporfsx.c',
-    'SRC/sla_porfsx_extended.c',
-    'SRC/sla_porcond.c',
-    'SRC/sla_porpvgrw.c',
-    'SRC/sgbsvxx.c',
-    'SRC/sgbrfsx.c',
-    'SRC/sla_gbrfsx_extended.c',
-    'SRC/sla_gbamv.c',
-    'SRC/sla_gbrcond.c',
-    'SRC/sla_gbrpvgrw.c',
-    'SRC/sla_lin_berr.c',
-    'SRC/slarscl2.c',
-    'SRC/slascl2.c',
-    'SRC/sla_wwaddw.c',
-    'SRC/cgesvxx.c',
-    'SRC/cgerfsx.c',
-    'SRC/cla_gerfsx_extended.c',
-    'SRC/cla_geamv.c',
-    'SRC/cla_gercond_c.c',
-    'SRC/cla_gercond_x.c',
-    'SRC/cla_gerpvgrw.c',
-    'SRC/csysvxx.c',
-    'SRC/csyrfsx.c',
-    'SRC/cla_syrfsx_extended.c',
-    'SRC/cla_syamv.c',
-    'SRC/cla_syrcond_c.c',
-    'SRC/cla_syrcond_x.c',
-    'SRC/cla_syrpvgrw.c',
-    'SRC/cposvxx.c',
-    'SRC/cporfsx.c',
-    'SRC/cla_porfsx_extended.c',
-    'SRC/cla_porcond_c.c',
-    'SRC/cla_porcond_x.c',
-    'SRC/cla_porpvgrw.c',
-    'SRC/cgbsvxx.c',
-    'SRC/cgbrfsx.c',
-    'SRC/cla_gbrfsx_extended.c',
-    'SRC/cla_gbamv.c',
-    'SRC/cla_gbrcond_c.c',
-    'SRC/cla_gbrcond_x.c',
-    'SRC/cla_gbrpvgrw.c',
-    'SRC/chesvxx.c',
-    'SRC/cherfsx.c',
-    'SRC/cla_herfsx_extended.c',
-    'SRC/cla_heamv.c',
-    'SRC/cla_hercond_c.c',
-    'SRC/cla_hercond_x.c',
-    'SRC/cla_herpvgrw.c',
-    'SRC/cla_lin_berr.c',
-    'SRC/clarscl2.c',
-    'SRC/clascl2.c',
-    'SRC/cla_wwaddw.c',
-    'SRC/dgesvxx.c',
-    'SRC/dgerfsx.c',
-    'SRC/dla_gerfsx_extended.c',
-    'SRC/dla_geamv.c',
-    'SRC/dla_gercond.c',
-    'SRC/dla_gerpvgrw.c',
-    'SRC/dsysvxx.c',
-    'SRC/dsyrfsx.c',
-    'SRC/dla_syrfsx_extended.c',
-    'SRC/dla_syamv.c',
-    'SRC/dla_syrcond.c',
-    'SRC/dla_syrpvgrw.c',
-    'SRC/dposvxx.c',
-    'SRC/dporfsx.c',
-    'SRC/dla_porfsx_extended.c',
-    'SRC/dla_porcond.c',
-    'SRC/dla_porpvgrw.c',
-    'SRC/dgbsvxx.c',
-    'SRC/dgbrfsx.c',
-    'SRC/dla_gbrfsx_extended.c',
-    'SRC/dla_gbamv.c',
-    'SRC/dla_gbrcond.c',
-    'SRC/dla_gbrpvgrw.c',
-    'SRC/dla_lin_berr.c',
-    'SRC/dlarscl2.c',
-    'SRC/dlascl2.c',
-    'SRC/dla_wwaddw.c',
-    'SRC/zgesvxx.c',
-    'SRC/zgerfsx.c',
-    'SRC/zla_gerfsx_extended.c',
-    'SRC/zla_geamv.c',
-    'SRC/zla_gercond_c.c',
-    'SRC/zla_gercond_x.c',
-    'SRC/zla_gerpvgrw.c',
-    'SRC/zsysvxx.c',
-    'SRC/zsyrfsx.c',
-    'SRC/zla_syrfsx_extended.c',
-    'SRC/zla_syamv.c',
-    'SRC/zla_syrcond_c.c',
-    'SRC/zla_syrcond_x.c',
-    'SRC/zla_syrpvgrw.c',
-    'SRC/zposvxx.c',
-    'SRC/zporfsx.c',
-    'SRC/zla_porfsx_extended.c',
-    'SRC/zla_porcond_c.c',
-    'SRC/zla_porcond_x.c',
-    'SRC/zla_porpvgrw.c',
-    'SRC/zgbsvxx.c',
-    'SRC/zgbrfsx.c',
-    'SRC/zla_gbrfsx_extended.c',
-    'SRC/zla_gbamv.c',
-    'SRC/zla_gbrcond_c.c',
-    'SRC/zla_gbrcond_x.c',
-    'SRC/zla_gbrpvgrw.c',
-    'SRC/zhesvxx.c',
-    'SRC/zherfsx.c',
-    'SRC/zla_herfsx_extended.c',
-    'SRC/zla_heamv.c',
-    'SRC/zla_hercond_c.c',
-    'SRC/zla_hercond_x.c',
-    'SRC/zla_herpvgrw.c',
-    'SRC/zla_lin_berr.c',
-    'SRC/zlarscl2.c',
-    'SRC/zlascl2.c',
-    'SRC/zla_wwaddw.c',
-  ]) + [
-    'INSTALL/dlamch.c',
-    'INSTALL/slamch.c',
+            # Files requiring XBLAS (extended precision), which we don't have.
+            "SRC/sgesvxx.c",
+            "SRC/sgerfsx.c",
+            "SRC/sla_gerfsx_extended.c",
+            "SRC/sla_geamv.c",
+            "SRC/sla_gercond.c",
+            "SRC/sla_gerpvgrw.c",
+            "SRC/ssysvxx.c",
+            "SRC/ssyrfsx.c",
+            "SRC/sla_syrfsx_extended.c",
+            "SRC/sla_syamv.c",
+            "SRC/sla_syrcond.c",
+            "SRC/sla_syrpvgrw.c",
+            "SRC/sposvxx.c",
+            "SRC/sporfsx.c",
+            "SRC/sla_porfsx_extended.c",
+            "SRC/sla_porcond.c",
+            "SRC/sla_porpvgrw.c",
+            "SRC/sgbsvxx.c",
+            "SRC/sgbrfsx.c",
+            "SRC/sla_gbrfsx_extended.c",
+            "SRC/sla_gbamv.c",
+            "SRC/sla_gbrcond.c",
+            "SRC/sla_gbrpvgrw.c",
+            "SRC/sla_lin_berr.c",
+            "SRC/slarscl2.c",
+            "SRC/slascl2.c",
+            "SRC/sla_wwaddw.c",
+            "SRC/cgesvxx.c",
+            "SRC/cgerfsx.c",
+            "SRC/cla_gerfsx_extended.c",
+            "SRC/cla_geamv.c",
+            "SRC/cla_gercond_c.c",
+            "SRC/cla_gercond_x.c",
+            "SRC/cla_gerpvgrw.c",
+            "SRC/csysvxx.c",
+            "SRC/csyrfsx.c",
+            "SRC/cla_syrfsx_extended.c",
+            "SRC/cla_syamv.c",
+            "SRC/cla_syrcond_c.c",
+            "SRC/cla_syrcond_x.c",
+            "SRC/cla_syrpvgrw.c",
+            "SRC/cposvxx.c",
+            "SRC/cporfsx.c",
+            "SRC/cla_porfsx_extended.c",
+            "SRC/cla_porcond_c.c",
+            "SRC/cla_porcond_x.c",
+            "SRC/cla_porpvgrw.c",
+            "SRC/cgbsvxx.c",
+            "SRC/cgbrfsx.c",
+            "SRC/cla_gbrfsx_extended.c",
+            "SRC/cla_gbamv.c",
+            "SRC/cla_gbrcond_c.c",
+            "SRC/cla_gbrcond_x.c",
+            "SRC/cla_gbrpvgrw.c",
+            "SRC/chesvxx.c",
+            "SRC/cherfsx.c",
+            "SRC/cla_herfsx_extended.c",
+            "SRC/cla_heamv.c",
+            "SRC/cla_hercond_c.c",
+            "SRC/cla_hercond_x.c",
+            "SRC/cla_herpvgrw.c",
+            "SRC/cla_lin_berr.c",
+            "SRC/clarscl2.c",
+            "SRC/clascl2.c",
+            "SRC/cla_wwaddw.c",
+            "SRC/dgesvxx.c",
+            "SRC/dgerfsx.c",
+            "SRC/dla_gerfsx_extended.c",
+            "SRC/dla_geamv.c",
+            "SRC/dla_gercond.c",
+            "SRC/dla_gerpvgrw.c",
+            "SRC/dsysvxx.c",
+            "SRC/dsyrfsx.c",
+            "SRC/dla_syrfsx_extended.c",
+            "SRC/dla_syamv.c",
+            "SRC/dla_syrcond.c",
+            "SRC/dla_syrpvgrw.c",
+            "SRC/dposvxx.c",
+            "SRC/dporfsx.c",
+            "SRC/dla_porfsx_extended.c",
+            "SRC/dla_porcond.c",
+            "SRC/dla_porpvgrw.c",
+            "SRC/dgbsvxx.c",
+            "SRC/dgbrfsx.c",
+            "SRC/dla_gbrfsx_extended.c",
+            "SRC/dla_gbamv.c",
+            "SRC/dla_gbrcond.c",
+            "SRC/dla_gbrpvgrw.c",
+            "SRC/dla_lin_berr.c",
+            "SRC/dlarscl2.c",
+            "SRC/dlascl2.c",
+            "SRC/dla_wwaddw.c",
+            "SRC/zgesvxx.c",
+            "SRC/zgerfsx.c",
+            "SRC/zla_gerfsx_extended.c",
+            "SRC/zla_geamv.c",
+            "SRC/zla_gercond_c.c",
+            "SRC/zla_gercond_x.c",
+            "SRC/zla_gerpvgrw.c",
+            "SRC/zsysvxx.c",
+            "SRC/zsyrfsx.c",
+            "SRC/zla_syrfsx_extended.c",
+            "SRC/zla_syamv.c",
+            "SRC/zla_syrcond_c.c",
+            "SRC/zla_syrcond_x.c",
+            "SRC/zla_syrpvgrw.c",
+            "SRC/zposvxx.c",
+            "SRC/zporfsx.c",
+            "SRC/zla_porfsx_extended.c",
+            "SRC/zla_porcond_c.c",
+            "SRC/zla_porcond_x.c",
+            "SRC/zla_porpvgrw.c",
+            "SRC/zgbsvxx.c",
+            "SRC/zgbrfsx.c",
+            "SRC/zla_gbrfsx_extended.c",
+            "SRC/zla_gbamv.c",
+            "SRC/zla_gbrcond_c.c",
+            "SRC/zla_gbrcond_x.c",
+            "SRC/zla_gbrpvgrw.c",
+            "SRC/zhesvxx.c",
+            "SRC/zherfsx.c",
+            "SRC/zla_herfsx_extended.c",
+            "SRC/zla_heamv.c",
+            "SRC/zla_hercond_c.c",
+            "SRC/zla_hercond_x.c",
+            "SRC/zla_herpvgrw.c",
+            "SRC/zla_lin_berr.c",
+            "SRC/zlarscl2.c",
+            "SRC/zlascl2.c",
+            "SRC/zla_wwaddw.c",
+        ],
+    ) + [
+        "INSTALL/dlamch.c",
+        "INSTALL/slamch.c",
+        "patched_xerbla.c",
+        "patched_err.c",
+        "F2CLIBS/libf2c/s_cat.c",
+        "F2CLIBS/libf2c/d_lg10.c",
+        "F2CLIBS/libf2c/d_sign.c",
+        "F2CLIBS/libf2c/i_dnnt.c",
+        "F2CLIBS/libf2c/pow_di.c",
+        "F2CLIBS/libf2c/s_copy.c",
+        "F2CLIBS/libf2c/s_cmp.c",
+        "F2CLIBS/libf2c/i_nint.c",
+        "F2CLIBS/libf2c/f77_aloc.c",
+        "F2CLIBS/libf2c/exit_.c",
+        "F2CLIBS/libf2c/r_cnjg.c",
+        "F2CLIBS/libf2c/c_abs.c",
+        "F2CLIBS/libf2c/r_imag.c",
+        "F2CLIBS/libf2c/c_div.c",
+        "F2CLIBS/libf2c/c_exp.c",
+        "F2CLIBS/libf2c/d_imag.c",
+        "F2CLIBS/libf2c/r_sign.c",
+        "F2CLIBS/libf2c/d_cnjg.c",
+        "F2CLIBS/libf2c/z_abs.c",
+        "F2CLIBS/libf2c/z_div.c",
+        "F2CLIBS/libf2c/z_exp.c",
+        "F2CLIBS/libf2c/z_sqrt.c",
+        "F2CLIBS/libf2c/pow_dd.c",
+        "F2CLIBS/libf2c/pow_ri.c",
+        "F2CLIBS/libf2c/pow_ci.c",
+        "F2CLIBS/libf2c/pow_ii.c",
+        "F2CLIBS/libf2c/pow_zi.c",
+        "F2CLIBS/libf2c/c_sqrt.c",
+        "F2CLIBS/libf2c/r_lg10.c",
+        "F2CLIBS/libf2c/i_len.c",
+        "F2CLIBS/libf2c/cabs.c",
+        "F2CLIBS/libf2c/sig_die.c",
+        "F2CLIBS/libf2c/close.c",
+        "F2CLIBS/libf2c/open.c",
+        "F2CLIBS/libf2c/endfile.c",
+        "F2CLIBS/libf2c/util.c",
+        "F2CLIBS/libf2c/iio.c",
+        "F2CLIBS/libf2c/fmt.c",
+        "F2CLIBS/libf2c/rdfmt.c",
+        "F2CLIBS/libf2c/wrtfmt.c",
+        #'F2CLIBS/libf2c/ctype.c',
+        "F2CLIBS/libf2c/wref.c",
+        "F2CLIBS/libf2c/fmtlib.c",
+        "F2CLIBS/libf2c/lread.c",
+        "F2CLIBS/libf2c/rsfe.c",
+        "F2CLIBS/libf2c/sfe.c",
+        "F2CLIBS/libf2c/dolio.c",
+        "F2CLIBS/libf2c/wsfe.c",
+        "extra_includes/sysdep1.h",
+    ],
+    hdrs = glob(
+        [
+            "INCLUDE/*.h",
+            "F2CLIBS/libf2c/*.h",
+        ],
+        exclude = ["F2CLIBS/libf2c/ctype.h"],
+    ),
+    copts = f2c_copts + [
+        "-Wno-sign-compare",
+        "-Wno-cast-qual",
+        "-Wno-cast-align",
+        "-Wno-self-assign",
 
-    'patched_xerbla.c',
-    'patched_err.c',
+        # Some files don't #include system headers when they should. sysdep1.h
+        # messes with feature test macros, so it always has to come first.
+        "-include",
+        "sysdep1.h",
+        "-include",
+        "stdio.h",
 
-    'F2CLIBS/libf2c/s_cat.c',
-    'F2CLIBS/libf2c/d_lg10.c',
-    'F2CLIBS/libf2c/d_sign.c',
-    'F2CLIBS/libf2c/i_dnnt.c',
-    'F2CLIBS/libf2c/pow_di.c',
-    'F2CLIBS/libf2c/s_copy.c',
-    'F2CLIBS/libf2c/s_cmp.c',
-    'F2CLIBS/libf2c/i_nint.c',
-    'F2CLIBS/libf2c/f77_aloc.c',
-    'F2CLIBS/libf2c/exit_.c',
-    'F2CLIBS/libf2c/r_cnjg.c',
-    'F2CLIBS/libf2c/c_abs.c',
-    'F2CLIBS/libf2c/r_imag.c',
-    'F2CLIBS/libf2c/c_div.c',
-    'F2CLIBS/libf2c/c_exp.c',
-    'F2CLIBS/libf2c/d_imag.c',
-    'F2CLIBS/libf2c/r_sign.c',
-    'F2CLIBS/libf2c/d_cnjg.c',
-    'F2CLIBS/libf2c/z_abs.c',
-    'F2CLIBS/libf2c/z_div.c',
-    'F2CLIBS/libf2c/z_exp.c',
-    'F2CLIBS/libf2c/z_sqrt.c',
-    'F2CLIBS/libf2c/pow_dd.c',
-    'F2CLIBS/libf2c/pow_ri.c',
-    'F2CLIBS/libf2c/pow_ci.c',
-    'F2CLIBS/libf2c/pow_ii.c',
-    'F2CLIBS/libf2c/pow_zi.c',
-    'F2CLIBS/libf2c/c_sqrt.c',
-    'F2CLIBS/libf2c/r_lg10.c',
-    'F2CLIBS/libf2c/i_len.c',
-    'F2CLIBS/libf2c/cabs.c',
-    'F2CLIBS/libf2c/sig_die.c',
-    'F2CLIBS/libf2c/close.c',
-    'F2CLIBS/libf2c/open.c',
-    'F2CLIBS/libf2c/endfile.c',
-    'F2CLIBS/libf2c/util.c',
-    'F2CLIBS/libf2c/iio.c',
-    'F2CLIBS/libf2c/fmt.c',
-    'F2CLIBS/libf2c/rdfmt.c',
-    'F2CLIBS/libf2c/wrtfmt.c',
-    #'F2CLIBS/libf2c/ctype.c',
-    'F2CLIBS/libf2c/wref.c',
-    'F2CLIBS/libf2c/fmtlib.c',
-    'F2CLIBS/libf2c/lread.c',
-    'F2CLIBS/libf2c/rsfe.c',
-    'F2CLIBS/libf2c/sfe.c',
-    'F2CLIBS/libf2c/dolio.c',
-    'F2CLIBS/libf2c/wsfe.c',
-
-    'extra_includes/sysdep1.h',
-  ],
-  hdrs = glob([
-    'INCLUDE/*.h',
-    'F2CLIBS/libf2c/*.h',
-  ],
-  exclude=['F2CLIBS/libf2c/ctype.h']),
-  includes = [
-    'INCLUDE',
-    'F2CLIBS/libf2c',
-    'extra_includes',
-  ],
-  copts = f2c_copts + [
-    '-Wno-sign-compare',
-    '-Wno-cast-qual',
-    '-Wno-cast-align',
-    '-Wno-self-assign',
-
-    # Some files don't #include system headers when they should. sysdep1.h
-    # messes with feature test macros, so it always has to come first.
-    '-include', 'sysdep1.h',
-    '-include', 'stdio.h',
-
-    # Don't mangle the names of all the BLAS symbols, because slicot needs to
-    # call them directly.
-    '-DNO_BLAS_WRAP',
-  ],
+        # Don't mangle the names of all the BLAS symbols, because slicot needs to
+        # call them directly.
+        "-DNO_BLAS_WRAP",
+    ],
+    includes = [
+        "F2CLIBS/libf2c",
+        "INCLUDE",
+        "extra_includes",
+    ],
+    visibility = ["//visibility:public"],
 )
diff --git a/debian/patch.BUILD b/debian/patch.BUILD
new file mode 100644
index 0000000..93f8e7f
--- /dev/null
+++ b/debian/patch.BUILD
@@ -0,0 +1,5 @@
+filegroup(
+    name = "patch",
+    srcs = ["usr/bin/patch"],
+    visibility = ["//visibility:public"],
+)
diff --git a/debian/patch.bzl b/debian/patch.bzl
new file mode 100644
index 0000000..fbc014e
--- /dev/null
+++ b/debian/patch.bzl
@@ -0,0 +1,3 @@
+files = {
+    "patch_2.7.5-1+deb8u1_amd64.deb": "5272a26273fd799ec1ec74db0e01df5883abbdf8b7e343ad28227295f660c35d",
+}