#! /bin/sh -e

dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p0 < $0
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

--- gcc/config/t-slibgcc-elf-ver.orig	2006-10-03 18:16:53.094898500 +0200
+++ gcc/config/t-slibgcc-elf-ver	2006-10-03 18:17:40.061833750 +0200
@@ -14,6 +14,7 @@
 SHLIB_LINK = $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -shared -nodefaultlibs \
 	-Wl,--soname=$(SHLIB_SONAME) \
 	-Wl,--version-script=$(SHLIB_MAP) \
+	-Wl,-O1 \
 	-o $(SHLIB_DIR)/$(SHLIB_SONAME).tmp @multilib_flags@ \
 	$(SHLIB_OBJS) $(SHLIB_LC) && \
 	rm -f $(SHLIB_DIR)/$(SHLIB_SOLINK) && \
--- libstdc++-v3/src/Makefile.am.orig	2006-10-03 18:16:53.186904250 +0200
+++ libstdc++-v3/src/Makefile.am	2006-10-03 18:17:40.121837500 +0200
@@ -185,6 +185,7 @@
 libstdc___la_DEPENDENCIES = ${version_dep} $(libstdc___la_LIBADD)
 
 libstdc___la_LDFLAGS = \
+	-Wl,-O1 \
 	-version-info $(libtool_VERSION) ${version_arg} -lm 
 
 # Use special rules for the deprecated source files so that they find
--- libstdc++-v3/src/Makefile.in.orig	2006-10-03 18:16:53.206905500 +0200
+++ libstdc++-v3/src/Makefile.in	2006-10-03 18:17:40.137838500 +0200
@@ -387,6 +387,7 @@
 
 libstdc___la_DEPENDENCIES = ${version_dep} $(libstdc___la_LIBADD)
 libstdc___la_LDFLAGS = \
+	-Wl,-O1 \
 	-version-info $(libtool_VERSION) ${version_arg} -lm 
 
 
--- libobjc/Makefile.in.orig	2006-10-03 18:16:53.098898750 +0200
+++ libobjc/Makefile.in	2006-10-03 18:17:40.061833750 +0200
@@ -276,11 +276,13 @@
 libobjc$(libext).la: $(OBJS)
 	$(LIBTOOL_LINK) $(CC) -o $@ $(OBJS) \
 		-rpath $(toolexeclibdir) \
+		-Wl,-O1 \
 		-version-info $(LIBOBJC_VERSION) $(extra_ldflags_libobjc)
 
 libobjc_gc$(libext).la: $(OBJS_GC)
 	$(LIBTOOL_LINK) $(CC) -o $@ $(OBJS_GC) \
 		-rpath $(toolexeclibdir) \
+		-Wl,-O1 \
 		-version-info $(LIBOBJC_GC_VERSION) $(extra_ldflags_libobjc)
 
 #
--- libgfortran/Makefile.am.orig	2006-10-03 18:16:53.102899000 +0200
+++ libgfortran/Makefile.am	2006-10-03 18:18:59.566802500 +0200
@@ -7,7 +7,7 @@
 gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
 
 toolexeclib_LTLIBRARIES = libgfortran.la
-libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lm $(extra_ldflags_libgfortran)
+libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lm $(extra_ldflags_libgfortran) -Wl,-O1
 
 myexeclib_LTLIBRARIES = libgfortranbegin.la
 myexeclibdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)
--- libgfortran/Makefile.in.orig	2006-10-03 18:16:53.106899250 +0200
+++ libgfortran/Makefile.in	2006-10-03 18:19:17.543926000 +0200
@@ -359,7 +359,7 @@
 ACLOCAL_AMFLAGS = -I ../config
 gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
 toolexeclib_LTLIBRARIES = libgfortran.la
-libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lm $(extra_ldflags_libgfortran)
+libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lm $(extra_ldflags_libgfortran) -Wl,-O1
 myexeclib_LTLIBRARIES = libgfortranbegin.la
 myexeclibdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)
 libgfortranbegin_la_SOURCES = fmain.c
--- libmudflap/Makefile.am.orig	2006-10-03 18:16:53.182904000 +0200
+++ libmudflap/Makefile.am	2006-10-03 18:17:40.117837250 +0200
@@ -34,7 +34,7 @@
 	mf-hooks2.c
 libmudflap_la_LIBADD = 
 libmudflap_la_DEPENDENCIES = $(libmudflap_la_LIBADD)
-libmudflap_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version`
+libmudflap_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -Wl,-O1
 
 clean-local:
 	rm -f pth/*.o pth/*.lo
--- libmudflap/Makefile.in.orig	2006-10-03 18:16:53.182904000 +0200
+++ libmudflap/Makefile.in	2006-10-03 18:17:40.121837500 +0200
@@ -241,7 +241,7 @@
 
 libmudflap_la_LIBADD = 
 libmudflap_la_DEPENDENCIES = $(libmudflap_la_LIBADD)
-libmudflap_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version`
+libmudflap_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -Wl,-O1
 libmudflapth_la_SOURCES = 
 libmudflapth_la_LIBADD = \
 	pth/mf-runtime.lo \
--- libffi/Makefile.am.orig	2006-10-03 18:16:53.098898750 +0200
+++ libffi/Makefile.am	2006-10-03 18:17:40.061833750 +0200
@@ -154,7 +154,7 @@
 
 AM_CFLAGS = -Wall -g -fexceptions
 
-libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version`
+libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -Wl,-O1
 
 AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src
 AM_CCASFLAGS = $(AM_CPPFLAGS)
--- libffi/Makefile.in.orig	2006-10-03 18:16:53.102899000 +0200
+++ libffi/Makefile.in	2006-10-03 18:17:40.065834000 +0200
@@ -436,7 +436,7 @@
 libffi_convenience_la_SOURCES = $(libffi_la_SOURCES)
 nodist_libffi_convenience_la_SOURCES = $(nodist_libffi_la_SOURCES)
 AM_CFLAGS = -Wall -g -fexceptions
-libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version`
+libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -Wl,-O1
 AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src
 AM_CCASFLAGS = $(AM_CPPFLAGS)
 all: fficonfig.h
--- libjava/Makefile.am.orig	2006-10-03 18:16:53.130900750 +0200
+++ libjava/Makefile.am	2006-10-03 18:17:40.093835750 +0200
@@ -97,7 +97,7 @@
 GCJLINK = $(LIBTOOL) --tag=GCJ --mode=link $(GCJ) -L$(here) $(JC1FLAGS) \
           $(LDFLAGS) -o $@
 LIBLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXX) -L$(here) $(JC1FLAGS) \
-          $(LDFLAGS) $(extra_ldflags_libjava) -o $@
+          $(LDFLAGS) $(extra_ldflags_libjava) -Wl,-O1 -o $@
 
 GCC_UNWIND_INCLUDE = @GCC_UNWIND_INCLUDE@
 
--- libjava/Makefile.in.orig	2006-10-03 18:16:53.162902750 +0200
+++ libjava/Makefile.in	2006-10-03 18:17:40.117837250 +0200
@@ -733,7 +733,7 @@
           $(LDFLAGS) -o $@
 
 LIBLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXX) -L$(here) $(JC1FLAGS) \
-          $(LDFLAGS) $(extra_ldflags_libjava) -o $@
+          $(LDFLAGS) $(extra_ldflags_libjava) -Wl,-O1 -o $@
 
 WARNINGS = -Wextra -Wall
 AM_CXXFLAGS = \
