diff -uNr src.ori/libs/obsdcompat/bsd-asprintf.c src/libs/obsdcompat/bsd-asprintf.c
--- src.ori/libs/obsdcompat/bsd-asprintf.c	2008-02-03 20:52:46.000000000 +0100
+++ src/libs/obsdcompat/bsd-asprintf.c	2008-02-09 13:49:16.000000000 +0100
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 #ifndef VA_COPY
 # ifdef HAVE_VA_COPY
diff -uNr src.ori/texk/configure src/texk/configure
--- src.ori/texk/configure	2008-02-03 20:52:54.000000000 +0100
+++ src/texk/configure	2008-02-09 13:49:16.000000000 +0100
@@ -4308,6 +4308,10 @@
     ld_shlibs=no
     ;;
 
+  aros*)
+    ld_shlibs=no
+    ;;
+
   beos*)
     if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
       allow_undefined_flag=unsupported
@@ -5048,6 +5052,11 @@
   finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "(cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a)"; (cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a) || exit 1; done'
   ;;
 
+aros*)
+  sys_lib_dlsearch_path_spec=""
+  sys_lib_search_path_spec="/SYS/Development/lib"
+  ;;
+
 beos*)
   library_names_spec='${libname}.so'
   dynamic_linker="$host_os ld.so"
diff -uNr src.ori/texk/contrib/fileutils.c src/texk/contrib/fileutils.c
--- src.ori/texk/contrib/fileutils.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/contrib/fileutils.c	2008-02-09 13:49:16.000000000 +0100
@@ -358,6 +358,7 @@
   string p = path;
   mode_t dir_perms = 0777 & ~umask (0);	/* default permissions for `mkdir' */
   mode_t parent_perms = 0;
+  char dir_sep;
 
   /* We can't authorize multiple slashes here */
   normalize(path);
@@ -406,6 +407,7 @@
 #endif
   for ( ; *p ; p++) {
     if (IS_DIR_SEP(*p)) {
+      dir_sep = *p;
       *p = '\0';
       errno = 0;
       if (!test_file('d', path)) {
@@ -426,7 +428,7 @@
 	  /* chmod the directory we just created.  */
 	  chmod(path, dir_perms);
       }
-      *p = DIR_SEP;
+      *p = dir_sep;
     }
   }
   /* and for the whole path */
@@ -497,9 +499,15 @@
   }
 #endif
   for ( p = q = path+offset; *p != '\0'; p++, q++) {
+#ifdef AMIGA
+    *q = *p;
+    if (IS_DIR_SEP(*p) && !IS_DEVICE_SEP(*p))
+      while (*(p+1) && IS_DIR_SEP(*(p+1))) p++;
+#else
     *q = (IS_DIR_SEP(*p) ? DIR_SEP : *p);
     if (IS_DIR_SEP(*p))
       while (*(p+1) && IS_DIR_SEP(*(p+1))) p++;
+#endif
   }
   *q = '\0';
 
diff -uNr src.ori/texk/contrib/fmtutil.c src/texk/contrib/fmtutil.c
--- src.ori/texk/contrib/fmtutil.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/contrib/fmtutil.c	2008-02-09 13:49:17.000000000 +0100
@@ -34,14 +34,17 @@
 #include "variables.h"
 #include "fmtutil.h"
 
+#ifdef AMIGA
+#include <dos/var.h>
+#include <proto/dos.h>
+#endif
+
 #ifdef _WIN32
 #define isatty _isatty
 #else
 #include <glob.h>
 #endif
 
-extern string fmtutil_version_string;
-
 /* 
    Global Variables found in the fmtutil script
 */
@@ -54,7 +57,6 @@
 
 /* fmtutil.cnf */
 
-static boolean downcase_names;
 char cmd_buf[1024];		/* Hope it is enough for handling command */
 char cmd_sys[1024];		/* system() calls */
 char msg_buf[1024];
