#! /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 -p1 < $0
        #cd ${dir}gcc && autoconf
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p1 < $0
        #rm ${dir}gcc/configure
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

diff -u ./gcc/config/t-slibgcc-elf-ver~ ./gcc/config/t-slibgcc-elf-ver
--- ./gcc/config/t-slibgcc-elf-ver~	2003-01-26 12:35:07.000000000 +0100
+++ ./gcc/config/t-slibgcc-elf-ver	2004-05-28 17:23:02.856048856 +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_NAME).tmp @multilib_flags@ $(SHLIB_OBJS) $(SHLIB_LC) && \
 	rm -f $(SHLIB_SOLINK) && \
 	if [ -f $(SHLIB_NAME) ]; then \
diff -u ./libf2c/Makefile.in~ ./libf2c/Makefile.in
--- ./libf2c/Makefile.in~	2003-07-04 21:53:54.000000000 +0200
+++ ./libf2c/Makefile.in	2004-05-28 17:17:35.334839648 +0200
@@ -154,6 +154,7 @@
 	$(LIBTOOL) --mode=link $(CC) -o $@ \
 	  -version-info $(VERSION_MAJOR):$(VERSION_MINOR):$(VERSION_SUB) \
 	  -rpath $(glibcpp_toolexeclibdir) \
+	  -Wl,-O1 \
 	  -objectlist s-libe77 \
 	  -objectlist s-libf77 \
 	  -objectlist s-libi77 \
diff -u ./libffi/Makefile.am~ ./libffi/Makefile.am
--- ./libffi/Makefile.am~	2004-05-23 13:59:17.000000000 +0200
+++ ./libffi/Makefile.am	2004-05-28 17:18:54.254841984 +0200
@@ -179,7 +179,7 @@
 
 AM_CFLAGS = -fexceptions
 
-libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version`
+libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -Wl,-O1
 
 INCLUDES = -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src
 
diff -u ./libffi/Makefile.in~ ./libffi/Makefile.in
--- ./libffi/Makefile.in~	2004-05-23 13:59:17.000000000 +0200
+++ ./libffi/Makefile.in	2004-05-28 17:19:33.776833728 +0200
@@ -223,7 +223,7 @@
 
 AM_CFLAGS = -fexceptions
 
-libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version`
+libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -Wl,-O1
 
 INCLUDES = -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
diff -u ./libjava/Makefile.in~ ./libjava/Makefile.in
--- ./libjava/Makefile.in~	2004-05-23 13:59:17.000000000 +0200
+++ ./libjava/Makefile.in	2004-05-28 17:14:23.595988384 +0200
@@ -162,7 +162,7 @@
 
 GCJCOMPILE = $(LIBTOOL) --tag=GCJ --mode=compile $(GCJ_WITH_FLAGS) -fclasspath= -fbootclasspath=$(here) $(JC1FLAGS) -MD -MT $@ -MF $(@:.lo=.d) -c
 GCJLINK = $(LIBTOOL) --tag=GCJ --mode=link $(GCJ) -L$(here) $(JC1FLAGS) $(LDFLAGS) -o $@
-LIBLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXX) -L$(here) $(JC1FLAGS) $(LDFLAGS) -o $@
+LIBLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXX) -L$(here) $(JC1FLAGS) $(LDFLAGS) -Wl,-O1 -o $@
 
 LTCXXCOMPILE = $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
 
diff -u ./libjava/Makefile.am~ ./libjava/Makefile.am
--- ./libjava/Makefile.am~	2004-05-23 13:59:17.000000000 +0200
+++ ./libjava/Makefile.am	2004-05-28 17:13:58.076867880 +0200
@@ -67,7 +67,7 @@
 
 GCJCOMPILE = $(LIBTOOL) --tag=GCJ --mode=compile $(GCJ_WITH_FLAGS) -fclasspath= -fbootclasspath=$(here) $(JC1FLAGS) -MD -MT $@ -MF $(@:.lo=.d) -c
 GCJLINK = $(LIBTOOL) --tag=GCJ --mode=link $(GCJ) -L$(here) $(JC1FLAGS) $(LDFLAGS) -o $@
-LIBLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXX) -L$(here) $(JC1FLAGS) $(LDFLAGS) -o $@
+LIBLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXX) -L$(here) $(JC1FLAGS) $(LDFLAGS) -Wl,-O1 -o $@
 
 ## We define this because otherwise libtool can be run with different
 ## values of `CXX' and will then get confused and fail to work.  So,
diff -u ./libobjc/Makefile.in~ ./libobjc/Makefile.in
--- ./libobjc/Makefile.in~	2004-05-23 13:59:17.000000000 +0200
+++ ./libobjc/Makefile.in	2004-05-28 17:16:18.398535744 +0200
@@ -264,11 +264,13 @@
 libobjc.la: $(OBJS)
 	$(LIBTOOL_LINK) $(CC) -o $@ $(OBJS) \
 		-rpath $(glibcpp_toolexeclibdir) \
+		-Wl,-O1 \
 		-version-info $(LIBOBJC_VERSION)
 
 libobjc_gc.la: $(OBJS_GC)
 	$(LIBTOOL_LINK) $(CC) -o $@ $(OBJS_GC) \
 		-rpath $(glibcpp_toolexeclibdir) \
+		-Wl,-O1 \
 		-version-info $(LIBOBJC_GC_VERSION)
 
 #
diff -u ./libstdc++-v3/src/Makefile.am~ ./libstdc++-v3/src/Makefile.am
--- ./libstdc++-v3/src/Makefile.am~	2004-05-28 13:18:10.000000000 +0200
+++ ./libstdc++-v3/src/Makefile.am	2004-05-28 13:19:11.000000000 +0200
@@ -148,6 +148,7 @@
 libstdc___la_DEPENDENCIES = ${version_dep} $(libstdc___la_LIBADD)
 
 libstdc___la_LDFLAGS = \
+	-Wl,-O1 \
 	-version-info $(libtool_VERSION) ${version_arg} -lm 
 
 
diff -u ./libstdc++-v3/src/Makefile.in~ ./libstdc++-v3/src/Makefile.in
--- ./libstdc++-v3/src/Makefile.in~	2004-05-28 13:18:10.000000000 +0200
+++ ./libstdc++-v3/src/Makefile.in	2004-05-28 13:19:55.000000000 +0200
@@ -305,6 +305,7 @@
 libstdc___la_DEPENDENCIES = ${version_dep} $(libstdc___la_LIBADD)
 
 libstdc___la_LDFLAGS = \
+	-Wl,-O1 \
 	-version-info $(libtool_VERSION) ${version_arg} -lm 
 
 
