#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

TARGET=avr
TARGET_ARCH=avr
PACKAGE=gcc-avr

ifeq (,$(DEB_BUILD_GNU_TYPE))
  include /usr/share/dbs/dpkg-arch.mk
endif

CONFARGS = -v \
        --enable-languages=c,c++ \
        --prefix=/usr \
        --infodir=/usr/share/info \
        --mandir=/usr/share/man \
        --enable-shared \
	--with-as=/usr/avr/bin/as \
        --with-gnu-as \
	--with-ld=/usr/avr/bin/ld \
        --with-gnu-ld \
        --with-system-zlib \
        --enable-long-long \
        --enable-nls \
        --without-included-gettext \
        --disable-checking \
        --build=$(DEB_BUILD_GNU_TYPE) \
        --host=$(DEB_HOST_GNU_TYPE) \
        --target=$(TARGET) 

srcdir=src

# Patches
#patch_stamp=patch-stamp
#debian_patches = gcc_avr_fixed_reg
#include /usr/src/toolchain/patches/gcc/rules.patch

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=3

TAR_DIR=gcc-*
include /usr/share/dbs/dbs-build.mk

#unpack: unpack-stamp
#unpack-stamp:
#	tar xjf /usr/src/toolchain/gcc.tar.bz2
#	mv gcc-* src
#	mkdir build
#
#	touch unpack-stamp

configure: configure-stamp
configure-stamp: $(patched)
	dh_testdir
	# Add here commands to configure the package.
	cd $(BUILD_TREE) && env CC="gcc" ./configure $(CONFARGS) 
	touch configure-stamp

build: configure-stamp build-stamp
build-stamp: $(patched)
	dh_testdir

	# Add here commands to compile the package.
	cd $(BUILD_TREE) && $(MAKE)
	#/usr/bin/docbook-to-man debian/$(PACKAGE).sgml > $(PACKAGE).1

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	#-$(MAKE) clean
	rm -rf $(STAMP_DIR) $(SOURCE_DIR)

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/$(PACKAGE).
	cd build-tree/*/ && $(MAKE) install DESTDIR=$(CURDIR)/debian/$(PACKAGE)/

	rm debian/$(PACKAGE)/usr/share/man/man1/avr-g++.1
	ln -s avr-gcc.1.gz debian/$(PACKAGE)/usr/share/man/man1/avr-g++.1.gz
	ln -s avr-gcc.1.gz debian/$(PACKAGE)/usr/share/man/man1/avr-c++.1.gz
	ln -s avr-gcc.1.gz debian/$(PACKAGE)/usr/share/man/man1/avr-gcc-3.4.0.1.gz
	ln -s gccbug.1.gz debian/$(PACKAGE)/usr/share/man/man1/avr-gccbug.1.gz
	cd debian/$(PACKAGE)/usr/ && \
	/usr/src/toolchain/scripts/tpkg-gcc-rm-common-files

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs -n
#	dh_installexamples
#	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
	dh_installman
	dh_installinfo
	dh_undocumented avr-gccbug.1 avr-gcov.1
	dh_installchangelogs 
	dh_link
	dh_strip -Xlibgcc.a
	avr-strip --strip-debug `find debian/gcc-avr/ -name libgcc.a`
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
