This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] AmigaOS 4 port contribution [libiberty]


DJ Delorie <dj@redhat.com> writes:

> make-temp-file.c: It would be nice to replace os-specific ifdefs with
> os-specific arrays of strings to try, then just loop through however
> many there are.  However, a simpler simplification would be to just
> hard-code "T:" in the amigaos-specific block:
> 
> +#ifndef __amigaos__
>    /* Try /var/tmp, /usr/tmp, then /tmp.  */
>    base = try (vartmp, base);
>    base = try (usrtmp, base);
>    base = try (tmp, base);
> +#else /* __amigaos__ */
> +  /* Try T: */
> +  base = try ("T:", base);
> +#endif /* __amigaos__ */
> 
> 
> The other ones are done the way they are because DIR_SEPARATOR might
> change.  That is not true for amigaos, so there's no point in making
> the code more complex for it.
> 
> Also, the code to avoid replicating a trailing dir separator can be
> platform-independent.  While amigaos is the only platform that needs
> it, all platforms can use it.

Ok, I have implemented these changes, and improved the pexecute
implementation to pass the test suggested by Zack.  What I'm going to
do now is to subdivide the patches according to the different
ChangeLogs so that I can repost them more quickly as I get ready with
each subpart.  Here is then the updated subpatch for libiberty.


  // Marcus


Changelog entry:

	* configure.in, Makefile.in: Add pex-amigaos.
	* pex-amigaos.c: New.
	* basename.c, lbasename.c, make-relative-prefix.c: Support
	AmigaOS pathname semantics.
	* lrealpath.c: Use readlink as a fallback on AmigaOS.
	* make-temp-file.c (choose_tmpdir): Use T: as the tmpdir on AmigaOS.
	Avoid adding DIR_SEPARATORs when not needed.


? libiberty/autom4te.cache
? libiberty/pex-amigaos.c
Index: libiberty/Makefile.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/Makefile.in,v
retrieving revision 1.93
diff -u -p -r1.93 Makefile.in
--- libiberty/Makefile.in	22 Jun 2003 15:59:49 -0000	1.93
+++ libiberty/Makefile.in	7 Oct 2003 20:53:21 -0000
@@ -143,7 +143,7 @@ CFILES = alloca.c argv.c asprintf.c atex
 	 mempcpy.c memset.c mkstemps.c					\
 	objalloc.c obstack.c						\
 	partition.c							\
-	 pex-djgpp.c pex-mpw.c pex-msdos.c pex-os2.c			\
+	 pex-amigaos.c pex-djgpp.c pex-mpw.c pex-msdos.c pex-os2.c	\
 	 pex-unix.c pex-win32.c						\
          physmem.c putenv.c						\
 	random.c regex.c rename.c rindex.c				\
@@ -187,7 +187,7 @@ CONFIGURED_OFILES = asprintf.o atexit.o	
 	getcwd.o getpagesize.o						\
 	index.o insque.o						\
 	memchr.o memcmp.o memcpy.o memmove.o mempcpy.o memset.o mkstemps.o \
-	pex-djgpp.o pex-mpw.o pex-msdos.o pex-os2.o			\
+	pex-amigaos.o pex-djgpp.o pex-mpw.o pex-msdos.o pex-os2.o	\
 	 pex-unix.o pex-win32.o						\
 	 putenv.o							\
 	random.o rename.o rindex.o					\
@@ -467,6 +467,8 @@ objalloc.o: config.h $(INCDIR)/ansidecl.
 obstack.o: config.h $(INCDIR)/obstack.h
 partition.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
 	$(INCDIR)/partition.h
+pex-amigaos.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
+	$(srcdir)/pex-common.h
 pex-djgpp.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
 	$(srcdir)/pex-common.h
 pex-mpw.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
Index: libiberty/basename.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/basename.c,v
retrieving revision 1.6
diff -u -p -r1.6 basename.c
--- libiberty/basename.c	26 Sep 2001 18:16:17 -0000	1.6
+++ libiberty/basename.c	7 Oct 2003 20:53:21 -0000
@@ -28,6 +28,12 @@ Behavior is undefined if the pathname en
 #endif
 #endif
 
