Segher Boessenkool <seg...@kernel.crashing.org> writes:

> Gaius, could you look through the two patches I did to get the build to
> work, see if those are correct or if something better needs to be done?
>
> <https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=28cec96b06d0f35c387cfa4c73e5ea0c9b9a7e47>
> $(subdir) is an absolute path for me, so ../$(subdir) cannot work.

Hi Segher,

ah after more testing the patch will fail on a relative srcdir and the
configure has to be run in the m2 or m2/gm2-libs build directories.
I've pushed some changes onto the gm2 repro at savannah to fix this
which are included below.  Also included are the renaming changes to
getopt you suggested

regards,
Gaius


diff --git a/gcc-versionno/gcc/m2/ChangeLog b/gcc-versionno/gcc/m2/ChangeLog
index eeac1930..e523f307 100644
--- a/gcc-versionno/gcc/m2/ChangeLog
+++ b/gcc-versionno/gcc/m2/ChangeLog
@@ -1,4 +1,23 @@
-2021-06-19      Matthias Klose <d...@ubuntu.com>
+2021-06-21       Gaius Mulley <gaius.mul...@southwales.ac.uk>
+
+       * tools-src/calcpath:  (New file).
+       * Make-lang.in:  (m2/gm2-libs/gm2-libs-host.h) use calcpath
+       to determine the srcdir of the new subdirectory.
+       (m2/gm2config.h) use calcpath
+       to determine the srcdir of the new subdirectory.
+       Fixes an error and based on a patch reported by Segher Boessenkool
+       <seg...@kernel.crashing.org>.
+       * Make-lang.in:  (m2/gm2-libs/gm2-libs-host.h) Restore tabs.
+       * Make-lang.in:  (m2/gm2config.h) Restore tabs.
+       * Make-lang.in:  Replaced getopt.c by cgetopt.c.
+       * gm2-libs/getopt.def:  Renamed gm2-libs/cgetopt.def.
+       * gm2-libs-ch/getopt.c:  Renamed gm2-libs-ch/cgetopt.c.
+       Replaced getopt_ by cgetopt_.
+       Fixes an error reported by Segher Boessenkool
+       <seg...@kernel.crashing.org>.
+       * tools-src/calcpath:  (Corrected header comment).
+
+2021-06-19       Matthias Klose <d...@ubuntu.com>
 
        * Make-lang.in:  introduce parallel linking.
        * Make-lang.in (m2.serial): New target.
diff --git a/gcc-versionno/gcc/m2/Make-lang.in 
b/gcc-versionno/gcc/m2/Make-lang.in
index 58e5312e..298da26f 100644
--- a/gcc-versionno/gcc/m2/Make-lang.in
+++ b/gcc-versionno/gcc/m2/Make-lang.in
@@ -1179,9 +1179,11 @@ m2/gm2-libs-iso/%.o: $(srcdir)/m2/gm2-libs-iso/%.mod
 
 m2/gm2-libs/gm2-libs-host.h:
        echo "Configuring to build libraries using native compiler" ; \
+        NEW_SRCDIR=`${srcdir}/m2/tools-src/calcpath ../../ ${srcdir} 
m2/gm2-libs` ; \
+        export NEW_SRCDIR ; \
         cd m2/gm2-libs ; \
-        $(SHELL) -c '../../$(srcdir)/m2/gm2-libs/config-host \
-               --srcdir=../../$(srcdir)/m2/gm2-libs \
+        $(SHELL) -c '$${NEW_SRCDIR}/config-host \
+               --srcdir=$${NEW_SRCDIR} \
                --target=$(target) \
                --program-suffix=$(exeext)'
 
@@ -1189,15 +1191,21 @@ m2/gm2-libs/gm2-libs-host.h:
 # cross compiler and the ../Makefile.in above appends this to INTERNAL_CFLAGS.
 
 m2/gm2config.h:
+       NEW_SRCDIR=`${srcdir}/m2/tools-src/calcpath ../ ${srcdir} m2` ; \
+        export NEW_SRCDIR ; \
        cd m2 ; \
        if echo $(INTERNAL_CFLAGS) | grep \\-DCROSS_DIRECTORY_STRUCTURE; then \
-            AR=`echo $(AR_FOR_TARGET) | sed -e "s/^ //"` ; \
+            AR=$(echo $(AR_FOR_TARGET) | sed -e "s/^ //") ; \
             export AR ; \
-            RANLIB=`echo $(RANLIB_FOR_TARGET) | sed -e "s/^ //"` ; \
+            RANLIB=$(echo $(RANLIB_FOR_TARGET) | sed -e "s/^ //") ; \
             export RANLIB ; \
