This is the mail archive of the gcc@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]

RFC: makefile cleanups wrt unified tree



   
 To cleanup gcc/Makefile a bit, I've written a couple of autoconf 
macros to detect tools not only in path, but in the unified source 
tree too. Currently I use them to set all *_FOR_TARGET variables in
gcc/Makefile, however I think they could help to autoconfiscate top
level directory in the long run. 

Those macros and some Makefile cleanup are in the patch below, and
I'm looking to hear if I'm on the right track and should continue
working on it.

The patch in its current form is only for commenting on and not for 
inclusion - trivial mklibgcc.in and not so trivial top level bits
are missing, and getting them right will take more work.

Laurynas

Index: gcc/gcc/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.618
diff -u -p -r1.618 Makefile.in
--- Makefile.in	2001/03/07 19:05:24	1.618
+++ Makefile.in	2001/03/09 19:59:33
@@ -199,43 +199,12 @@ host_canonical = @host_canonical@
 # objdir is set by configure.
 objdir = @objdir@
 
-AR_FOR_TARGET = ` \
-  if [ -f $(objdir)/../binutils/ar ] ; then \
-    echo $(objdir)/../binutils/ar ; \
-  else \
-    if [ "$(host_canonical)" = "$(target)" ] ; then \
-      echo ar; \
-    else \
-       t='$(program_transform_cross_name)'; echo ar | sed -e $$t ; \
-    fi; \
-  fi`
+AR_FOR_TARGET = @target_ar@
 AR_FLAGS_FOR_TARGET = 
 AR_CREATE_FOR_TARGET = $(AR_FOR_TARGET) $(AR_FLAGS_FOR_TARGET) rc
 AR_EXTRACT_FOR_TARGET = $(AR_FOR_TARGET) $(AR_FLAGS_FOR_TARGET) x
-RANLIB_FOR_TARGET = ` \
-  if [ -f $(objdir)/../binutils/ranlib ] ; then \
-    echo $(objdir)/../binutils/ranlib ; \
-  else \
-    if [ "$(host_canonical)" = "$(target)" ] ; then \
-      echo ranlib; \
-    else \
-       t='$(program_transform_cross_name)'; echo ranlib | sed -e $$t ; \
-    fi; \
-  fi`
-RANLIB_TEST_FOR_TARGET = \
-  [ -f $(RANLIB_FOR_TARGET) ] \
-  || ( [ "$(host_canonical)" = "$(target)" ] \
-       && [ -f /usr/bin/ranlib -o -f /bin/ranlib ] )
-NM_FOR_TARGET = ` \
-  if [ -f $(objdir)/../binutils/nm ] ; then \
-    echo $(objdir)/../binutils/nm ; \
-  else \
-    if [ "$(host_canonical)" = "$(target)" ] ; then \
-      echo nm; \
-    else \
-       t='$(program_transform_cross_name)'; echo nm | sed -e $$t ; \
-    fi; \
-  fi`
+RANLIB_FOR_TARGET = @target_ranlib@
+NM_FOR_TARGET = @target_nm@
 
 # Dir to search for system headers.  Overridden by cross-make.
 SYSTEM_HEADER_DIR = /usr/include
@@ -526,13 +495,9 @@ ALL=all.internal
 INSTALL_TARGET=install-normal
 
 # Setup the testing framework, if you have one
-EXPECT = `if [ -f $${rootme}/../expect/expect ] ; then \
-            echo $${rootme}/../expect/expect ; \
-          else echo expect ; fi`
-
-RUNTEST = `if [ -f $${srcdir}/../dejagnu/runtest ] ; then \
-	       echo $${srcdir}/../dejagnu/runtest ; \
-	    else echo runtest; fi`
+EXPECT = @expect@
+
+RUNTEST = @runtest@
 RUNTESTFLAGS =
 
 # Extra symbols for fixproto to define when parsing headers.
@@ -676,7 +641,6 @@ ORDINARY_FLAGS_TO_PASS = \
 	"MAKEINFOFLAGS=$(MAKEINFOFLAGS)" \
 	"MAKEOVERRIDES=" \
 	"RANLIB_FOR_TARGET=$(RANLIB_FOR_TARGET)" \
-	"RANLIB_TEST_FOR_TARGET=$(RANLIB_TEST_FOR_TARGET)" \
 	"SHELL=$(SHELL)" \
 	"STAGE_PREFIX=@stage_prefix_set_by_configure@" \
 	"exeext=$(exeext)" \
@@ -1039,7 +1003,6 @@ libgcc.a: $(LIBGCC_DEPS)
 	  OLDCC="$(OLDCC)" CCLIBFLAGS="$(CCLIBFLAGS)" \
 	  CFLAGS="$(CFLAGS) $(WARN_CFLAGS)" \
 	  RANLIB_FOR_TARGET="$(RANLIB_FOR_TARGET)" \