+#ifdef __amigaos__
+#  ifndef DIR_SEPARATOR_2 
+#    define DIR_SEPARATOR_2 ':'
+#  endif
+#endif
+
 /* Define IS_DIR_SEPARATOR.  */
 #ifndef DIR_SEPARATOR_2
 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
Index: libiberty/configure.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/configure.in,v
retrieving revision 1.73
diff -u -p -r1.73 configure.in
--- libiberty/configure.in	1 Oct 2003 17:11:29 -0000	1.73
+++ libiberty/configure.in	7 Oct 2003 20:53:24 -0000
@@ -481,6 +481,7 @@ case "${host}" in
      *-*-msdosdjgpp*)		pexecute=pex-djgpp.o  ;;
      *-*-msdos*)		pexecute=pex-msdos.o  ;;
      *-*-os2-emx*)		pexecute=pex-os2.o    ;;
+     *-*-amigaos*)		pexecute=pex-amigaos.o;;
      *)				pexecute=pex-unix.o   ;;
 esac
 AC_SUBST(pexecute)
Index: libiberty/lbasename.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/lbasename.c,v
retrieving revision 1.4
diff -u -p -r1.4 lbasename.c
--- libiberty/lbasename.c	18 Jun 2002 02:04:33 -0000	1.4
+++ libiberty/lbasename.c	7 Oct 2003 20:53:24 -0000
@@ -53,6 +53,12 @@ and a path ending in @code{/} returns th
 #  endif
 #endif
 
+#ifdef __amigaos__
+#  ifndef DIR_SEPARATOR_2 
+#    define DIR_SEPARATOR_2 ':'
+#  endif
+#endif
+
 #ifndef DIR_SEPARATOR_2
 #  define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
 #else
Index: libiberty/lrealpath.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/lrealpath.c,v
retrieving revision 1.1
diff -u -p -r1.1 lrealpath.c
--- libiberty/lrealpath.c	20 Feb 2003 22:11:13 -0000	1.1
+++ libiberty/lrealpath.c	7 Oct 2003 20:53:24 -0000
@@ -49,6 +49,7 @@ components will be simplified.  The retu
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
+#include <stdio.h> /* for MAXPATHLEN */
 
 /* On GNU libc systems the declaration is only visible with _GNU_SOURCE.  */
 #if defined(HAVE_CANONICALIZE_FILE_NAME) \
@@ -121,6 +122,16 @@ lrealpath (filename)
 	return ret;
       }
   }
+#endif
+
+#ifdef __amigaos__
+  /* Special case for AmigaOS 4:
+     Here readlink actually works as a realpath, so try using it. */
+  {
+    char buf[MAXPATHLEN];
+    if (readlink (filename, buf, sizeof buf) >= 0)
+      return strdup (buf);
+  }  
 #endif
 
   /* This system is a lost cause, just duplicate the filename.  */
Index: libiberty/make-relative-prefix.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/make-relative-prefix.c,v
retrieving revision 1.4
diff -u -p -r1.4 make-relative-prefix.c
--- libiberty/make-relative-prefix.c	20 Feb 2003 22:10:58 -0000	1.4
+++ libiberty/make-relative-prefix.c	7 Oct 2003 20:53:24 -0000
@@ -82,8 +82,14 @@ relative prefix can be found, return @co
 #    define DIR_SEPARATOR_2 '\\'
 #  endif
 #  define PATH_SEPARATOR ';'
-#else
-#  define PATH_SEPARATOR ':'
+#endif
+
+#ifdef __amigaos__
+#  ifndef DIR_SEPARATOR_2 
+#    define DIR_SEPARATOR_2 ':'
+#  endif
+#  define PATH_SEPARATOR ';'
+#  define DIR_UP ""
 #endif
 
 #ifndef DIR_SEPARATOR_2
@@ -93,7 +99,13 @@ relative prefix can be found, return @co
 	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
 #endif
 
