OSDN Git Service

* rtl.h (addr_diff_vec_flags): New typedef.
[pf3gnuchains/gcc-fork.git] / gcc / fixinc.svr4
index 55049a9..46e07ce 100755 (executable)
@@ -1,9 +1,8 @@
 #! /bin/sh
-#
-#   fixinc.svr4  --  Install modified versions of certain ANSI-incompatible
-#   native System V Release 4 system include files.
-#
-#   Written by Ron Guilmette (rfg@ncd.com).
+# Install modified versions of certain ANSI-incompatible
+# native System V Release 4 system include files.
+# Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
+# Contributed by Ron Guilmette (rfg@monkeys.com).
 #
 # This file is part of GNU CC.
 # 
@@ -19,7 +18,8 @@
 # 
 # You should have received a copy of the GNU General Public License
 # along with GNU CC; see the file COPYING.  If not, write to
-# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+# the Free Software Foundation, 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
 #
 #      This script munges the native include files provided with System V
 #      Release 4 systems so as to remove things which are violations of the
@@ -31,9 +31,6 @@
 #
 #      See README-fixinc for more information.
 
-# Directory where gcc sources (and sometimes special include files) live.
-SRCDIR=${3-${SRCDIR-.}}
-
 # Directory containing the original header files.
 INPUT=${2-${INPUT-/usr/include}}
 
@@ -76,7 +73,7 @@ fi
 echo 'Making directories:'
 cd ${INPUT}
 if $LINKS; then
-  files=`ls -LR | sed -n s/:$//p`
+  files=`find . -follow -type d -print 2>/dev/null | sed '/^.$/d'`
 else
   files=`find . -type d -print | sed '/^.$/d'`
 fi
@@ -101,6 +98,7 @@ if $LINKS; then
       # In case $dest is relative, get to $file's dir first.
       cd ${INPUT}
       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
+      rwd=`pwd`
       # Check that the target directory exists.
       # Redirections changed to avoid bug in sh on Ultrix.
       (cd $dest) > /dev/null 2>&1
@@ -110,12 +108,25 @@ if $LINKS; then
        x=`pwd`
        # If link leads back into ${INPUT},
        # make a similar link here.
-       if expr $x : "${INPUT}/.*" > /dev/null; then
+        if expr "$dest" : '[^/][^/]*' >/dev/null && [ ! -h $dest ]; then
+          echo $file '->'  $dest': Making link'
+          rm -fr ${LIB}/$file > /dev/null 2>&1
+          ln -s $dest ${LIB}/$file > /dev/null 2>&1
+       elif expr $x : "${INPUT}/.*" > /dev/null; then
          # Y gets the actual target dir name, relative to ${INPUT}.
          y=`echo $x | sed -n "s&${INPUT}/&&p"`
          # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
          dots=`echo "$file" |
-               sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
+           sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
+         echo $file '->' $dots$y ': Making link'
+         rm -fr ${LIB}/$file > /dev/null 2>&1
+         ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
+       elif expr $x : "${rwd}/.*" > /dev/null; then
+         # Y gets the actual target dir name, relative to the directory where the link is.
+         y=`echo $x | sed -n "s&${rwd}/&&p"`
+         # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
+         dots=`echo "$file" |
+           sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
          echo $file '->' $dots$y ': Making link'
          rm -fr ${LIB}/$file > /dev/null 2>&1
          ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
