Propagate ifdefs correctly to improve build efficiency.

With -DRESTRICT_SCHUR_SPECIALIZATIONS, now the various
specializations are empty, decreasing build time and
reducing the size of the static library.

Change-Id: I8ec431279741a9a83516a4167c54a364c4608143
diff --git a/internal/ceres/generate_eliminator_specialization.py b/internal/ceres/generate_eliminator_specialization.py
index 6095351..b14b145 100644
--- a/internal/ceres/generate_eliminator_specialization.py
+++ b/internal/ceres/generate_eliminator_specialization.py
@@ -65,8 +65,7 @@
                    (4, 4, 4),
                    (4, 4, "Eigen::Dynamic"),
                    ("Eigen::Dynamic", "Eigen::Dynamic", "Eigen::Dynamic")]
-
-SPECIALIZATION_FILE = """// Ceres Solver - A fast non-linear least squares minimizer
+HEADER = """// Ceres Solver - A fast non-linear least squares minimizer
 // Copyright 2010, 2011, 2012, 2013 Google Inc. All rights reserved.
 // http://code.google.com/p/ceres-solver/
 //
@@ -107,6 +106,24 @@
 //
 // This file is generated using generate_eliminator_specializations.py.
 // Editing it manually is not recommended.
+"""
+
+DYNAMIC_FILE = """
+
+#include "ceres/schur_eliminator_impl.h"
+#include "ceres/internal/eigen.h"
+
+namespace ceres {
+namespace internal {
+
+template class SchurEliminator<%s, %s, %s>;
+
+}  // namespace internal
+}  // namespace ceres
+"""
+
+SPECIALIZATION_FILE = """
+#ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION
 
 #include "ceres/schur_eliminator_impl.h"
 #include "ceres/internal/eigen.h"
@@ -119,21 +136,10 @@
 }  // namespace internal
 }  // namespace ceres
 
+#endif  // CERES_RESTRICT_SCHUR_SPECIALIZATION
 """
 
-FACTORY_FILE_HEADER = """// Copyright 2011 Google Inc. All Rights Reserved.
-// Author: sameeragarwal@google.com (Sameer Agarwal)
-//
-// ========================================
-// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
-// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
-// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
-// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
-//=========================================
-//
-// This file is generated using generate_template_specializations.py.
-// Editing it manually is not recommended.
-
+FACTORY_FILE_HEADER = """
 #include "ceres/linear_solver.h"
 #include "ceres/schur_eliminator.h"
 #include "ceres/internal/eigen.h"
@@ -184,6 +190,7 @@
   Generate specialization code and the conditionals to instantiate it.
   """
   f = open("schur_eliminator.cc", "w")
+  f.write(HEADER)
   f.write(FACTORY_FILE_HEADER)
 
   for row_block_size, e_block_size, f_block_size in SPECIALIZATIONS:
@@ -192,9 +199,15 @@
                                     e_block_size,
                                     f_block_size) + ".cc"
     fptr = open(output, "w")
-    fptr.write(SPECIALIZATION_FILE % (row_block_size,
-                                      e_block_size,
-                                      f_block_size))
+    fptr.write(HEADER)
+
+    template = SPECIALIZATION_FILE
+    if (row_block_size == "Eigen::Dynamic" and
+        e_block_size == "Eigen::Dynamic" and
+        f_block_size == "Eigen::Dynamic") :
+      template = DYNAMIC_FILE
+
+    fptr.write(template % (row_block_size, e_block_size, f_block_size));
     fptr.close()
 
     f.write(FACTORY_CONDITIONAL % (row_block_size,