-#define DIR_UP ".."
+#ifndef PATH_SEPARATOR
+#  define PATH_SEPARATOR ':'
+#endif
+
+#ifndef DIR_UP
+#  define DIR_UP ".."
+#endif
 
 static char *save_string PARAMS ((const char *, int));
 static char **split_directories	PARAMS ((const char *, int *));
@@ -241,6 +253,7 @@ make_relative_prefix (progname, bin_pref
      of the directories specified in the PATH environment variable.  */
   if (lbasename (progname) == progname)
     {
+#ifndef __amigaos__
       char *temp;
 
       temp = getenv ("PATH");
@@ -294,6 +307,13 @@ make_relative_prefix (progname, bin_pref
 		endp++;
 	    }
 	}
+#else /* __amigaos__ */
+      /* On AmigaOS there is PROGDIR:, so no need to look... */
+      char * nstore = (char *) alloca (strlen (progname) + 9);
+      strcpy (nstore, "PROGDIR:");
+      strcat (nstore, progname);
+      progname = nstore;
+#endif /* __amigaos__ */
     }
 
   full_progname = lrealpath (progname);
Index: libiberty/make-temp-file.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/make-temp-file.c,v
retrieving revision 1.5
diff -u -p -r1.5 make-temp-file.c
--- libiberty/make-temp-file.c	17 Oct 2001 21:15:41 -0000	1.5
+++ libiberty/make-temp-file.c	7 Oct 2003 20:53:24 -0000
@@ -50,6 +50,26 @@ extern int mkstemps PARAMS ((char *, int
 #define DIR_SEPARATOR '/'
 #endif
 
+#if defined (_WIN32) || defined (__MSDOS__) \
+    || defined (__DJGPP__) || defined (__OS2__)
+#  ifndef DIR_SEPARATOR_2
+#    define DIR_SEPARATOR_2 '\\'
+#  endif
+#endif
+
+#ifdef __amigaos__
+#  ifndef DIR_SEPARATOR_2 
+#    define DIR_SEPARATOR_2 ':'
+#  endif
+#endif
+
+#ifndef DIR_SEPARATOR_2
+#  define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else
+#  define IS_DIR_SEPARATOR(ch) \
+	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif
+
 /* Name of temporary file.
    mktemp requires 6 trailing X's.  */
 #define TEMP_FILE "ccXXXXXX"
@@ -75,11 +95,13 @@ try (dir, base)
   return 0;
 }
 
+#ifndef __amigaos__
 static const char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 };
 static const char usrtmp[] =
 { DIR_SEPARATOR, 'u', 's', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 };
 static const char vartmp[] =
 { DIR_SEPARATOR, 'v', 'a', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 };
+#endif /* __amigaos__ */
 
 static char *memoized_tmpdir;
 
@@ -112,10 +134,15 @@ choose_tmpdir ()
   base = try (P_tmpdir, base);
 #endif
 
+#ifndef __amigaos__
   /* Try /var/tmp, /usr/tmp, then /tmp.  */
   base = try (vartmp, base);
   base = try (usrtmp, base);
   base = try (tmp, base);
+#else /* __amigaos__ */
+  /* Try T: */
+  base = try ("T:", base);
+#endif /* __amigaos__ */
  
   /* If all else fails, use the current directory!  */
   if (base == 0)
@@ -126,8 +153,16 @@ choose_tmpdir ()
   len = strlen (base);
   tmpdir = xmalloc (len + 2);
   strcpy (tmpdir, base);
-  tmpdir[len] = DIR_SEPARATOR;
-  tmpdir[len+1] = '\0';
+
+  /* Don't add DIR_SEPARATOR if base already ends with a dir separator,
+     it's unneeded and can cause ill effects on e.g. AmigaOS.  */
+  if (IS_DIR_SEPARATOR(base[len-1]))
+    tmpdir[len] = '\0';
+  else
+    {
+      tmpdir[len] = DIR_SEPARATOR;
+      tmpdir[len+1] = '\0';
+    }
 
   memoized_tmpdir = tmpdir;
   return tmpdir;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]