#! /bin/sh
target_dir=/mingw
if [ "$1" = '3' ]; then
	gcc_ver=3.4.5
elif [ "$1" = '4' ]; then
	gcc_ver=sjlj
else
	echo 'give 3 or 4 for argument to switch'
	exit 1
fi

# version-specific files are ignored
# libstdc++_*_6.dll does not exist for gcc3.4.5, so ignored
bin_files='c++ cpp g++ gcc gcov mingw32-c++ mingw32-g++ mingw32-gcc'
bin2_files='gccbug'
info_files='cpp cppinternals gcc gccinstall gccint'
man1_files='cpp g++ gcc gcov'
man7_files='fsf-funding gfdl gpl'

if [ ! -f ${target_dir}/bin/gcc-${gcc_ver}.exe ]; then
	echo "${target_dir}/bin/gcc-${gcc_ver}.exe is not found"
	exit 1
fi

# libiberty
cp -fp ${target_dir}/lib/libiberty-${gcc_ver}.a ${target_dir}/lib/libiberty.a

# bin(exe)
for file in ${bin_files}
do
	cp -fp ${target_dir}/bin/${file}-${gcc_ver}.exe ${target_dir}/bin/${file}.exe
done

# bin(other)
for file in ${bin2_files}
do
	cp -fp ${target_dir}/bin/${file}-${gcc_ver} ${target_dir}/bin/${file}
done

# info
for file in ${info_files}
do
	cp -fp ${target_dir}/info/${file}-${gcc_ver}.info ${target_dir}/info/${file}.info
done

# man1
for file in ${man1_files}
do
	cp -fp ${target_dir}/man/man1/${file}-${gcc_ver}.1 ${target_dir}/man/man1/${file}.1
done

# man7
for file in ${man7_files}
do
	cp -fp ${target_dir}/man/man7/${file}-${gcc_ver}.7 ${target_dir}/man/man7/${file}.7
done