-	  RANLIB_TEST_FOR_TARGET="$(RANLIB_TEST_FOR_TARGET)" \
 	  NM_FOR_TARGET="$(NM_FOR_TARGET)" AWK="$(AWK)" \
 	  LIBGCC2_CFLAGS="$(LIBGCC2_CFLAGS)" \
 	  INCLUDES="$(INCLUDES)" MAYBE_USE_COLLECT2="$(MAYBE_USE_COLLECT2)" \
@@ -1074,7 +1037,6 @@ stmp-multilib: $(LIBGCC_DEPS)
 	  OLDCC="$(OLDCC)" CCLIBFLAGS="$(CCLIBFLAGS)" \
 	  CFLAGS="$(CFLAGS) $(WARN_CFLAGS)" \
 	  RANLIB_FOR_TARGET="$(RANLIB_FOR_TARGET)" \
-	  RANLIB_TEST_FOR_TARGET="$(RANLIB_TEST_FOR_TARGET)" \
 	  NM_FOR_TARGET="$(NM_FOR_TARGET)" AWK="$(AWK)" \
 	  LIBGCC2_CFLAGS="$(LIBGCC2_CFLAGS)" \
 	  INCLUDES="$(INCLUDES)" MAYBE_USE_COLLECT2="$(MAYBE_USE_COLLECT2)" \
@@ -2587,26 +2549,16 @@ install-man: installdirs $(GENERATED_MAN
 
 # Install the library.
 install-libgcc: libgcc.mk libgcc.a installdirs
-	if $(RANLIB_TEST_FOR_TARGET); then \
-	  r_f_t=$(RANLIB_FOR_TARGET); \
-	else \
-	  r_f_t=: ; \
-	fi; \
 	$(MAKE) INSTALL_DATA="$(INSTALL_DATA)" \
-	  RANLIB_FOR_TARGET="$$r_f_t" \
+	  RANLIB_FOR_TARGET="$(RANLIB_FOR_TARGET)" \
 	  libsubdir="$(libsubdir)" \
 	  slibdir="$(slibdir)" \
 	  -f libgcc.mk install
 
 # Install multiple versions of libgcc.a.
 install-multilib: stmp-multilib installdirs
-	if $(RANLIB_TEST_FOR_TARGET); then \
-	  r_f_t=$(RANLIB_FOR_TARGET); \
-	else \
-	  r_f_t=: ; \
-	fi; \
 	$(MAKE) INSTALL_DATA="$(INSTALL_DATA)" \
-	  RANLIB_FOR_TARGET="$$r_f_t" \
+	  RANLIB_FOR_TARGET="$(RANLIB_FOR_TARGET)" \
 	  libsubdir="$(libsubdir)" \
 	  slibdir="$(slibdir)" \
 	  -f libgcc.mk install
@@ -3070,9 +3022,7 @@ stage1-start:
 	-if [ -f collect-ld$(exeext) ] ; then $(LN_S) ../collect-ld$(exeext) stage1 ; else true ; fi
 	-rm -f stage1/libgcc.a
 	-cp libgcc.a stage1
-	-if $(RANLIB_TEST_FOR_TARGET) ; then \
-	  $(RANLIB_FOR_TARGET) stage1/libgcc.a; \
-	else true; fi
+	-$(RANLIB_FOR_TARGET) stage1/libgcc.a
 	-for f in .. $(EXTRA_MULTILIB_PARTS); do if [ x$${f} != x.. ]; then \
 	  cp stage1/$${f} . ; \
 	else true; \
@@ -3095,9 +3045,7 @@ stage2-start:
 	-if [ -f collect-ld ] ; then $(LN_S) ../collect-ld$(exeext) stage2 ; else true ; fi
 	-rm -f stage2/libgcc.a
 	-cp libgcc.a stage2
-	-if $(RANLIB_TEST_FOR_TARGET) ; then \
-	  $(RANLIB_FOR_TARGET) stage2/libgcc.a; \
-	else true; fi
+	-$(RANLIB_FOR_TARGET) stage2/libgcc.a
 	-for f in .. $(EXTRA_MULTILIB_PARTS); do if [ x$${f} != x.. ]; then \
 	  cp stage2/$${f} . ; \
 	else true; \
@@ -3120,9 +3068,7 @@ stage3-start:
 	-if [ -f collect-ld$(exeext) ] ; then $(LN_S) ../collect-ld$(exeext) stage3 ; else true ; fi
 	-rm -f stage3/libgcc.a
 	-cp libgcc.a stage3
-	-if $(RANLIB_TEST_FOR_TARGET) ; then \
-	  $(RANLIB_FOR_TARGET) stage3/libgcc.a; \
-	else true; fi
+	-$(RANLIB_FOR_TARGET) stage3/libgcc.a
 	-for f in .. $(EXTRA_MULTILIB_PARTS); do if [ x$${f} != x.. ]; then \
 	  cp stage3/$${f} . ; \
 	else true; \
@@ -3145,9 +3091,7 @@ stage4-start:
 	-if [ -f collect-ld$(exeext) ] ; then $(LN_S) ../collect-ld$(exeext) stage4 ; else true ; fi
 	-rm -f stage4/libgcc.a
 	-cp libgcc.a stage4
-	-if $(RANLIB_TEST_FOR_TARGET) ; then \
-	  $(RANLIB_FOR_TARGET) stage4/libgcc.a; \
-	else true; fi
+	-$(RANLIB_FOR_TARGET) stage4/libgcc.a
 	-for f in .. $(EXTRA_MULTILIB_PARTS); do if [ x$${f} != x.. ]; then \
 	  cp stage4/$${f} . ; \
 	else true; \
Index: gcc/gcc/aclocal.m4
===================================================================
RCS file: /cvs/gcc/gcc/gcc/aclocal.m4,v
retrieving revision 1.42
diff -u -p -r1.42 aclocal.m4
--- aclocal.m4	2001/03/06 09:52:28	1.42
+++ aclocal.m4	2001/03/09 19:59:37
@@ -1123,3 +1123,55 @@ else
   gcc_cv_prog_$2_modern=no
 fi
 ])
