Index: /trunk/src/kmk/read.c
===================================================================
--- /trunk/src/kmk/read.c	(revision 1816)
+++ /trunk/src/kmk/read.c	(revision 1817)
@@ -139,5 +139,9 @@
 static void do_define (char *name, unsigned int namelen,
                        enum variable_origin origin, struct ebuffer *ebuf);
+#ifndef CONFIG_WITH_VALUE_LENGTH
 static int conditional_line (char *line, int len, const struct floc *flocp);
+#else
+static int conditional_line (char *line, char *eol, int len, const struct floc *flocp);
+#endif
 #ifndef CONFIG_WITH_INCLUDEDEP
 static void record_files (struct nameseq *filenames, const char *pattern,
@@ -189,5 +193,9 @@
       warn_undefined_variables_flag = 0;
 
+#ifndef CONFIG_WITH_VALUE_LENGTH
       value = allocated_variable_expand ("$(MAKEFILES)");
+#else
+      value = allocated_variable_expand_2 (STRING_SIZE_TUPLE("$(MAKEFILES)"), NULL);
+#endif
 
       warn_undefined_variables_flag = save;
@@ -686,5 +694,9 @@
       if (!in_ignored_define)
 	{
+#ifndef CONFIG_WITH_VALUE_LENGTH
  	  int i = conditional_line (p, wlen, fstart);
+#else
+ 	  int i = conditional_line (p, eol, wlen, fstart);
+#endif
           if (i != -2)
             {
@@ -831,5 +843,9 @@
                   /* Expand the line so we can use indirect and constructed
                      variable names in an export command.  */
-                  cp = ap = allocated_variable_expand (p2); ///// FIXME
+#ifndef CONFIG_WITH_VALUE_LENGTH
+                  cp = ap = allocated_variable_expand (p2);
+#else
+                  cp = ap = allocated_variable_expand_2 (p2, eol - p2, NULL);
+#endif
 
                   for (p = find_next_token (&cp, &l); p != 0;
@@ -861,5 +877,9 @@
               /* Expand the line so we can use indirect and constructed
                  variable names in an unexport command.  */
-              cp = ap = allocated_variable_expand (p2); ///// FIXME
+#ifndef CONFIG_WITH_VALUE_LENGTH
+              cp = ap = allocated_variable_expand (p2);
+#else
+              cp = ap = allocated_variable_expand_2 (p2, eol - p2, NULL);
+#endif
 
               for (p = find_next_token (&cp, &l); p != 0;
@@ -920,8 +940,9 @@
           if (memchr (name, '$', eol - name))
             {
-              free_me = name = allocated_variable_expand (name);
+              unsigned int name_len;
+              free_me = name = allocated_variable_expand_2 (name, eol - name, &name_len);
+              eol = name + name_len;
               while (isspace ((unsigned char)*name))
                 ++name;
-              eol = strchr (name, '\0');
             }
 
@@ -949,5 +970,9 @@
 	  int noerror = (p[0] != 'i');
 
-	  p = allocated_variable_expand (p2); //// FIXME
+#ifndef CONFIG_WITH_VALUE_LENGTH
+	  p = allocated_variable_expand (p2);
+#else
+	  p = allocated_variable_expand_2 (p2, eol - p2, NULL);
+#endif
 
           /* If no filenames, it's a no-op.  */
@@ -1618,5 +1643,9 @@
 
 static int
+#ifndef CONFIG_WITH_VALUE_LENGTH
 conditional_line (char *line, int len, const struct floc *flocp)
+#else
+conditional_line (char *line, char *eol, int len, const struct floc *flocp)
+#endif
 {
   char *cmdname;
@@ -1632,4 +1661,7 @@
   unsigned int i;
   unsigned int o;
+#ifdef CONFIG_WITH_VALUE_LENGTH
+  assert (strchr (line, '\0') == eol);
+#endif
 
   /* Compare a word, both length and contents. */
@@ -1717,5 +1749,9 @@
       /* If it's 'else' or 'endif' or an illegal conditional, fail.  */
       if (word1eq("else") || word1eq("endif")
+#ifndef CONFIG_WITH_VALUE_LENGTH
           || conditional_line (line, len, flocp) < 0)
+#else
+          || conditional_line (line, eol, len, flocp) < 0)
+#endif
 	EXTRANEOUS ();
       else
@@ -1770,5 +1806,9 @@
       /* Expand the thing we're looking up, so we can use indirect and
          constructed variable names.  */
+#ifndef CONFIG_WITH_VALUE_LENGTH
       var = allocated_variable_expand (line);
+#else
+      var = allocated_variable_expand_2 (line, eol - line, NULL);
+#endif
 
       /* Make sure there's only one variable name to test.  */
@@ -1806,4 +1846,7 @@
       unsigned int l;
       char termin = *line == '(' ? ',' : *line;
+#ifdef CONFIG_WITH_VALUE_LENGTH
+      char *buf_pos;
+#endif
 
       if (termin != ',' && termin != '"' && termin != '\'')
@@ -1837,8 +1880,17 @@
 	    --p;
 	  *p = '\0';
+#ifdef CONFIG_WITH_VALUE_LENGTH
+          l = p - s1;
+#endif
 	}
       else
-	*line++ = '\0';
-
+        {
+#ifdef CONFIG_WITH_VALUE_LENGTH
+          l = line - s1;
+#endif
+	  *line++ = '\0';
+        }
+
+#ifndef CONFIG_WITH_VALUE_LENGTH
       s2 = variable_expand (s1);
       /* We must allocate a new copy of the expanded string because
@@ -1847,4 +1899,8 @@
       s1 = alloca (l + 1);
       memcpy (s1, s2, l + 1);
+#else
+      s1 = variable_expand_string_2 (NULL, s1, l, &buf_pos);
+      ++buf_pos;
+#endif
 
       if (termin != ',')
@@ -1886,9 +1942,19 @@
 
       *line = '\0';
+#ifdef CONFIG_WITH_VALUE_LENGTH
+      l = line - s2;
+#endif
       line = next_token (++line);
       if (*line != '\0')
 	EXTRANEOUS ();
 
+#ifndef CONFIG_WITH_VALUE_LENGTH
       s2 = variable_expand (s2);
+#else
+      if ((size_t)buf_pos & 7)
+        buf_pos = variable_buffer_output (buf_pos, "\0\0\0\0\0\0\0\0",
+                                          8 - (size_t)buf_pos & 7);
+      s2 = variable_expand_string (buf_pos, s2, l);
+#endif
 #ifdef CONFIG_WITH_SET_CONDITIONALS
       if (cmdtype == c_if1of || cmdtype == c_ifn1of)
@@ -3398,5 +3464,9 @@
 	warn_undefined_variables_flag = 0;
 
+#ifndef CONFIG_WITH_VALUE_LENGTH
 	home_dir = allocated_variable_expand ("$(HOME)");
+#else
+	home_dir = allocated_variable_expand_2 (STRING_SIZE_TUPLE("$(HOME)"), NULL);
+#endif
 
 	warn_undefined_variables_flag = save;