-            $(SHELL) -c '../$(srcdir)/m2/configure --srcdir=../$(srcdir)/m2 
--target=$(target) --program-suffix=$(exeext) --includedir=$(SYSTEM_HEADER_DIR) 
--libdir=$(libdir) --libexecdir=$(libexecdir)' ; \
+            $(SHELL) -c '$${NEW_SRCDIR}/configure --srcdir=$${NEW_SRCDIR} \
+                --target=$(target) --program-suffix=$(exeext) \
+                --includedir=$(SYSTEM_HEADER_DIR) --libdir=$(libdir) \
+                --libexecdir=$(libexecdir)' ; \
         else \
-            $(SHELL) -c '../$(srcdir)/m2/configure --srcdir=../$(srcdir)/m2 
--target=$(target) --program-suffix=$(exeext)' ; \
+            $(SHELL) -c '$${NEW_SRCDIR}/configure --srcdir=$(NEW_SRCDIR) \
+                --target=$(target) --program-suffix=$(exeext)' ; \
         fi
 
 $(objdir)/m2/gm2-libs-min/SYSTEM.def: $(GM2_PROG_DEP)
diff --git a/gcc-versionno/gcc/m2/gm2-libs-ch/getopt.c 
b/gcc-versionno/gcc/m2/gm2-libs-ch/cgetopt.c
similarity index 67%
rename from gcc-versionno/gcc/m2/gm2-libs-ch/getopt.c
rename to gcc-versionno/gcc/m2/gm2-libs-ch/cgetopt.c
index 1f483a72..205c0487 100644
--- a/gcc-versionno/gcc/m2/gm2-libs-ch/getopt.c
+++ b/gcc-versionno/gcc/m2/gm2-libs-ch/cgetopt.c
@@ -28,21 +28,21 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 #include "system.h"
 #include "ansi-decl.h"
 
-char *getopt_optarg;
-int getopt_optind;
-int getopt_opterr;
-int getopt_optopt;
+char *cgetopt_optarg;
+int cgetopt_optind;
+int cgetopt_opterr;
+int cgetopt_optopt;
 
 
 char