+
+dnl gcc_AC_PROG_UNIFIED(variable, tool[, subdir[, value-if-not-found[, source]]])
+dnl Locates a tool in the unified source tree.  Because this is being done
+dnl at configure time, the tool might be not yet built and have to check the
+dnl presence of some source file.  If you don't build that tool later, blame 
+dnl yourself.
+AC_DEFUN(gcc_AC_PROG_UNIFIED,
+[  AC_CACHE_CHECK(for $2 in the unified source tree, gcc_cv_unified_$2,
+   [if test "x$3" = "x"; then
+      dnl Assume that tool subdir name in the unified source tree is the same 
+      dnl as the tool name
+      gcc_ac_dir=$2
+   else
+      gcc_ac_dir=$3
+      if test "x$4" = "x"; then
+         gcc_ac_missing=":"
+      else
+         gcc_ac_missing=$4
+         if test "x$5" = "x"; then
+            dnl Assume that source file name is made from executable name with .c 
+            dnl extension
+            gcc_ac_source=$2.c
+         else
+            gcc_ac_source=$5
+         fi    
+      fi
+   fi
+   if test -f $srcdir/../$gcc_ac_dir/$gcc_ac_source; then
+      $1=$objdir/../$gcc_ac_dir/$2
+   else
+      $1=$gcc_ac_missing 
+   fi
+   gcc_cv_unified_$2=$$1 
+   AC_SUBST([$1])
+   ])
+])
+
+dnl gcc_AC_CHECK_TARGET_TOOL(variable, tool[, subdir[, value-if-not-found[, source]]])
+dnl Locate tools for target in the following order:
+dnl  - in system path with target alias prepended
+dnl  - in system path as-is
+dnl  - in unified source tree
+AC_DEFUN(gcc_AC_CHECK_TARGET_TOOL,
+[  AC_REQUIRE([AC_CANONICAL_SYSTEM])
+   AC_CHECK_PROG([$1], $target-[$2], $target-[$2])
+   if test -z "[$]$1"; then
+      AC_CHECK_PROG([$1], [$2], [$2], [$4])
+      if test -z "[$]$1"; then
+         gcc_AC_PROG_UNIFIED([$1], [$2], [$3], [$4], [$5])
+      fi
+   fi
+])
Index: gcc/gcc/configure.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/configure.in,v
retrieving revision 1.491
diff -u -p -r1.491 configure.in
--- configure.in	2001/03/08 19:36:21	1.491
+++ configure.in	2001/03/09 19:59:54
@@ -432,6 +432,11 @@ gcc_AC_PROG_LN_S
 gcc_AC_C_VOLATILE
 AC_PROG_RANLIB
 gcc_AC_PROG_INSTALL
+gcc_AC_CHECK_TARGET_TOOL(target_ar, ar, binutils)
+gcc_AC_CHECK_TARGET_TOOL(target_ranlib, ranlib, binutils, true)
+gcc_AC_CHECK_TARGET_TOOL(target_nm, nm, binutils)
+gcc_AC_PROG_UNIFIED(expect, expect, dejagnu, expect, expect.c)
+gcc_AC_PROG_UNIFIED(runtest, runtest, dejagnu, runtest, runtest.c)
 
 AC_HEADER_STDC
 AC_HEADER_TIME






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