@@ -354,7 +356,7 @@
     return false;
   if (strncasecmp(texargs, "nls=", 4) == 0) {
     pool = texargs+4;
-    if (tcx = strchr(pool, ',')) {
+    if ((tcx = strchr(pool, ','))) {
       *tcx = '\0';
     }
     texargs = strtok(NULL, " \t");
@@ -490,7 +492,6 @@
 void __cdecl output_and_cleanup(int code)
 {
   /* FIXME : what cleanup ? */
-  int count = 0;
 
   if (test_file('d', tmpdir))
     rec_rmdir(tmpdir);
@@ -623,7 +624,7 @@
   if (test_file('n', cwd)) {
     /* Fixme : is it enough ? */
     if (getenv("KPSE_DOT") == NULL) {
-      xputenv("KPSE_DOT", cwd);
+      xputenv("KPSE_DOT", concat(".;", cwd));
     }
     texinputs = getval("TEXINPUTS");
     if (test_file('z', texinputs)) {
@@ -661,8 +662,12 @@
     tempenv = "c:/tmp";	/* "/tmp" is not good if we are on a CD-ROM */
 #else
   if (test_file ('z', tempenv))
+#ifdef AMIGA
+    tempenv = "T:";
+#else
     tempenv = "/tmp";
 #endif
+#endif
   sprintf(tmpdir, "%s/fmXXXXXX", tempenv);
   mktemp(tmpdir);
   if (do_makedir(tmpdir)) {
@@ -758,7 +763,13 @@
 
 int do_format(int f)
 {
+#ifdef WIN32
   string cmdfmt = "%s -ini %s %s=%s -progname=%s %s <nul";
+#elif AMIGA
+  string cmdfmt = "%s -ini %s %s=%s -progname=%s %s <NIL:";
+#else
+  string cmdfmt = "%s -ini %s %s=%s -progname=%s %s </dev/null";
+#endif
   string fmtswitch;
   string prgswitch;
   int ret = 0;
@@ -813,7 +824,7 @@
 
     process_multiple_files("*.pool", remove_file);
     if (test_file('n', poolfile) && test_file('f', poolfile)) {
-      fprintf(stderr, "%s: attempting to create localized format using pool=$pool and tcx=$tcx.\n",
+      fprintf(stderr, "%s: attempting to create localized format using pool=%s and tcx=%s.\n",
 	      kpse_program_name, fmts[f].poolbase, fmts[f].tcx);
       catfile(poolfile, local_poolfile, false);
       xputenv("TEXPOOL", ".");
@@ -940,7 +951,7 @@
   while (fgets(line, sizeof(line), fin)) {
     if (strncmp(line, "#! ", 3) == 0
 	&& strncmp(line+3, format, strlen(format)) == 0
-	&& isspace(line+3+strlen(format))) {
+	&& isspace(line[3+strlen(format)])) {
       fputs(line + 3, fout);
     }
     else {
@@ -972,7 +983,7 @@
   }
   while (fgets(line, sizeof(line), fin)) {
     if (strncmp(line, format, strlen(format)) == 0
-	&& isspace(line + strlen(format))) {
+	&& isspace(line[strlen(format)])) {
       fputs("#! ", fout);
     }
     fputs(line, fout);
@@ -1100,6 +1111,7 @@
   HANDLE hnd;
 #else
   glob_t gl;
+  int i;
 #endif
 
   strcpy(path, filespec);
@@ -1134,7 +1146,7 @@
 
 #else /* ! WIN32 */
 
-  switch  (glob(path, GLOB_NOCHECK, NULL, &gl)) {
+  switch  (glob(path, GLOB_ERR, NULL, &gl)) {
   case 0:			/* success */
       for (i = 0; i < gl.gl_pathc; i++) {
 	(*fn)(gl.gl_pathv[i]);
@@ -1192,7 +1204,10 @@
   system(cmd);
   /* if we have been called to build a format at runtime */
   if (incarnation == MKTEXFMT) {
-    fputs(fmtdest, stdout);
+    fprintf(stdout, "%s\n", fmtdest);
+#ifdef AMIGA
+    SetVar("LAST_FONT_CREATED", fmtdest, -1, LV_VAR | GVF_GLOBAL_ONLY);
+#endif
   }
   free(fmtdest);
 
diff -uNr src.ori/texk/contrib/main.c src/texk/contrib/main.c
--- src.ori/texk/contrib/main.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/contrib/main.c	2008-02-09 13:49:17.000000000 +0100
@@ -4,6 +4,11 @@
 #include "variables.h"
 #include "fileutils.h"
 
+#ifdef AMIGA
+#include <dos/dos.h>
+#include <proto/dos.h>
+#endif
+
 void __cdecl output_and_cleanup(int code)
 {
   FILE *f;
@@ -32,6 +37,16 @@
     }
   }
 
+  {
+    extern FILE *fout;
+    if (fout)
+    {
+      if (fclose(fout) == EOF)
+        fprintf(stderr, "cannot close fout, errno=%d\n", errno);
+      fout = NULL;
+    }
+  }
+
   if (test_file('d', tmpdir))
     rec_rmdir(tmpdir);
 
@@ -39,7 +54,11 @@
       int count = 0;
       /* Give more than one chance to remove the files */
       while ((count++ < 20) && test_file('d', tmpdir)) {
+#ifdef AMIGA
+	Delay(12); /* 12/50 seconds */
+#else
 	Sleep(250);
+#endif
        rec_rmdir(tmpdir);
       }
   }
diff -uNr src.ori/texk/contrib/makempx.c src/texk/contrib/makempx.c
--- src.ori/texk/contrib/makempx.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/contrib/makempx.c	2008-02-09 13:49:17.000000000 +0100
@@ -195,6 +195,7 @@
 #include "mktex.h"
 #include "stackenv.h"
 #include "fileutils.h"
+#include "variables.h"
 
 static char *DMP;
 static char *DVITOMP;
@@ -259,9 +260,9 @@
 typedef enum { TEXMODE = 0, TROFFMODE} typeset_mode;
 
 #ifdef __GNUC__
-void __attribute__((noreturn)) usage(int exit_code)
+static void __attribute__((noreturn)) usage(int exit_code)
 #else
-void usage(int exit_code)
+static void usage(int exit_code)
 #endif
 {
   fprintf(stderr, "Usage: %s [-tex|-tex=<program>|-troff] MPFILE MPXFILE.\n\
@@ -339,9 +340,9 @@
 #else
   DIR *dp;
   struct dirent *de;
-  int temp_len = strlen(mptemplate) + 1; /* +1 for the dot */
+  int temp_len = strlen(mptemplate);
 
-  if ((dp = opendir(".")) != 0) {
+  if (temp_len > 0 && (dp = opendir(".")) != 0) {
     while ((de = readdir(dp)) != 0)
       if (FILESTRNCASEEQ(de->d_name, mptemplate, temp_len))
 	remove(de->d_name);
@@ -351,7 +352,6 @@
   /* ERRLOG is removed only on normal exit. */
   if (code == 0)
     remove(ERRLOG);
-  
 }
 
 char *change_suffix(char *old, char *suf)
@@ -399,7 +399,7 @@
   string path;
   string mpto_cmd;
   char errbuf[PATH_MAX*2];
-  int mpto_status;
+  int status;
 
   output_and_cleanup_function = output_and_cleanup;
   mptemplate[0] = '\0';
@@ -516,7 +516,7 @@
 
   /* Step 1: Extract typesetter source from MetaPost source.  */
 
-  sprintf(mptemplate, "mpx%d", getpid());
+  sprintf(mptemplate, "mpx%d", (int)getpid());
   strcpy(mpxtex, mptemplate); strcat(mpxtex, ".tex");
   /* redirecting 1 -> mpx$$.tex 2 -> ERRLOG */
   if (!(fmpx = fopen(mpxtex, "w"))) {
@@ -532,14 +532,14 @@
   push_fd(newfd);
 
   mpto_cmd = concat3(MPTO, " ", MPFILE);
-  mpto_status = system(mpto_cmd);
+  status = system(mpto_cmd);
   free(mpto_cmd);
   pop_fd();
   fclose(fmpx);
-  fclose(ferr);
-  if (mpto_status != 0) {
+  if (status != 0) {
     fprintf(stderr, "%s: Command failed: %s %s\n", progname, MPTO, MPFILE);
 
+    fclose(ferr);
     output_file(stderr, ERRLOG);
     /* rm -f mpx$$.tex -- this is done by the wrap-up code */
     mt_exit(1);
@@ -565,13 +565,22 @@
     }
 #ifdef _WIN32
     sprintf(cmd, "%s --interaction=batchmode %s < nul > nul", TEX, mpxtex);
+#elif defined AMIGA
+    sprintf(cmd, "%s --interaction=batchmode %s", TEX, mpxtex);
 #else
     sprintf(cmd, "%s --interaction=batchmode %s </dev/null >/dev/null",
 	    TEX, mpxtex);
 #endif
-    if (system(cmd)) {
+
+    newfd[0] = 0; newfd[1] = fileno(ferr); newfd[2] = fileno(ferr);
+    push_fd(newfd);
+    status = system(cmd);
+    pop_fd();
+
+    if (status != 0) {
       fprintf(stderr, "%s: Command failed: %s %s; see %s\n",
 	      progname, TEX, TEXERR, ERRLOG);
+      fclose(ferr);
       mvfile(mpxtex, TEXERR);
       mvfile(mpxlog, ERRLOG);
       mt_exit(2);
@@ -614,9 +623,15 @@
   }
 
   /* Step 3: Translate typesetter output to a MetaPost MPX.  */
+  sprintf(cmd, "%s %s %s", WHATEVER_TO_MPX, INFILE, MPXFILE);
+
+  newfd[0] = 0; newfd[1] = fileno(ferr); newfd[2] = fileno(ferr);
+  push_fd(newfd);
+  status = system(cmd);
+  pop_fd();
+  fclose(ferr);
 
-  sprintf(cmd, "%s %s %s > %s", WHATEVER_TO_MPX, INFILE, MPXFILE, ERRLOG);
-  if (system(cmd)) {
+  if (status != 0) {
     fprintf(stderr, "%s: Command failed: %s %s %s\n", progname,
 	    WHATEVER_TO_MPX, INERROR, MPXFILE);
     mvfile(INFILE, INERROR);
@@ -626,5 +641,6 @@
     output_file(stderr, ERRLOG);
     mt_exit(3);
   }
+
   mt_exit(0);
 }
diff -uNr src.ori/texk/contrib/mktex.c src/texk/contrib/mktex.c
--- src.ori/texk/contrib/mktex.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/contrib/mktex.c	2008-02-09 13:49:17.000000000 +0100
@@ -31,6 +31,11 @@
 #include "fileutils.h"
 #include "mktex.h"
 
+#ifdef AMIGA
+#include <dos/var.h>
+#include <proto/dos.h>
+#endif
+
 #ifdef _WIN32
 #define isatty _isatty
 #endif
@@ -204,6 +209,9 @@
   int option_index;
   string tempenv, cwd, vartexmf;
 
+  /* default value */
+  setval("MAG", "1");
+
   for(;;) {
     g = getopt_long_only (argc, argv, "", long_options, &option_index);
 
@@ -309,8 +317,12 @@
     tempenv = "c:/tmp";	/* "/tmp" is not good if we are on a CD-ROM */
 #else
   if (test_file ('z', tempenv))
+#ifdef AMIGA
+    tempenv = "T:";
+#else
     tempenv = "/tmp";
 #endif
+#endif
   sprintf(tmpdir, "%s/mtXXXXXX", tempenv);
   mktemp(tmpdir);
   if (do_makedir(tmpdir)) {
@@ -405,7 +417,7 @@
 
 /* If non-negative, records the handle to redirect STDOUT
    in `output_and_cleanup'.  */
-int redirect_stdout;
+int redirect_stdout = -1;
 
 /* Record the handle where STDOUT is to be redirected
    for printing the names of the generated files before we exit.  */
@@ -597,6 +609,18 @@
 
 #ifdef MONOCASE_FILENAMES
   char name[PATH_MAX];
+#ifdef AMIGA
+  string s = path;
+  string d = name;
+
+  retval = FALSE;
+
+  while (!IS_DEVICE_SEP(*s) && *s != '\0')
+    *d++ = *s++;
+  if (*s != '\0')
+    *d++ = *s++;
+  *d = '\0';
+#else
 #ifdef _WIN32
   char volname[PATH_MAX];
   DWORD sernum;
@@ -678,6 +702,8 @@
      After all, this flag distinguishes NTFS from all FATs */
     retval = (fsflags & FS_CASE_SENSITIVE) != 0;
   
+#endif /* AMIGA */
+
   if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
     fprintf(stderr, "FS %s %s case-sensitive\n", name, 
 	    (retval ? "is" : "is not"));
@@ -806,15 +832,23 @@
 	continue;
       }
 
+#define I_WILL_USE_EXISTING_TMP_DIR 1
+
+#if I_WILL_USE_EXISTING_TMP_DIR
+      /* this is created at startup */
+      sprintf(db_dir_tmp, "%s", getval("TEMPDIR"));
+#else
       sprintf(db_dir_tmp, "%s/lsXXXXXX", db_dir);
       if (mktemp(db_dir_tmp) == NULL) {
 	perror(db_dir_tmp);
 	mt_exit(1);
       }
       if (mkdir(db_dir_tmp, 0777 & ~umask(0)) == -1) {
-	fprintf(stderr, "%s: could not create directory '%s'. Skipping...\n");
+	fprintf(stderr, "%s: could not create directory '%s'. Skipping...\n",
+	        progname, db_dir_tmp);
 	continue;
       }
+#endif
 
       sprintf(db_file_tmp, "%s/lsXXXXXX", db_dir_tmp); 
       if (mktemp(db_file_tmp) == NULL) {
@@ -842,8 +876,11 @@
       push_fd(newfd);
       
       puts(getval("ls_R_magic"));
+
+#ifdef I_WANT_DEV_NULL_AND_NEWLINE_AT_START_OF_MY_LS_R
       fputs("/dev/null", stdout);	/* like `ls -R' does */
       putchar('\n');
+#endif
 
       /* Record the info about the temporary file, so we don't enter
          it into the database.  */
@@ -885,14 +922,18 @@
 	mt_exit(1);
       }
 
+#if !!! I_WILL_USE_EXISTING_TMP_DIR
       do_rmdir(db_dir_tmp);
+#endif
 
       free(db_file);
     }
   }
   free(newargv);
 
+#ifdef WIN32
   hash_reinit();
+#endif
 
   if (isatty(fileno(stdout)))
     fprintf(stderr, "%s: Done.\n", progname);
@@ -1443,6 +1484,7 @@
 
   s_dest = expand_var("$DEST");
   if (test_file('n', s_dest))
+  {
     if (kpse_absolute_p(s_dest, false)) {
       setval("MT_PKDESTDIR", s_dest);
       setval("MT_TFMDESTDIR", s_dest);
@@ -1451,6 +1493,7 @@
     }
     else
       setval("MT_NAMEPART", s_dest);
+  }
   
   setval ("MT_MODE", expand_var("$MODE"));
   setval ("MT_NAMEPART", expand_var("$MT_NAMEPART"));
@@ -1861,6 +1904,7 @@
   chmod_as_dir(tmpmf, ".", 00644);
   unlink(mfname);
   if (mvfile(tmpmf, mfname) == FALSE) {
+/*sleep(30);*/
     mt_exit(1);
   }
   setval("destdir", destdir);
@@ -1954,11 +1998,14 @@
   setval("TFMNAME", concat(name, ".tfm"));
   /* FIXME: can e.g. cmr10.600gf clash with e.g. cmr10.600whatever on DOS?  */
   setval("GFNAME", concatn(name, ".", getval("DPI"), "gf", NULL));
-  
-  fullname = expand_var("$TFMDESTDIR/$TFMNAME");
+
+  fullname = getval("MT_TFMNAME");/*expand_var("$TFMDESTDIR/$TFMNAME");*/
   if (test_file('r', fullname)) {
     fprintf(stderr, "%s: %s already exists.\n", progname, fullname);
     fprintf(fout, "%s\n", fullname);
+#ifdef AMIGA
+    SetVar("LAST_FONT_CREATED", fullname, -1, LV_VAR | GVF_GLOBAL_ONLY);
+#endif
     free(fullname);
     do_mktexupdate(getval("TFMDESTDIR"), getval("TFMNAME"));
     return;
@@ -2043,11 +2090,16 @@
 				       getval("PKNAME")))) {
     char *pktmp_base;
 
-    sprintf(cmd, "gftopk ./%s %s", getval("GFNAME"), getval("PKNAME"));
+    sprintf(cmd, "gftopk %s %s", getval("GFNAME"), getval("PKNAME"));
     if (KPSE_DEBUG_P(MKTEX_DEBUG)) {
       fprintf(stderr, "Running: %s\n", cmd);
     }
-    retcode = system(cmd);
+    {
+      string kpse_dot = getenv("KPSE_DOT");
+      xputenv("KPSE_DOT", xgetcwd());
+      retcode = system(cmd);
+      xputenv("KPSE_DOT", kpse_dot);
+    }
     if (retcode != 0) {
       if (retcode == -1)
 	perror("gftopk");
@@ -2075,6 +2127,11 @@
       do_mktexupdate(getval("PKDESTDIR"), getval("PKNAME"));
     }
     popd();
+
+#ifdef AMIGA
+    SetVar("LAST_FONT_CREATED", fullname, -1, LV_VAR | GVF_GLOBAL_ONLY);
+#endif
+    free(fullname);
   }
 }
 
@@ -2214,7 +2271,7 @@
 	modes[nb_modes].hor_res = atoi(cp);
 	modes[nb_modes].vert_res = atoi(cp);
       }
-      else if (cp = strstr(line, "aspect_ratio")) {
+      else if ((cp = strstr(line, "aspect_ratio"))) {
 	SKIP_NON_DIGIT (cp);
 	modes[nb_modes].vert_res = atoi(cp);
       }
@@ -2313,6 +2370,9 @@
 
   setval("NAME", argv[1]);
 
+  if (!getval("DPI"))
+    setval("DPI", getval("BDPI"));
+
   has_ttf2pk = find_exe("ttf2pk");
   has_hbf2gf = find_exe("hbf2gf");
 
@@ -2521,6 +2581,9 @@
     fprintf(stderr, "%s: %s already exists.\n",
 	    progname, fullname);
     fprintf(fout, "%s\n", fullname);
+#ifdef AMIGA
+    SetVar("LAST_FONT_CREATED", fullname, -1, LV_VAR | GVF_GLOBAL_ONLY);
+#endif
     free(fullname);
     do_mktexupdate(getval("PKDESTDIR"), getval("PKNAME"));
     return 0;
@@ -2558,10 +2621,18 @@
       mt_exit(1);
     }
   }
-  
+
   if (test_file('r', getval("GFNAME"))) {
-    gfcmd = expand_var("gftopk ./$GFNAME $PKNAME");
+    string cwd = xgetcwd();
+    string kpse_dot = getval("KPSE_DOT");
+    gfcmd = expand_var("gftopk $GFNAME $PKNAME");
+    xputenv("KPSE_DOT", cwd);
+
     retcode = system(gfcmd);
+
+    xputenv("KPSE_DOT", kpse_dot);
+    free(cwd);
+
     if (retcode == -1) {
       perror("gftopk");
       mt_exit(1);
@@ -2603,6 +2674,9 @@
   fprintf(fout, "%s\n", fullname);
   fprintf(stderr, "%s: %s: successfully generated.\n", progname,
 	  fullname);
+#ifdef AMIGA
+  SetVar("LAST_FONT_CREATED", fullname, -1, LV_VAR | GVF_GLOBAL_ONLY);
+#endif
   free(fullname);
 
   popd();
diff -uNr src.ori/texk/contrib/stackenv.c src/texk/contrib/stackenv.c
--- src.ori/texk/contrib/stackenv.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/contrib/stackenv.c	2008-02-09 13:49:17.000000000 +0100
@@ -112,7 +112,7 @@
   }
   stack_env[index_env].op = CHDIR;
   if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
-    fprintf(stderr, "At %d, pushing from %s to %s\n", index_env, 
+    kprintf("At %d, pushing from %s to %s\n", index_env, 
 	    stack_env[index_env].data.path, p);
   }
 
@@ -201,11 +201,15 @@
       stack_env[index_env].data.oldfd[i] = i;
     else {
       if ((stack_env[index_env].data.oldfd[i] = dup(i)) == -1) {
-	perror("push_fd: dup");
+        char str[32];
+        sprintf(str, "push_fd: dup(%d)", i);
+	perror(str);
 	mt_exit(1);
       }
       if (dup2(newfd[i], i) == -1) {
-	perror("push_fd : dup2");
+        char str[32];
+        sprintf(str, "push_fd: dup2(%d)", i);
+	perror(str);
 	mt_exit(1);
       }
     }
@@ -327,11 +331,7 @@
 {
   int newfd[3];
   if (fnul == NULL)
-#ifdef _WIN32
-  fnul = fopen("nul", "r");	/* fopen /dev/null */
-#else
-  fnul = fopen("/dev/null", "r");
-#endif
+    fnul = fopen(DEV_NULL, "r");
   
   newfd[0] = fileno(fnul);
   newfd[1] = (discard_stdout ? fileno(fnul) : fileno(stderr));
diff -uNr src.ori/texk/contrib/variables.c src/texk/contrib/variables.c
--- src.ori/texk/contrib/variables.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/contrib/variables.c	2008-02-09 13:49:17.000000000 +0100
@@ -28,23 +28,23 @@
   */
 
 /* The symbol table */
-hash_table_type *symtab = NULL;
+hash_table_type symtab = {0};
 
 /* Initialize a symbol table to store all the vars used by 
    the various shell scripts. */
 void init_vars()
 {
 
-  symtab = hash_create(719, hashtable_symtab);
+  symtab = hash_create(719);
 
 }
 
 void
-hash_remove_all (hash_table_type *table, string key)
+hash_remove_all (hash_table_type table, string key)
 {
   string *val;
   while ((val = hash_lookup(table, key))) {
-    hash_remove(table, key, *val);
+    hash_remove(&table, key, *val);
     free (val);
   }
 }
@@ -108,7 +108,7 @@
   /* Be safe ... */
   if (!value) value = "";
   hash_remove_all(symtab, name);
-  hash_insert(symtab, name, value);
+  hash_insert(&symtab, name, value);
   if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
     fprintf(stderr, "SetVal %s <= %s\n", name, value);
   }
@@ -134,7 +134,7 @@
   /* The mktex... scripts NEVER use ${foo:=bar}, always ${foo=bar}.
      So we only need to set NAME=VALUE if $NAME is unset.  */
   if ((old_value = getval(name)) == NULL) {
-    hash_insert(symtab, name, value);
+    hash_insert(&symtab, name, value);
     if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
       fprintf(stderr, "SetVal %s <= %s\n", name, value);
     }
@@ -144,15 +144,22 @@
 
   return value;
 }
-
+#define HAVE_GNU_REGEX 1
 string *grep(char *regexp, char *line, int num_vars) 
 {
+#ifdef HAVE_GNU_REGEX
   struct re_pattern_buffer *rc;
   struct re_registers *p;
   const_string ok;
+#else
+  regex_t preg;
+  regmatch_t *p;
+#endif
   string *vars = NULL;
-  string *lookup;
   int i;
+#if 0
+  string *lookup;
+#endif
 
   if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
     fprintf(stderr, "Grep\n\t%s\n\tin\n\t%s\n", regexp, line);
@@ -177,11 +184,17 @@
       fprintf(stderr, "\tCompiling the regexp\n");
     }
 
+#ifdef HAVE_GNU_REGEX
     re_syntax_options = RE_SYNTAX_POSIX_EGREP;
     rc = (struct re_pattern_buffer *) calloc(1, sizeof(struct re_pattern_buffer));
     rc->regs_allocated = REGS_UNALLOCATED;
     if ((ok = re_compile_pattern(regexp, strlen(regexp), rc)) != 0)
       FATAL1("Can't compile regex %s\n", regexp);
+#else
+    if (regcomp(&preg, regexp, REG_EXTENDED) != 0)
+      FATAL1("Can't compile regex %s\n", regexp);
+#endif
+
 #if 0
     hash_remove_all(symtab, regexp);
     hash_insert(symtab, regexp, (char *)rc);
@@ -191,6 +204,7 @@
   }
 #endif
 
+#ifdef HAVE_GNU_REGEX
   p = (struct re_registers *) calloc(1, sizeof(struct re_registers));
   p->num_regs = num_vars;
   if ((re_match(rc, line, strlen(line), 0, p)) > 0) {
@@ -201,7 +215,24 @@
       vars[i][p->end[i] - p->start[i]] = '\0';
     }
   }
-  free (p);
+#else
+  p = (regmatch_t*)calloc(num_vars + 1, sizeof(regmatch_t));
+  if (regexec(&preg, line, num_vars, p, 0) == 0) {
+    vars = (char **) xmalloc ((num_vars+1) * sizeof(char *));
+    for (i = 0; i <= num_vars; i++) {
+      if (p[i].rm_so >= 0) {
+        int len = p[i].rm_eo - p[i].rm_so;
+        vars[i] = malloc((len + 1) * sizeof(char));
+        strncpy(vars[i], line + p[i].rm_so, len);
+        vars[i][len] = '\0';
+      } else {
+        vars[i] = NULL;
+        break;
+      }
+    }
+  }
+#endif
+  free(p);
   if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
     if (vars)
       for(i = 0; i <= num_vars; i++)
@@ -225,7 +256,7 @@
   static char *r1 = "^[[:space:]]*([[:alnum:]_]+)=[[:space:]]*([^[:space:]]*)[[:space:]]*.*$";
   static char *r2 = "^:[[:space:]]+\\$\\{([[:alnum:]_]+)=([^\\}]*)\\}[[:space:]]*.*$";
 
-  if ((vars = grep(r1, line, 2))) {
+  if (0&&(vars = grep(r1, line, 2))) {
     setval(vars[1], vars[2]);
     return true;
   }
diff -uNr src.ori/texk/contrib/variables.h src/texk/contrib/variables.h
--- src.ori/texk/contrib/variables.h	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/contrib/variables.h	2008-02-09 13:49:17.000000000 +0100
@@ -11,11 +11,13 @@
 extern MKTEXDLL char *getval(char *name);
 extern MKTEXDLL char *setval(char *name,char *value);
 extern MKTEXDLL char *setval_default(char *name,char *value);
-extern MKTEXDLL char **grep(char *regexp,char *line,int num_vars) ;
+extern MKTEXDLL char **grep(char *regexp,char *line,int num_vars);
 
 extern MKTEXDLL boolean parse_variable(char *line);
 
+#ifndef __AROS__
 extern char *strcasestr(char *s1,char *s2);
+#endif
 
 extern char *subst(char *line, char *from, char *to);
 extern MKTEXDLL string expand_var(const_string);
diff -uNr src.ori/texk/dvipos/configure src/texk/dvipos/configure
--- src.ori/texk/dvipos/configure	2008-02-03 20:52:49.000000000 +0100
+++ src/texk/dvipos/configure	2008-02-09 13:49:17.000000000 +0100
@@ -3260,6 +3260,10 @@
     ld_shlibs=no
     ;;
 
+  aros*)
+    ld_shlibs=no
+    ;;
+
   beos*)
     if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
       allow_undefined_flag=unsupported
@@ -3538,6 +3542,10 @@
     ld_shlibs=no
     ;;
 
+  aros*)
+    ld_shlibs=no
+    ;;
+
   cygwin* | mingw* | pw32*)
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -4000,6 +4008,11 @@
   finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "(cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a)"; (cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a) || exit 1; done'
   ;;
 
+aros*)
+  sys_lib_dlsearch_path_spec=""
+  sys_lib_search_path_spec="/SYS/Development/lib"
+  ;;
+
 beos*)
   library_names_spec='${libname}.so'
   dynamic_linker="$host_os ld.so"
diff -uNr src.ori/texk/kpathsea/config.h src/texk/kpathsea/config.h
--- src.ori/texk/kpathsea/config.h	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/kpathsea/config.h	2008-02-09 13:49:17.000000000 +0100
@@ -47,13 +47,15 @@
 #endif
 
 /* case-insensitive filename comparisons? */
-#if defined (DOSISH)
+#if defined (DOSISH) || defined (AMIGA)
 #define MONOCASE_FILENAMES
 #endif
 
 /* NULL device. */
 #if defined (DOSISH)
 #define DEV_NULL "NUL"
+#elif defined (AMIGA)
+#define DEV_NULL "NIL:"
 #else
 #define DEV_NULL "/dev/null"
 #endif
diff -uNr src.ori/texk/kpathsea/configure src/texk/kpathsea/configure
--- src.ori/texk/kpathsea/configure	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/kpathsea/configure	2008-02-09 13:49:17.000000000 +0100
@@ -3268,6 +3268,10 @@
     ld_shlibs=no
     ;;
 
+  aros*)
+    ld_shlibs=no
+    ;;
+
   beos*)
     if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
       allow_undefined_flag=unsupported
@@ -3546,6 +3550,10 @@
     ld_shlibs=no
     ;;
 
+  aros*)
+    ld_shlibs=no
+    ;;
+
   cygwin* | mingw* | pw32*)
     # When not using gcc, we currently assume that we are using
     # Microsoft Visual C++.
@@ -4008,6 +4016,11 @@
   finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "(cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a)"; (cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a) || exit 1; done'
   ;;
 
+aros*)
+  sys_lib_dlsearch_path_spec=""
+  sys_lib_search_path_spec="/SYS/Development/lib"
+  ;;
+
 beos*)
   library_names_spec='${libname}.so'
   dynamic_linker="$host_os ld.so"
