fixinc's gen-machine.h

Bruce Korb bkorb@sco.COM
Wed Feb 2 08:24:00 GMT 2000


Hi Zack,

On reflection, I don't really like files that
match *.h to be shell scripts.  This patch
will eliminate the gen-machine.h file entirely
and put it in the genfixes script, since I
use it for make targets already anyway.
Please sanity check and I'll apply tomorrow.

Bruce
	* fixinc/genfixes(machname.h):
	Move the functionality from gen-machine.h into this file.
	UNdef MN_NAME_PAT if there are no names to change.
	Also, be a little kinder when AutoGen is not present.

	* fixinc/Makefile.in(machname.h):
	Change the generation rule to use genfixes.

	* fixinc/fixfixes.c(machine_name):
	machine_name_fix's functionality now dependent upon whether
	MN_NAME_PAT is defined.

	* fixinc/fixtests.c(machine_name):
	ditto.

	* fixinc/fixlib.c(mn_get_regexps): conditional on definition
	of MN_NAME_PAT.

	* fixinc/fixlib.h(mn_get_regexps):
	ditto

	* fixinc/gen-machine.h: DELETED

Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/Makefile.in,v
retrieving revision 1.15
diff -u -r1.15 Makefile.in
--- Makefile.in	2000/02/01 23:51:38	1.15
+++ Makefile.in	2000/02/02 16:00:53
@@ -139,5 +139,4 @@
 	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
 
 machname.h: ../specs
-	$(SHELL) $(srcdir)/gen-machname.h < ../specs > machname.T
-	mv -f machname.T machname.h
+	$(SHELL) $(srcdir)/genfixes machname.h
Index: fixfixes.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixfixes.c,v
retrieving revision 1.11
diff -u -r1.11 fixfixes.c
--- fixfixes.c	2000/02/01 23:51:38	1.11
+++ fixfixes.c	2000/02/02 16:00:54
@@ -560,16 +560,16 @@
 
 FIX_PROC_HEAD( machine_name_fix )
 {
+#ifndef MN_NAME_PAT
+  fputs( "The target machine has no needed machine name fixes\n", stderr );
+#else
   regmatch_t match[2];
   char *line, *base, *limit, *p, *q;
   regex_t *label_re, *name_re;
   char scratch[SCRATCHSZ];
   size_t len;
 
-  if (mn_get_regexps (&label_re, &name_re, "machine_name_fix"))
-    /* This platform doesn't need this fix.  We can only get here if
-       someone is running fixfixes by hand, but let's be polite.  */
-    goto done;
+  mn_get_regexps (&label_re, &name_re, "machine_name_fix");
 
   scratch[0] = '_';
   scratch[1] = '_';
@@ -647,6 +647,7 @@
 	}
     }
  done:
+#endif
   fputs (text, stdout);
 }
 
Index: fixlib.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixlib.c,v
retrieving revision 1.8
diff -u -r1.8 fixlib.c
--- fixlib.c	2000/02/01 23:51:38	1.8
+++ fixlib.c	2000/02/02 16:00:54
@@ -181,7 +181,7 @@
    Helper routine and data for the machine_name test and fix.
    machname.h is created by black magic in the Makefile.  */
 
-#include "machname.h"
+#ifdef MN_NAME_PAT
 
 tSCC mn_label_pat[] = "^[ \t]*#[ \t]*(if|ifdef|ifndef)[ \t]+";
 static regex_t mn_label_re;
@@ -191,16 +191,12 @@
 
 static int mn_compiled = 0;
 
-int
+void
 mn_get_regexps( label_re, name_re, who )
      regex_t **label_re;
      regex_t **name_re;
      tCC *who;
 {
-  /* Maybe we don't need to do this fix at all?  */
-  if (mn_name_pat[0] == '\0')
-    return 1;
-
   if (! mn_compiled)
     {
       compile_re (mn_label_pat, &mn_label_re, 1, "label pattern", who);
@@ -209,5 +205,5 @@
     }
   *label_re = &mn_label_re;
   *name_re = &mn_name_re;
-  return 0;
 }
+#endif
Index: fixtests.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixtests.c,v
retrieving revision 1.12
diff -u -r1.12 fixtests.c
--- fixtests.c	2000/02/01 23:51:38	1.12
+++ fixtests.c	2000/02/02 16:00:54
@@ -271,12 +271,14 @@
 
 TEST_FOR_FIX_PROC_HEAD( machine_name_test )
 {
+#ifndef MN_NAME_PAT
+  return SKIP_FIX;
+#else
   regex_t *label_re, *name_re;
   regmatch_t match[2];
   tCC *base, *limit;
 
-  if (mn_get_regexps(&label_re, &name_re, "machine_name_test"))
-    return SKIP_FIX;
+  mn_get_regexps(&label_re, &name_re, "machine_name_test");
 
   for (base = text;
        regexec (label_re, base, 2, match, 0) == 0;
@@ -314,6 +316,7 @@
       /* Otherwise, keep looking... */
     }
   return SKIP_FIX;
+#endif
 }
 
 
Index: genfixes
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/genfixes,v
retrieving revision 1.6
diff -u -r1.6 genfixes
--- genfixes	1999/12/17 21:49:30	1.6
+++ genfixes	2000/02/02 16:00:54
@@ -1,15 +1,25 @@
 #! /bin/sh
 
-if (autogen --help > /dev/null 2>&1) ; then : ; else
-  echo "AutoGen does not appear to be correctly installed."
-  echo "Please download and install:"
-  echo "   ftp://sourceware.cygnus.com/pub/egcs/infrastructure/autogen.tar.gz "
-  exit 1
-fi
+# Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+# This file is part of GNU CC.
+
+# GNU CC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# GNU CC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# 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, 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
 
 SHELL=/bin/sh
 export SHELL
