diff -Nurd -x'*~' recode-3.6.orig/Makefile.am recode-3.6/Makefile.am
--- recode-3.6.orig/Makefile.am	2000-12-06 15:03:24.000000000 -0500
+++ recode-3.6/Makefile.am	2011-09-14 03:41:59.000000000 -0400
@@ -23,7 +23,7 @@
 
 BABYL = ../rmail/* ../*/rmail/* ../*/*/RMAIL ../*/*/rmail/*
 EXTRA_DIST = COPYING-LIB PATCHES-AC rebox.el recode.spec aclocal.sh
-SUBDIRS = m4 doc lib libiconv i18n src tests contrib
+SUBDIRS = m4 doc lib i18n src tests contrib
 
 POTFILES = src/main.c src/names.c src/outer.c src/recode.c \
 src/request.c src/strip-data.c src/task.c src/testdump.c
diff -Nurd -x'*~' recode-3.6.orig/configure.in recode-3.6/configure.in
--- recode-3.6.orig/configure.in	2001-01-03 10:50:54.000000000 -0500
+++ recode-3.6/configure.in	2011-09-14 03:41:59.000000000 -0400
@@ -7,6 +7,7 @@
 AM_CONFIG_HEADER(config.h)
 AM_INIT_AUTOMAKE(recode, 3.6)
 AT_CONFIG(../src)
+AC_CONFIG_MACRO_DIR([m4])
 ALL_LINGUAS="da de el es fr gl it nl pl pt sl sv"
 
 AC_PROG_CC
@@ -18,7 +19,7 @@
 AM_C_PROTOTYPES
 AC_C_CONST
 AC_C_INLINE
-ad_AC_PROG_FLEX
+AC_PROG_LEX
 
 AC_HEADER_STDC
 AC_CHECK_HEADERS(limits.h locale.h memory.h stdbool.h stddef.h stdlib.h string.h unistd.h utime.h)
diff -Nurd -x'*~' recode-3.6.orig/lib/Makefile.am recode-3.6/lib/Makefile.am
--- recode-3.6.orig/lib/Makefile.am	2000-10-24 15:48:40.000000000 -0400
+++ recode-3.6/lib/Makefile.am	2011-09-14 03:41:59.000000000 -0400
@@ -20,8 +20,8 @@
 AUTOMAKE_OPTIONS = gnits
 
 noinst_LIBRARIES = libreco.a
-noinst_HEADERS = error.h getopt.h gettext.h pathmax.h xstring.h
-libreco_a_SOURCES = error.c getopt.c getopt1.c xstrdup.c
+noinst_HEADERS = error.h gettext.h pathmax.h xstring.h
+libreco_a_SOURCES = error.c xstrdup.c
 
 EXTRA_DIST = alloca.c gettext.c malloc.c realloc.c strtol.c strtoul.c
 
diff -Nurd -x'*~' recode-3.6.orig/lib/error.c recode-3.6/lib/error.c
--- recode-3.6.orig/lib/error.c	2000-08-02 21:21:13.000000000 -0400
+++ recode-3.6/lib/error.c	2011-09-14 03:41:59.000000000 -0400
@@ -80,7 +80,7 @@
 
 /* The calling program should define program_name and set it to the
    name of the executing program.  */
-extern char *program_name;
+# define program_name getprogname()
 
 # ifdef HAVE_STRERROR_R
 #  define __strerror_r strerror_r
diff -Nurd -x'*~' recode-3.6.orig/src/Makefile.am recode-3.6/src/Makefile.am
--- recode-3.6.orig/src/Makefile.am	2000-12-06 11:36:12.000000000 -0500
+++ recode-3.6/src/Makefile.am	2011-09-14 03:41:59.000000000 -0400
@@ -43,14 +43,15 @@
 L_SURFACES =
 
 recode_SOURCES = main.c freeze.c mixed.c
-recode_LDADD = librecode.la ../lib/libreco.a
+recode_LDADD = librecode.la
 
 librecode_la_SOURCES = argmatch.c charname.c combine.c fr-charname.c \
-hash.c iconv.c libiconv.c localcharset.c merged.c names.c outer.c quotearg.c \
+hash.c libiconv.c merged.c names.c outer.c quotearg.c \
 recode.c request.c strip-pool.c task.c xmalloc.c $(C_STEPS)
-librecode_la_LDFLAGS = -version-info 0:0:0
+librecode_la_LDFLAGS = -version-info 0:0:0 -no-undefined
+librecode_la_LIBADD = ../lib/libreco.a
 
-INCLUDES = -I.. -I$(srcdir) -I$(top_srcdir)/lib -I$(top_srcdir)/libiconv
+INCLUDES = -I.. -I$(srcdir) -I$(top_srcdir)/lib
 DEFS = -DLIBDIR=\"$(libdir)\" @DEFS@
 
 ETAGS_ARGS = $(L_STEPS)
diff -Nurd -x'*~' recode-3.6.orig/src/argmatch.c recode-3.6/src/argmatch.c
--- recode-3.6.orig/src/argmatch.c	2000-08-02 21:21:15.000000000 -0400
+++ recode-3.6/src/argmatch.c	2011-09-14 03:41:59.000000000 -0400
@@ -20,6 +20,7 @@
 
 #include "argmatch.h"
 