diff -uNr src.ori/texk/kpathsea/db.c src/texk/kpathsea/db.c
--- src.ori/texk/kpathsea/db.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/kpathsea/db.c	2008-02-09 13:49:17.000000000 +0100
@@ -49,7 +49,9 @@
 
 static const_string db_names[] = {
     DB_NAME,
+#ifndef MONOCASE_FILENAMES
     DB_NAME_LC,
+#endif
     NULL
 };
 
diff -uNr src.ori/texk/kpathsea/findpath.c src/texk/kpathsea/findpath.c
--- src.ori/texk/kpathsea/findpath.c	1970-01-01 01:00:00.000000000 +0100
+++ src/texk/kpathsea/findpath.c	2008-02-09 13:52:51.000000000 +0100
@@ -0,0 +1,45 @@
+/* SAS/C compitibility
+
+This function locates a file in the currently defined path. If the process is
+not a Shell process, it uses the path in effect when Workbench was loaded.
+
+If the findpath function finds the file, it returns a lock on that directory
+even if it is the current directory. The lock must be unlocked with the
+AmigaDOS UnLock function. If the findpath function cannot find the file,
+it returns a -1. The value NULL is not used because NULL is a valid lock.
+
+*/
+
+#include <proto/dos.h>
+
+void* findpath(const char *filename)
+{
+    BPTR file = Lock(filename, SHARED_LOCK);
+
+    if (file <= 0)
+    {
+	struct CommandLineInterface *cli = Cli();
+        BPTR oldCurDir = CurrentDir(NULL);
+	BPTR *paths = BADDR(cli->cli_CommandDir);
+
+        if (IoErr() == ERROR_OBJECT_IN_USE)
+          return -1;
+
+        for (; !file && paths; paths = BADDR(paths[0]))
+        {
+            CurrentDir(paths[1]);
+            file = Lock(filename, SHARED_LOCK);
+        }
+
+	CurrentDir(oldCurDir);
+    }
+
+    if (file > 0)
+    {
+	BPTR dir = ParentOfFH(file);
+	UnLock(file);
+	file = dir;
+    }
+
+    return file ? file : -1;
+}
diff -uNr src.ori/texk/kpathsea/getpath.c src/texk/kpathsea/getpath.c
--- src.ori/texk/kpathsea/getpath.c	1970-01-01 01:00:00.000000000 +0100
+++ src/texk/kpathsea/getpath.c	2008-02-09 13:53:52.000000000 +0100
@@ -0,0 +1,18 @@
+/* SAS/C compatibility
+
+This function returns the fully specified path string for the directory
+and/or file referenced by the lock. The path argument includes the volume
+name. The destination buffer must be large enought to contain the string.
+
+If the getpath function is successful, it returns 0; otherwise, it returns -1. 
+*/
+
+#include <proto/dos.h>
+#include <stdio.h>
+
+int getpath(BPTR lock, char *path)
+{
+    if (!NameFromLock(lock, path, BUFSIZ))
+        return -1;
+    return 0;
+}
diff -uNr src.ori/texk/kpathsea/lib.h src/texk/kpathsea/lib.h
--- src.ori/texk/kpathsea/lib.h	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/kpathsea/lib.h	2008-02-09 13:49:17.000000000 +0100
@@ -22,6 +22,7 @@
 #ifndef KPATHSEA_LIB_H
 #define KPATHSEA_LIB_H
 
