# Tanım: GNU C Derleyici Araçları
# URL: http://gcc.gnu.org
# Paketçi: milisarge
# Gerekler: 
# Grup: sistem

isim=gcc7
surum=7.4.0
devir=1
kaynak=(ftp://gcc.gnu.org/pub/gcc/releases/gcc-$surum/gcc-$surum.tar.xz
		http://isl.gforge.inria.fr/isl-0.18.tar.bz2
		bz84080.patch)

derle() {
	cd gcc-$surum
	patch -p0 -i "$SRC/bz84080.patch"
	sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
	sed -i '/m64=/s/lib64/lib/' gcc/config/i386/t-linux64
	sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" {libiberty,gcc}/configure
	ln -s ../isl-0.18 isl
	_surum=7
	comphost="x86_64-pc-linux-gnu"
	_libdir=usr/lib/gcc/$comphost/${surum}
	mkdir build
	cd build
	CFLAGS=${CFLAGS/-pipe/}
	CXXFLAGS=${CXXFLAGS/-pipe/}
	#ln -s /usr/lib64/*.o /usr/lib/
	../configure --prefix=/usr \
	--libdir=/usr/lib \
	--libexecdir=/usr/lib \
	--mandir=/usr/share/man \
	--infodir=/usr/share/info \
	--enable-languages=c,c++,fortran,objc \
	--enable-shared \
	--enable-threads=posix \
	--enable-libmpx \
	--with-system-zlib \
	--with-isl \
	--enable-__cxa_atexit \
	--disable-libunwind-exceptions \
	--enable-clocale=gnu \
	--disable-libstdcxx-pch \
	--disable-libssp \
	--enable-gnu-unique-object \
	--enable-linker-build-id \
	--enable-lto \
	--enable-plugin \
	--enable-install-libiberty \
	--with-linker-hash-style=gnu \
	--enable-gnu-indirect-function \
	--disable-werror \
	--enable-checking=release \
	--enable-default-pie \
	--enable-default-ssp \
	--program-suffix=-${_surum} \
	--enable-version-specific-runtime-libs \
	--disable-multilib

	make
	make -j3 DESTDIR=$PKG install

    mv "$PKG"/usr/lib/libcc1.so* "$PKG"/${_libdir}
    rm -rf "$PKG"/usr/lib/libcc1.la
    mv $PKG/${_libdir}/include-fixed/{limits.h,syslimits.h} $PKG/${_libdir}/include/
     
    rm -rf $PKG/usr/share/{info,locale,man}
    rm -rf $PKG/usr/include
    rm -rf $PKG/usr/lib64
    
    rm -rf $PKG/usr/bin/*-linux-gnu-*
    rm -rf $PKG/${_libdir}/{install-tools,include-fixed} 
	rm -rf $PKG/${_libdir}/*.la
	rm -rf $PKG/${_libdir}/plugin/libcp1plugin.la
	rm -rf $PKG/${_libdir}/plugin/libcc1plugin.la
    mv "$PKG"/usr/lib/gcc/$comphost/lib/libgcc_s.so* "$PKG"/$_libdir
    rm -rf "$PKG"/usr/lib/gcc/$comphost/lib
	ln -s gcc-7 "$PKG"/usr/bin/cc-7
	mkdir -p $PKG/etc/ld.so.conf.d
	echo "/usr/lib/gcc/x86_64-pc-linux-gnu/$surum" > $PKG/etc/ld.so.conf.d/gcc7.conf
}