+#include <stdlib.h>
 #include <stdio.h>
 #ifdef STDC_HEADERS
 # include <string.h>
diff -Nurd -x'*~' recode-3.6.orig/src/hash.h recode-3.6/src/hash.h
--- recode-3.6.orig/src/hash.h	2000-08-02 21:21:15.000000000 -0400
+++ recode-3.6/src/hash.h	2011-09-14 03:41:59.000000000 -0400
@@ -21,6 +21,11 @@
 /* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
    obstacks instead of malloc, and recompile `hash.c' with same setting.  */
 
+#define hash_lookup recode_hash_lookup
+#define hash_delete recode_hash_delete
+#define hash_free   recode_hash_free
+#define hash_insert recode_hash_insert
+
 #ifndef PARAMS
 # if PROTOTYPES || __STDC__
 #  define PARAMS(Args) Args
diff -Nurd -x'*~' recode-3.6.orig/src/libiconv.c recode-3.6/src/libiconv.c
--- recode-3.6.orig/src/libiconv.c	2000-07-01 13:13:25.000000000 -0400
+++ recode-3.6/src/libiconv.c	2011-09-14 03:41:59.000000000 -0400
@@ -1,5 +1,5 @@
 /* Conversion of files between different charsets and surfaces.
-   Copyright � 1999, 2000 Free Software Foundation, Inc.
+   Copyright � 1999, 2000, 2001 Free Software Foundation, Inc.
    Contributed by Fran�ois Pinard <pinard@iro.umontreal.ca>, 1999,
    and Bruno Haible <haible@clisp.cons.org>, 2000.
 
@@ -37,7 +37,7 @@
   char output_buffer[LIBICONV_BUFFER_SIZE];
   size_t input_left;
   size_t output_left;
-  const char *input;
+  char *input;
   char *output;
   char *cursor;
   int transliterate;
@@ -118,7 +118,7 @@
 		  char tmp_buf[6];
 		  size_t tmp_input_left;
 		  size_t tmp_output_left;
-		  const char *tmp_input;
+		  char *tmp_input;
 		  char *tmp_output;
 
 		  RETURN_IF_NOGO (RECODE_INVALID_INPUT, subtask);
@@ -195,12 +195,17 @@
 	 memcpy() doesn't do here, because the regions might overlap.
 	 memmove() isn't worth it, because we rarely have to move more
 	 than 12 bytes.  */
-      if (input > input_buffer && input_left > 0)
+      cursor = input_buffer;
+      if (input_left > 0)
 	{
-	  cursor = input_buffer;
-	  do
-	    *cursor++ = *input++;
-	  while (--input_left > 0);
+	  if (input > input_buffer)
+	    {
+	      do
+		*cursor++ = *input++;
+	      while (--input_left > 0);
+	    }
+	  else
+	    cursor += input_left;
 	}
     }
 
diff -Nurd -x'*~' recode-3.6.orig/src/recode.c recode-3.6/src/recode.c
--- recode-3.6.orig/src/recode.c	2000-07-01 14:22:55.000000000 -0400
+++ recode-3.6/src/recode.c	2011-09-14 03:41:59.000000000 -0400
@@ -1,6 +1,6 @@
 /* Conversion of files between different charsets and surfaces.
-   Copyright � 1990,92,93,94,96,97,98,99,00 Free Software Foundation, Inc.
-   Contributed by Fran�ois Pinard <pinard@iro.umontreal.ca>, 1990.
+   Copyright � 1990,92,93,94,96,97,98,99,00 Free Software Foundation, Inc.
+   Contributed by Fran�ois Pinard <pinard@iro.umontreal.ca>, 1990.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public License
@@ -32,8 +32,6 @@
 #endif
 
 #include "hash.h"
-
-extern const char *program_name;
 
 /* Error handling.  */
 
diff -Nurd -x'*~' recode-3.6.orig/src/request.c recode-3.6/src/request.c
--- recode-3.6.orig/src/request.c	2000-06-28 14:40:21.000000000 -0400
+++ recode-3.6/src/request.c	2011-09-14 03:41:59.000000000 -0400
@@ -1073,7 +1073,7 @@
   if (task->output.cursor + 4 >= task->output.limit)
     {
       RECODE_OUTER outer = task->request->outer;
-      size_t old_size = task->output.limit - task->output.buffer;
+      size_t old_size = task->output.cursor - task->output.buffer;
       size_t new_size = task->output.cursor + 4 - task->output.buffer;
 
       /* FIXME: Rethink about how the error should be reported.  */
diff -Nurd -x'*~' recode-3.6.orig/src/task.c recode-3.6/src/task.c
--- recode-3.6.orig/src/task.c	2000-07-01 13:50:43.000000000 -0400
+++ recode-3.6/src/task.c	2011-09-14 03:41:59.000000000 -0400
@@ -1198,6 +1198,8 @@
       else
 	success = transform_mere_copy (subtask);
 
+      task->output = subtask->output;
+       
       if (subtask->input.name && *subtask->input.name)
 	fclose (subtask->input.file);
       if (subtask->output.name && *subtask->output.name)