+#include <kpathsea/c-ctype.h>
 #include <kpathsea/c-proto.h>
 #include <kpathsea/types.h>
 
diff -uNr src.ori/texk/kpathsea/strstr.c src/texk/kpathsea/strstr.c
--- src.ori/texk/kpathsea/strstr.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/kpathsea/strstr.c	2008-02-09 13:49:17.000000000 +0100
@@ -82,7 +82,8 @@
 	      a = *++haystack;
 	      if (a == '\0')
 		goto ret0;
-shloop:	    }
+shloop:	continue;
+            }
           while (a != b);
 
 jin:	  a = *++haystack;
diff -uNr src.ori/texk/kpathsea/tex-make.c src/texk/kpathsea/tex-make.c
--- src.ori/texk/kpathsea/tex-make.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/kpathsea/tex-make.c	2008-02-09 13:49:17.000000000 +0100
@@ -172,11 +172,14 @@
     string newcmd;
     cmd = xstrdup(args[0]);
     for (s = &args[1];  *s != NULL; s++) {
-      newcmd = concat(cmd, *s);
+      newcmd = concat3(cmd, " ", *s);
       free (cmd);
       cmd = newcmd;
     }
-    ret = system(cmd) == 0 ? getenv ("LAST_FONT_CREATED"): NULL;
+    if (system(cmd) == 0)
+      ret = getenv ("LAST_FONT_CREATED");
+    else
+      ret = NULL;
     free (cmd);
   }
 #elif defined (MSDOS) && !defined(DJGPP)