@@ -177,6 +188,8 @@ while [ $# != 0 ]; do
          /#[a-z]*if.*[  (]m68k/                s/\([^_]\)m68k/\1__m68k__/g
          /#[a-z]*if.*[  (]__i386\([^_]\)/      s/__i386/__i386__/g
          /#[a-z]*if.*[  (]i386/                s/\([^_]\)i386/\1__i386__/g
+         /#[a-z]*if.*[  (!]__i860\([^_]\)/     s/__i860/__i860__/g
+         /#[a-z]*if.*[  (!]i860/               s/\([^_]\)i860/\1__i860__/g
          /#[a-z]*if.*[  (]sparc/       s/\([^_]\)sparc/\1__sparc__/g
          /#[a-z]*if.*[  (]mc68000/     s/\([^_]\)mc68000/\1__mc68000__/g
          /#[a-z]*if.*[  (]vax/         s/\([^_]\)vax/\1__vax__/g
@@ -188,7 +201,10 @@ while [ $# != 0 ]; do
          s/__STDC__[   ][      ]*==[   ][      ]*0/!defined (__STRICT_ANSI__)/g
          s/__STDC__[   ][      ]*==[   ][      ]*1/defined (__STRICT_ANSI__)/g
          s/__STDC__[   ][      ]*!=[   ][      ]*0/defined (__STRICT_ANSI__)/g
+         s/__STDC__[   ][      ]*!=[   ][      ]*1/!defined (__STRICT_ANSI__)/g
          s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
+         s/__STDC__ - 0 == 1/defined (__STRICT_ANSI__)/g
+         /^typedef[    ][      ]*[unsigned     ]*long[         ][      ]*[u_]*longlong_t;/s/long/long long/
        ' $2/$file > $2/$file.sed
        mv $2/$file.sed $2/$file
        if cmp $file $2/$file >/dev/null 2>&1; then
@@ -201,6 +217,44 @@ while [ $# != 0 ]; do
   shift; shift
 done
 
+# Install the proper definition of the three standard types in header files
+# that they come from.
+for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
+  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
+    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
+    chmod +w ${LIB}/$file 2>/dev/null
+    chmod a+r ${LIB}/$file 2>/dev/null
+  fi
+
+  if [ -r ${LIB}/$file ]; then
+    echo Fixing size_t, ptrdiff_t and wchar_t in $file
+    sed \
+      -e '/typedef[    ][      ]*[a-z_][       a-z_]*[         ]size_t/i\
+#ifndef __SIZE_TYPE__\
+#define __SIZE_TYPE__ long unsigned int\
+#endif
+' \
+      -e 's/typedef[   ][      ]*[a-z_][       a-z_]*[         ]size_t/typedef __SIZE_TYPE__ size_t/' \
+      -e '/typedef[    ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/i\
+#ifndef __PTRDIFF_TYPE__\
+#define __PTRDIFF_TYPE__ long int\
+#endif
+' \
+      -e 's/typedef[   ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
+      -e '/typedef[    ][      ]*[a-z_][       a-z_]*[         ]wchar_t/i\
+#ifndef __WCHAR_TYPE__\
+#define __WCHAR_TYPE__ int\
+#endif
+' \
+      -e 's/typedef[   ][      ]*[a-z_][       a-z_]*[         ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
+      ${LIB}/$file > ${LIB}/${file}.sed
+    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
+    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
+      rm ${LIB}/$file
+    fi
+  fi
+done
+
 # Fix first broken decl of getcwd present on some svr4 systems.
 
 file=stdlib.h
@@ -389,8 +443,7 @@ if [ \! -z "$file_to_fix" ]; then
   chmod +w /tmp/$base
   sed -e '/^extern caddr_t mmap();$/c\
 #ifdef __STDC__\
-extern caddr_t mmap (caddr_t addr, size_t len, int prot, int flags,\
-                     int fd, off_t off);\
+extern caddr_t mmap (caddr_t, size_t, int, int, int, off_t);\
 #else /* !defined(__STDC__) */\
 extern caddr_t mmap ();\
 #endif /* !defined(__STDC__) */' /tmp/$base > /tmp/$base.sed
@@ -437,14 +490,16 @@ else
 static\
 #else\
 extern\
-#endif'\
+#endif
+'\
   -e 's/extern \(int ftw(const.*\)$/\1/' \
   -e '/^extern int nftw/i\
 #if defined(_STYPES)\
 static\
 #else\
 extern\
-#endif'\
+#endif
+'\
   -e 's/extern \(int nftw.*\)$/\1/' \
   -e '/^extern int ftw(),/c\
 #if !defined(_STYPES)\
@@ -470,6 +525,38 @@ extern\
   rm -f /tmp/$base /tmp/$base.sed
 fi
 
+# Avoid the definition of the bool type in the Solaris 2.x curses.h when using
+# g++, since it's now an official type in the C++ language.
+file=curses.h
+base=`basename $file`
+if [ -r ${LIB}/$file ]; then
+  file_to_fix=${LIB}/$file
+else
+  if [ -r ${INPUT}/$file ]; then
+    file_to_fix=${INPUT}/$file
+  else
+    file_to_fix=""
+  fi
+fi
+
+if [ \! -z "$file_to_fix" ]; then
+  echo Checking $file_to_fix
+  cp $file_to_fix /tmp/$base
+  chmod +w /tmp/$base
+  sed -e 's,^typedef[  ]char[  ]bool;$,#ifndef __cplusplus\
+typedef        char bool;\
+#endif /* !defined __cplusplus */,' /tmp/$base > /tmp/$base.sed
+  if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
+    true
+  else
+    echo Fixed $file_to_fix
+    rm -f ${LIB}/$file
+    cp /tmp/$base.sed ${LIB}/$file
+    chmod a+r ${LIB}/$file
+  fi
+  rm -f /tmp/$base /tmp/$base.sed
+fi
+
 # Add a `static' declaration of `getrnge' into <regexp.h>.
 
 # Don't do this if there is already a `static void getrnge' declaration
@@ -939,32 +1026,35 @@ if [ \! -z "$file_to_fix" ]; then
 fi
 
 # Conditionalize some of <netinet/in.h> on _KERNEL being defined.
-
-file=netinet/in.h
-base=`basename $file`
-if [ -r ${LIB}/$file ]; then
-  file_to_fix=${LIB}/$file
-else
-  if [ -r ${INPUT}/$file ]; then
-    file_to_fix=${INPUT}/$file
-  else
-    file_to_fix=""
-  fi
-fi
-if [ \! -z "$file_to_fix" ]; then
-  echo Checking $file_to_fix
-  if grep _KERNEL $file_to_fix > /dev/null; then
-    true
-  else
-    sed -e '/#ifdef INKERNEL/i\
-#ifdef _KERNEL' \
-    -e '/#endif[       ]*\/\* INKERNEL \*\//a\
-#endif /* _KERNEL */' \
-    $file_to_fix > ${LIB}/${file}.sed
-    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
-    echo Fixed $file_to_fix
-  fi
-fi
+# This has been taken out because it breaks on some versions of
+# DYNIX/ptx, and it does not seem to do much good on any system.
+# file=netinet/in.h
+# base=`basename $file`
+# if [ -r ${LIB}/$file ]; then
+#   file_to_fix=${LIB}/$file
+# else
+#   if [ -r ${INPUT}/$file ]; then
+#     file_to_fix=${INPUT}/$file
+#   else
+#     file_to_fix=""
+#   fi
+# fi
+# if [ \! -z "$file_to_fix" ]; then
+#   echo Checking $file_to_fix
+#   if grep _KERNEL $file_to_fix > /dev/null; then
+#     true
+#   else
+#     sed -e '/#ifdef INKERNEL/i\
+# #ifdef _KERNEL
+# ' \
+#     -e '/#endif[     ]*\/\* INKERNEL \*\//a\
+# #endif /* _KERNEL */
+# ' \
+#     $file_to_fix > ${LIB}/${file}.sed
+#     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
+#     echo Fixed $file_to_fix
+#   fi
+# fi
 
 # Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
 
@@ -985,10 +1075,12 @@ if [ \! -z "$file_to_fix" ]; then
     true
   else
     sed -e '/# ifdef   __STDC__/i\
-#   if !defined (__GNUC__) && !defined (__GNUG__)' \
+#   if !defined (__GNUC__) && !defined (__GNUG__)
+' \
     -e '/#             include <sys\/byteorder.h>/s/           /   /'\
     -e '/#   include   <sys\/byteorder.h>/i\
-#   endif /* !defined (__GNUC__) && !defined (__GNUG__) */'\
+#   endif /* !defined (__GNUC__) && !defined (__GNUG__) */
+'\
     $file_to_fix > ${LIB}/${file}.sed
     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
     echo Fixed $file_to_fix
@@ -1127,28 +1219,28 @@ if [ \! -z "$file_to_fix" ]; then
   echo Checking $file_to_fix
   cp $file_to_fix /tmp/$base
   chmod +w /tmp/$base
-  sed -e '/^stat(/{
+  sed -e '/^stat([     ]*[^c]/{
 N
 N
 s/(.*)\n/( /
 s/;\n/, /
 s/;$/)/
 }' \
-  -e '/^lstat(/{
+  -e '/^lstat([        ]*[^c]/{
 N
 N
 s/(.*)\n/( /
 s/;\n/, /
 s/;$/)/
 }' \
-  -e '/^fstat(/{
+  -e '/^fstat([        ]*[^i]/{
 N
 N
 s/(.*)\n/( /
 s/;\n/, /
 s/;$/)/
 }' \
-  -e '/^mknod(/{
+  -e '/^mknod([        ]*[^c]/{
 N
 N
 N
@@ -1264,29 +1356,41 @@ fi
 if [ \! -z "$file_to_fix" ]; then
   echo Checking $file_to_fix
   sed -e '/[   ]FLT_MIN[       ]/i\
-#ifndef FLT_MIN'\
+#ifndef FLT_MIN
+'\
       -e '/[   ]FLT_MIN[       ]/a\
-#endif'\
+#endif
+'\
       -e '/[   ]FLT_MAX[       ]/i\
-#ifndef FLT_MAX'\
+#ifndef FLT_MAX
+'\
       -e '/[   ]FLT_MAX[       ]/a\
-#endif'\
+#endif
+'\
       -e '/[   ]FLT_DIG[       ]/i\
-#ifndef FLT_DIG'\
+#ifndef FLT_DIG
+'\
       -e '/[   ]FLT_DIG[       ]/a\
-#endif'\
+#endif
+'\
       -e '/[   ]DBL_MIN[       ]/i\
-#ifndef DBL_MIN'\
+#ifndef DBL_MIN
+'\
       -e '/[   ]DBL_MIN[       ]/a\
-#endif'\
+#endif
+'\
       -e '/[   ]DBL_MAX[       ]/i\
-#ifndef DBL_MAX'\
+#ifndef DBL_MAX
+'\
       -e '/[   ]DBL_MAX[       ]/a\
-#endif'\
+#endif
+'\
       -e '/[   ]DBL_DIG[       ]/i\
-#ifndef DBL_DIG'\
+#ifndef DBL_DIG
+'\
       -e '/[   ]DBL_DIG[       ]/a\
-#endif' $file_to_fix > /tmp/$base
+#endif
+' $file_to_fix > /tmp/$base
   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
     true
   else
@@ -1320,6 +1424,109 @@ EOF
   chmod a+r ${LIB}/$file
 fi
 
+# In math.h, put #ifndefs around things that might be defined in a gcc
+# specific math-*.h file.
+
+file=math.h
+base=`basename $file`
+if [ -r ${LIB}/$file ]; then
+  file_to_fix=${LIB}/$file
+else
+  if [ -r ${INPUT}/$file ]; then
+    file_to_fix=${INPUT}/$file
+  else
+    file_to_fix=""
+  fi
+fi
+if [ \! -z "$file_to_fix" ]; then
+  echo Checking $file_to_fix
+  sed -e '/define[     ]HUGE_VAL[      ]/i\
+#ifndef HUGE_VAL
+'\
+      -e '/define[     ]HUGE_VAL[      ]/a\
+#endif
+' $file_to_fix > /tmp/$base
+  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
+    true
+  else
+    echo Fixed $file_to_fix
+    rm -f ${LIB}/$file
+    cp /tmp/$base ${LIB}/$file
+    chmod a+r ${LIB}/$file
+  fi
+  rm -f /tmp/$base
+fi
+
+# Solaris math.h and floatingpoint.h define __P without protection,
+# which conflicts with the fixproto definition.  The fixproto
+# definition and the Solaris definition are used the same way.
+for file in math.h floatingpoint.h; do
+  base=`basename $file`
+  if [ -r ${LIB}/$file ]; then
+    file_to_fix=${LIB}/$file
+  else
+    if [ -r ${INPUT}/$file ]; then
+      file_to_fix=${INPUT}/$file
+    else
+      file_to_fix=""
+    fi
+  fi
+  if [ \! -z "$file_to_fix" ]; then
+    echo Checking $file_to_fix
+    sed -e '/^#define[         ]*__P/i\
+#ifndef __P
+'\
+        -e '/^#define[         ]*__P/a\
+#endif
+' $file_to_fix > /tmp/$base
+    if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
+      true
+    else
+      echo Fixed $file_to_fix
+      rm -f ${LIB}/$file
+      cp /tmp/$base ${LIB}/$file
+      chmod a+r ${LIB}/$file
+    fi
+   rm -f /tmp/$base
+  fi
+done
+
+# The Solaris math.h defines struct exception, which conflicts with
+# the class exception defined in the C++ file std/stdexcept.h.  We
+# redefine it to __math_exception.  This is not a great fix, but I
+# haven't been able to think of anything better.
+file=math.h
+base=`basename $file`
+if [ -r ${LIB}/$file ]; then
+  file_to_fix=${LIB}/$file
+else
+  if [ -r ${INPUT}/$file ]; then
+    file_to_fix=${INPUT}/$file
+  else
+    file_to_fix=""
+  fi
+fi
+if [ \! -z "$file_to_fix" ]; then
+  echo Checking $file_to_fix
+  sed -e '/struct exception/i\
+#ifdef __cplusplus\
+#define exception __math_exception\
+#endif'\
+      -e '/struct exception/a\
+#ifdef __cplusplus\
+#undef exception\
+#endif' $file_to_fix > /tmp/$base
+  if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
+    true
+  else
+    echo Fixed $file_to_fix
+    rm -f ${LIB}/$file
+    cp /tmp/$base ${LIB}/$file
+    chmod a+r ${LIB}/$file
+  fi
+  rm -f /tmp/$base
+fi
+
 echo 'Removing unneeded directories:'
 cd $LIB
 files=`find . -type d -print | sort -r`
@@ -1334,7 +1541,7 @@ if $LINKS; then
   for file in $files; do
     dest=`ls -ld $file | sed -n 's/.*-> //p'`
     if expr "$dest" : '[^/].*' > /dev/null; then    
-      target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
+      target=${LIB}/`echo $file | sed "s|[^/]*\$|$dest|"`
       if [ -f $target ]; then
         ln -s $dest ${LIB}/$file >/dev/null 2>&1
       fi
@@ -1345,8 +1552,175 @@ fi
 cd ${ORIG_DIR}
 
 echo 'Replacing <sys/byteorder.h>'
+if [ \! -d $LIB/sys ]; then
+  mkdir $LIB/sys
+fi
 rm -f ${LIB}/sys/byteorder.h
-cp ${SRCDIR}/byteorder.h ${LIB}/sys/byteorder.h
+cat <<'__EOF__' >${LIB}/sys/byteorder.h
+#ifndef _SYS_BYTEORDER_H
+#define _SYS_BYTEORDER_H
+
+/* Functions to convert `short' and `long' quantities from host byte order
+   to (internet) network byte order (i.e. big-endian).
+
+   Written by Ron Guilmette (rfg@ncd.com).
+
+   This isn't actually used by GCC.  It is installed by fixinc.svr4.
+
+   For big-endian machines these functions are essentially no-ops.
+
+   For little-endian machines, we define the functions using specialized
+   asm sequences in cases where doing so yields better code (e.g. i386).  */
+
+#if !defined (__GNUC__) && !defined (__GNUG__)
+#error You lose!  This file is only useful with GNU compilers.
+#endif
+
+#ifndef __BYTE_ORDER__
+/* Byte order defines.  These are as defined on UnixWare 1.1, but with
+   double underscores added at the front and back.  */
+#define __LITTLE_ENDIAN__   1234
+#define __BIG_ENDIAN__      4321
+#define __PDP_ENDIAN__      3412
+#endif
+
+#ifdef __STDC__
+static __inline__ unsigned long htonl (unsigned long);
+static __inline__ unsigned short htons (unsigned int);
+static __inline__ unsigned long ntohl (unsigned long);
+static __inline__ unsigned short ntohs (unsigned int);
+#endif /* defined (__STDC__) */
+
+#if defined (__i386__)
+
+#ifndef __BYTE_ORDER__
+#define __BYTE_ORDER__ __LITTLE_ENDIAN__
+#endif
+
+/* Convert a host long to a network long.  */
+
+/* We must use a new-style function definition, so that this will also
+   be valid for C++.  */
+static __inline__ unsigned long
+htonl (unsigned long __arg)
+{
+  register unsigned long __result;
+
+  __asm__ ("xchg%B0 %b0,%h0\n\
+       ror%L0 $16,%0\n\
+       xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
+  return __result;
+}
+
+/* Convert a host short to a network short.  */
+
+static __inline__ unsigned short
+htons (unsigned int __arg)
+{
+  register unsigned short __result;
+
+  __asm__ ("xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
+  return __result;
+}
+
+#elif ((defined (__i860__) && !defined (__i860_big_endian__))  \
+       || defined (__ns32k__) || defined (__vax__)             \
+       || defined (__spur__) || defined (__arm__))
+
+#ifndef __BYTE_ORDER__
+#define __BYTE_ORDER__ __LITTLE_ENDIAN__
+#endif
+
+/* For other little-endian machines, using C code is just as efficient as
+   using assembly code.  */
+
+/* Convert a host long to a network long.  */
+
+static __inline__ unsigned long
+htonl (unsigned long __arg)
+{
+  register unsigned long __result;
+
+  __result = (__arg >> 24) & 0x000000ff;
+  __result |= (__arg >> 8) & 0x0000ff00;
+  __result |= (__arg << 8) & 0x00ff0000;
+  __result |= (__arg << 24) & 0xff000000;
+  return __result;
+}
+
+/* Convert a host short to a network short.  */
+
+static __inline__ unsigned short
+htons (unsigned int __arg)
+{
+  register unsigned short __result;
+
+  __result = (__arg << 8) & 0xff00;
+  __result |= (__arg >> 8) & 0x00ff;
+  return __result;
+}
+
+#else /* must be a big-endian machine */
+
+#ifndef __BYTE_ORDER__
+#define __BYTE_ORDER__ __BIG_ENDIAN__
+#endif
+
+/* Convert a host long to a network long.  */
+
+static __inline__ unsigned long
+htonl (unsigned long __arg)
+{
+  return __arg;
+}
+
+/* Convert a host short to a network short.  */
+
+static __inline__ unsigned short
+htons (unsigned int __arg)
+{
+  return __arg;
+}
+
+#endif /* big-endian */
+
+/* Convert a network long to a host long.  */
+
+static __inline__ unsigned long
+ntohl (unsigned long __arg)
+{
+  return htonl (__arg);
+}
+
+/* Convert a network short to a host short.  */
+
+static __inline__ unsigned short
+ntohs (unsigned int __arg)
+{
+  return htons (__arg);
+}
+
+__EOF__
+
+if [ -r ${INPUT}/sys/byteorder.h ]; then
+  if grep BYTE_ORDER ${INPUT}/sys/byteorder.h >/dev/null 2>/dev/null; then
+    cat <<'__EOF__' >>${LIB}/sys/byteorder.h
+#ifndef BYTE_ORDER
+#define LITTLE_ENDIAN __LITTLE_ENDIAN__
+#define BIG_ENDIAN __BIG_ENDIAN__
+#define PDP_ENDIAN __PDP_ENDIAN__
+#define BYTE_ORDER __BYTE_ORDER__
+#endif
+
+__EOF__
+  fi
+fi
+
+cat <<'__EOF__' >>${LIB}/sys/byteorder.h
+#endif /* !defined (_SYS_BYTEORDER_H) */
+__EOF__
+
+chmod a+r ${LIB}/sys/byteorder.h
 
 exit 0