-getopt_getopt (int argc, char *argv[], char *optstring)
+cgetopt_getopt (int argc, char *argv[], char *optstring)
 {
   char r = getopt (argc, argv, optstring);
 
-  getopt_optarg = optarg;
-  getopt_optind = optind;
-  getopt_opterr = opterr;
-  getopt_optopt = optopt;
+  cgetopt_optarg = optarg;
+  cgetopt_optind = optind;
+  cgetopt_opterr = opterr;
+  cgetopt_optopt = optopt;
 
   if (r == (char)-1)
     return (char)0;
@@ -51,47 +51,47 @@ getopt_getopt (int argc, char *argv[], char *optstring)
 
 
 int
-getopt_getopt_long (int argc, char *argv[], char *optstring, const struct 
option *longopts,
+cgetopt_cgetopt_long (int argc, char *argv[], char *optstring, const struct 
option *longopts,
                     int *longindex)
 {
-  int r = getopt_long (argc, argv, optstring, longopts, longindex);
+  int r = cgetopt_long (argc, argv, optstring, longopts, longindex);
 
-  getopt_optarg = optarg;
-  getopt_optind = optind;
-  getopt_opterr = opterr;
-  getopt_optopt = optopt;
+  cgetopt_optarg = optarg;
+  cgetopt_optind = optind;
+  cgetopt_opterr = opterr;
+  cgetopt_optopt = optopt;
 
   return r;
 }
 
 
 int
-getopt_getopt_long_only (int argc, char *argv[], char *optstring,
+cgetopt_cgetopt_long_only (int argc, char *argv[], char *optstring,
                          const struct option *longopts, int *longindex)
 {
-  int r = getopt_long_only (argc, argv, optstring, longopts, longindex);
+  int r = cgetopt_long_only (argc, argv, optstring, longopts, longindex);
 
-  getopt_optarg = optarg;
-  getopt_optind = optind;
-  getopt_opterr = opterr;
-  getopt_optopt = optopt;
+  cgetopt_optarg = optarg;
+  cgetopt_optind = optind;
+  cgetopt_opterr = opterr;
+  cgetopt_optopt = optopt;
 
   return r;
 }
 
 
-typedef struct getopt_Options_s {
+typedef struct cgetopt_Options_s {
   struct option *cinfo;
   unsigned int high;
-} getopt_Options;
+} cgetopt_Options;
 
 
 /* InitOptions a constructor for Options.  */
 
-getopt_Options *
-getopt_InitOptions (void)
+cgetopt_Options *
+cgetopt_InitOptions (void)
 {
-  getopt_Options *o = (getopt_Options *) malloc (sizeof (getopt_Options));
+  cgetopt_Options *o = (cgetopt_Options *) malloc (sizeof (cgetopt_Options));
   o->cinfo = (struct option *) malloc (sizeof (struct option));
   o->high = 0;
   return o;
@@ -101,8 +101,8 @@ getopt_InitOptions (void)
 /* KillOptions a deconstructor for Options.  Returns NULL after freeing
    up all allocated memory associated with o.  */
 
-getopt_Options *
-getopt_KillOptions (getopt_Options *o)
+cgetopt_Options *
+cgetopt_KillOptions (cgetopt_Options *o)
 {
   free (o->cinfo);
   free (o);
@@ -113,7 +113,7 @@ getopt_KillOptions (getopt_Options *o)
 /* SetOption set option[index] with {name, has_arg, flag, val}.  */
 
 void
-getopt_SetOption (getopt_Options *o, unsigned int index,
+cgetopt_SetOption (cgetopt_Options *o, unsigned int index,
                  char *name, unsigned int has_arg,
                  int *flag, int val)
 {
@@ -133,7 +133,7 @@ getopt_SetOption (getopt_Options *o, unsigned int index,
    long options.  */
 
 struct option *
-getopt_GetLongOptionArray (getopt_Options *o)
+cgetopt_GetLongOptionArray (cgetopt_Options *o)
 {
   return o->cinfo;
 }
@@ -142,12 +142,12 @@ getopt_GetLongOptionArray (getopt_Options *o)
 /* GNU Modula-2 linking fodder.  */
 
 void
-_M2_getopt_init (void)
+_M2_cgetopt_init (void)
 {
 }
 
 
 void
-_M2_getopt_finish (void)
+_M2_cgetopt_finish (void)
 {
 }
diff --git a/gcc-versionno/gcc/m2/gm2-libs/getopt.def 
b/gcc-versionno/gcc/m2/gm2-libs/cgetopt.def
similarity index 98%
rename from gcc-versionno/gcc/m2/gm2-libs/getopt.def
rename to gcc-versionno/gcc/m2/gm2-libs/cgetopt.def
index c280958d..90ea8886 100644
--- a/gcc-versionno/gcc/m2/gm2-libs/getopt.def
+++ b/gcc-versionno/gcc/m2/gm2-libs/cgetopt.def
@@ -24,7 +24,7 @@ a copy of the GCC Runtime Library Exception along with this 
program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  *)
 
-DEFINITION MODULE getopt ;
+DEFINITION MODULE cgetopt ;
 
 FROM SYSTEM IMPORT ADDRESS ;
 
@@ -104,4 +104,4 @@ PROCEDURE SetOption (o: Options; index: CARDINAL;
 PROCEDURE GetLongOptionArray (o: Options) : ADDRESS ;
 
 
-END getopt.
+END cgetopt.
diff --git a/gcc-versionno/gcc/m2/tools-src/calcpath 
b/gcc-versionno/gcc/m2/tools-src/calcpath
new file mode 100755
index 00000000..6123d4ca
--- /dev/null
+++ b/gcc-versionno/gcc/m2/tools-src/calcpath
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+# calcpath return a path which is $1/$2/$3 when $2 is relative and $2/$3 if 
absolute.
+
+# Copyright (C) 2021 Free Software Foundation, Inc.
+# Contributed by Gaius Mulley <gaius.mul...@southwales.ac.uk>.
+#
+# This file is part of GNU Modula-2.
+#
+# GNU Modula-2 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 3, or (at your option) any later
+# version.
+#
+# GNU Modula-2 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 gm2; see the file COPYING.  If not, write to the Free Software
+# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
+
+
+Usage () {
+   echo "Usage: calcpath pathcomponent1 pathcomponent2 subdir"
+   echo -n "  if pathcomponent1 is relative then 
pathcomponent1/pathcomponet2/subdir is"
+   echo " returned"
+   echo "  otherwise pathcomponet2/subdir is returned"
+   echo "  the path is checked for legality in subdir."
+}
+
+
+if [ $# -eq 3 ]; then
+   if [ "$(echo $2 | cut -b 1)" = "." ] ; then
+       # relative path
+       the_path=$1/$2/$3
+   else
+       the_path=$2/$3
+   fi
+   cd $3
+   if realpath -e ${the_path} > /dev/null ; then
+       echo ${the_path}
+   else
+       echo "calcpath: error ${the_path} is not a valid path in subdirectory 
$3"
+       exit 1
+   fi
+else
+   Usage
+   exit 1
+fi


regards,
Gaius

Reply via email to