diff -uNr src.ori/texk/kpathsea/xdirname.c src/texk/kpathsea/xdirname.c
--- src.ori/texk/kpathsea/xdirname.c	2008-02-03 20:52:51.000000000 +0100
+++ src/texk/kpathsea/xdirname.c	2008-02-09 13:49:17.000000000 +0100
@@ -69,10 +69,18 @@
             strcpy(ret, name);
         }
     } else {
+#ifdef AMIGA
+	/* On AmigaOS, AROS, ..., device separtor is important to keep  */
+	if (loc > limit+1 && IS_DIR_SEP(name[loc-1]))
+	    --loc;
+	if (loc > limit+1 && IS_DEVICE_SEP(name[loc]))
+	    ++loc;
+#else
         /* If have ///a, must return /, so don't strip off everything.  */
         while (loc > limit+1 && IS_DIR_SEP (name[loc-1])) {
             loc--;
         }
+#endif
         ret = (string)xmalloc(loc+1);
         strncpy(ret, name, loc);
         ret[loc] = '\0';
@@ -95,6 +103,12 @@
     "p:win32\\kpsewhich.exe",
     "p:kpsewhich.exe",
     "p:///kpsewhich.exe",
+    "SYS:Extras/bin/kpsewhich",
+    "SYS:bin/kpsewhich",
+    "SYS:kpsewhich",
+    "SYS:",
+    "SYS:toto//titi/kpsewhich",
+    "SYS:toto//kpsewhich",
     "/usr/bin/win32/kpsewhich.exe",
     "/usr/bin/kpsewhich.exe",
     "/usr/kpsewhich.exe",
diff -uNr src.ori/texk/libtool.m4 src/texk/libtool.m4
--- src.ori/texk/libtool.m4	2008-02-03 20:52:54.000000000 +0100
+++ src/texk/libtool.m4	2008-02-09 13:49:17.000000000 +0100
@@ -1276,6 +1276,10 @@
     ld_shlibs=no
     ;;
 
+  aros*)
+    ld_shlibs=no
+    ;;
+
   beos*)
     if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
       allow_undefined_flag=unsupported
