# Template file for 'msp430-toolchain'
pkgname=msp430-toolchain
version=3.03.04.00
revision=1
short_desc="Toolchain for the TI MSP430 microprocessor"
maintainer="allan <mail@may.mooo.com>"
homepage="http://www.ti.com/tool/msp430-gcc-opensource"
license="GPL-2"
distfiles="http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/${version//./_}/exports/msp430-gcc-source.tar.bz2
	   http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/${version//./_}/exports/msp430-gcc-support-files.zip"
checksum="67179535e68951bfb82f8bb1bf099a716e921f11b1ad773c87a08b6054ed31b0
	  a67c7132f08713427604610595ab102ba73d0e2c2ca6e73355501e4c6d71d7ad"
nocross=yes
nostrip=yes
create_wrksrc=yes
hostmakedepends="unzip expect flex"
makedepends="tk-devel ncurses-devel"

_prefix=/usr/msp430
_target=msp430-none-elf

do_configure() {
	unset CC LD AR AS RANLIB CPP CFLAGS CPPFLAGS LDFLAGS

	mkdir obj-msp
	cd obj-msp
	../sources/tools/configure \
	   --prefix=$_prefix \
	   --enable-languages=c \
	   --program-prefix="msp430-" \
	   --disable-nls \
	   --enable-gold \
	   --target=$_target
}

do_build() {
	unset CC LD AR AS RANLIB CPP CFLAGS CPPFLAGS LDFLAGS

	cd obj-msp
	sed -i 's:^prefix =.*:prefix = '${DESTDIR}'/@prefix@:' \
		../sources/tools/libgloss/Makefile.in
	sed -i 's:^LIBEXPAT .*:LIBEXPAT = @LIBEXPAT@ @BDYNAMIC@:' \
		../sources/tools/gdb/Makefile.in

	make ${makejobs} DESTDIR=${DESTDIR} all
}

do_install() {
	cd obj-msp
	sed -i '190,194s:$(tooldir):'${DESTDIR}'/$(tooldir):' \
		msp430-none-elf/libgloss/msp430/Makefile
	sed -i '190,194s:$(tooldir):'${DESTDIR}'/$(tooldir):' \
		msp430-none-elf/430/libgloss/msp430/Makefile
	sed -i '190,194s:$(tooldir):'${DESTDIR}'/$(tooldir):' \
		msp430-none-elf/large/libgloss/msp430/Makefile

	make DESTDIR=${DESTDIR} prefix=${_prefix} install

	# copy msp430-gcc-support-files.zip
	cp ${wrksrc}/msp430-gcc-support-files/*.h \
		${DESTDIR}/${_prefix}/${_target}/include/
	cp ${wrksrc}/msp430-gcc-support-files/*.ld \
		${DESTDIR}/${_prefix}/${_target}/lib/430/

	mkdir -p ${DESTDIR}/usr/bin
	cd ${DESTDIR}/${_prefix}/bin
	for i in *
	do ln -s ${_prefix}/bin/$i ${DESTDIR}/usr/bin/$i
	done
}