-AG="autogen"
 if [ $# -eq 0 ] ; then
   not_done=false
 else
@@ -37,8 +47,9 @@
   '-?' )
     echo "USAGE: gendefs [ -D<def-name> ... ] [ <output-name> ]"
     echo "WHERE: '<def-name>' specifies a #define test name from inclhack.def"
-    echo "  and  '<output-name>' is one of:  inclhack.sh fixincl.x fixincl.sh"
-    echo "The default is to produce all three outputs."
+    echo "  and  '<output-name>' is one of:"
+    echo "       inclhack.sh fixincl.x fixincl.sh machine.h"
+    echo "The default is to produce the first three outputs."
     exit 0
     ;;
 
@@ -49,33 +60,82 @@
 done
 
 if [ $# -eq 0 ] ; then
-  echo AutoGen-ing inclhack.sh
-  $AG inclhack.def
-
-  echo AutoGen-ing fixincl.x
-  $AG -T fixincl.tpl -b fixincl inclhack.def
-
-  echo AutoGen-ing fixincl.sh
-  $AG -DPROGRAM=1 -b fixincl inclhack.def
+  ${SHELL} $0 $AG inclhack.sh || exit 1
+  ${SHELL} $0 $AG fixincl.x   || exit 1
+  ${SHELL} $0 $AG fixincl.sh  || exit 1
   exit 0
 fi
 
+AG="autogen $AG"
 set -e
 
 case "$1" in
 inclhack.sh )
-  echo AutoGen-ing inclhack.sh
-  $AG inclhack.def
+  if (autogen --help > /dev/null 2>&1)
+  then
+    echo AutoGen-ing inclhack.sh
+    $AG inclhack.def
+  else
+    echo "AutoGen does not appear to be correctly installed."
+    echo "Please download and install:"
+    echo "   ftp://sourceware.cygnus.com/pub/egcs/infrastructure/autogen.tar.gz "
+    touch inclhack.sh
+  fi
   ;;
 
 fixincl.x )
-  echo AutoGen-ing fixincl.x
-  $AG -T fixincl.tpl -b fixincl inclhack.def
+  if (autogen --help > /dev/null 2>&1)
+  then
+    echo AutoGen-ing fixincl.x
+    $AG -T fixincl.tpl -b fixincl inclhack.def
+  else
+    echo "AutoGen does not appear to be correctly installed."
+    echo "Please download and install:"
+    echo "   ftp://sourceware.cygnus.com/pub/egcs/infrastructure/autogen.tar.gz "
+    touch fixincl.x
+  fi
   ;;
 
 fixincl.sh )
-  echo AutoGen-ing fixincl.sh
-  $AG -DPROGRAM=1 -b fixincl inclhack.def
+  if (autogen --help > /dev/null 2>&1)
+  then
+    echo AutoGen-ing fixincl.sh
+    $AG -DPROGRAM=1 -b fixincl inclhack.def
+  else
+    echo "AutoGen does not appear to be correctly installed."
+    echo "Please download and install:"
+    echo "   ftp://sourceware.cygnus.com/pub/egcs/infrastructure/autogen.tar.gz "
+    touch fixincl.sh
+  fi
+  ;;
+
+machname.h )
+  # This script extracts from the specs file all the predefined macros
+  # that are not in the C89 reserved namespace (the reserved namespace
+  # is all identifiers beginnning with two underscores or one underscore
+  # followed by a capital letter).  The specs file is on standard input.
+  # A #define for a regular expression to find any of those macros in a
+  # header file is written to standard output.
+
+  # Note dependency on ASCII. \040 = space, \011 = tab, \012 = newline.
+  # tr ' ' '\n' is, alas, not portable.
+
+  tr -s '\040\011' '\012\012' < ../specs |
+    sed -n 's/^.*-D\([a-zA-Z_][a-zA-Z0-9_]*\).*$/\1/p' |
+    sort -u > mn.T
+
+  if grep -v '^_[_A-Z]' mn.T > mn.U
+  then
+    echo "Forbidden identifiers: `tr '\012' ' ' <mn.U`" >&2
+    sed 's/^/\\\\</; s/$/\\\\>/' <mn.U | tr '\012' '|' > mn.V
+    echo '' >>mn.V
+    sed 's/^/#define MN_NAME_PAT "/; s/|$/"/' < mn.V > machname.T
+  else
+    echo "No forbidden identifiers defined by this target" >&2
+    echo '#undef MN_NAME_PAT' > machname.T
+  fi
+  rm -f mn.[TUV]
+  mv -f machname.T machname.h
   ;;
 
 * )
Index: fixlib.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixlib.h,v
retrieving revision 1.7
diff -u -r1.7 fixlib.h
--- fixlib.h	2000/02/01 23:51:38	1.7
+++ fixlib.h	2000/02/02 16:08:26
@@ -30,6 +30,7 @@
 #include "system.h"
 
 #include "gnu-regex.h"
+#include "machname.h"
 
 #ifndef STDIN_FILENO
 # define STDIN_FILENO   0
@@ -99,6 +100,8 @@
 t_bool is_cxx_header  _P_(( tCC* filename, tCC* filetext ));
 void   compile_re     _P_(( tCC* pat, regex_t* re, int match,
 			    tCC *e1, tCC *e2 ));
-int    mn_get_regexps _P_(( regex_t** label_re, regex_t** name_re,
+#ifdef MN_NAME_PAT
+void   mn_get_regexps _P_(( regex_t** label_re, regex_t** name_re,
 			    tCC *who ));
+#endif
 #endif /* FIXINCLUDES_FIXLIB_H */


More information about the Gcc-patches mailing list