@@ -2013,6 +2017,11 @@
   finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "(cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a)"; (cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a) || exit 1; done'
   ;;
 
+aros*)
+  sys_lib_search_path_spec="/SYS/Development/lib /SYS/Extra/lib"
+  sys_lib_dlsearch_path_spec=""
+  ;;
+
 beos*)
   library_names_spec='${libname}.so'
   dynamic_linker="$host_os ld.so"
diff -uNr src.ori/texk/web2c/mpdir/Makefile.in src/texk/web2c/mpdir/Makefile.in
--- src.ori/texk/web2c/mpdir/Makefile.in	2008-02-03 20:52:53.000000000 +0100
+++ src/texk/web2c/mpdir/Makefile.in	2008-02-09 13:49:17.000000000 +0100
@@ -5,6 +5,7 @@
 kpse_include ../make/common.mk
 kpse_include ../make/programs.mk
 kpse_include ../make/library.mk
+kpse_include ../make/cross.mk
 
 kpathsea_srcdir_parent = $(srcdir)/../..
 kpathsea_dir_parent = ../..
@@ -24,7 +25,7 @@
 	$(RANLIB) $@
 
 makecpool: makecpool.o
-	$(link_command) makecpool.o
+	$(build_link_command) makecpool.o
 
 kpse_include ../make/clean.mk
 
diff -uNr src.ori/texk/web2c/mpware/makempx.c src/texk/web2c/mpware/makempx.c
--- src.ori/texk/web2c/mpware/makempx.c	2008-02-03 20:52:52.000000000 +0100
+++ src/texk/web2c/mpware/makempx.c	2008-02-09 13:49:17.000000000 +0100
@@ -52,6 +52,9 @@
 #include <io.h>
 #include <process.h>
 #else
+#ifdef __AROS__
+#include <process.h>
+#endif
 #include <sys/types.h>
 #include <dirent.h>
 #include <sys/wait.h>
@@ -258,7 +261,7 @@
     int i;
     char *cmd;
     int retcode;
-#ifndef WIN32
+#if !defined WIN32 && !defined AMIGA
     pid_t child;
 #endif
     char **options = NULL;
@@ -280,7 +283,7 @@
 	    fprintf(stderr, " %s", options[i]);
 	fprintf(stderr, "\n");
     }
-#ifndef WIN32
+#if !defined WIN32 && !defined AMIGA
     {
 	child = fork();
 	if (child >= 0) {
diff -uNr src.ori/texk/web2c/window/amiga.c src/texk/web2c/window/amiga.c
--- src.ori/texk/web2c/window/amiga.c	2008-02-03 20:52:52.000000000 +0100
+++ src/texk/web2c/window/amiga.c	2008-02-09 13:49:17.000000000 +0100
@@ -108,7 +108,7 @@
 int scaledheight = 0;
 
 #ifndef scalefactor
-#define scalefactor 1
+#define scalefactor 2
 #endif
 
 /*
@@ -276,10 +276,10 @@
 
   SetAPen (Win->RPort, BACKGROUNDCOLOR);
   RectFill(Win->RPort,
-    (SHORT)(Win->BorderLeft + left/scalefactor),
-    (SHORT)(Win->BorderTop + top/(scalefactor*lacefactor)),
-    (SHORT)(Win->BorderLeft + right/scalefactor - 1),
-    (SHORT)(Win->BorderTop + bottom/(scalefactor*lacefactor) - 1));
+    (WORD)(Win->BorderLeft + left/scalefactor),
+    (WORD)(Win->BorderTop + top/(scalefactor*lacefactor)),
+    (WORD)(Win->BorderLeft + right/scalefactor - 1),
+    (WORD)(Win->BorderTop + bottom/(scalefactor*lacefactor) - 1));
 } /* mf_amiga_blankrectangle() */
 
 /*
