#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess. 
# $Id: rules 541 2009-10-15 10:54:57Z robert $ 
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export PATH := /home/robert/bin/gcc-4.4:$(PATH)

CC			:= gcc
CXX			:= g++
package			:= $(shell dh_listpackages)

BIG_ENDIAN_ARCHS	:= hppa ia64 sparc 
DEB_BUILD_ARCH		:= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

export DESTDIR		:= $(CURDIR)/debian/$(package)

CXXFLAGS		:= -DWITH_UCL -g
ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CXXFLAGS 	+= -O2
else
	CXXFLAGS 	+= -O0
endif


ifneq (,$(findstring $(DEB_BUILD_ARCH), $(BIG_ENDIAN_ARCHS)))
	CXXFLAGS 	+= -D__BIG_ENDIAN__=1
	CPPFLAGS 	+= -D__BIG_ENDIAN__=1
endif


ifeq (0,1)
	CXXFLAGS 	+= -I $(I)
	LDFLAGS 	+= -L $(L)
endif

ifeq (armel,$(DEB_BUILD_ARCH))
	# [asac] not thumb2 ready - use -marm
	CXXFLAGS	+= -marm
endif


build: build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	@echo "Starting build process ($(DEB_BUILD_ARCH))"
	  UPX_UCLDIR=/none CC=$(CC) CXX=$(CXX) 	\
	  CXXFLAGS="$(CXXFLAGS)" 		\
	  CPPFLAGS="$(CPPFLAGS)"		\
	  LDFLAGS="$(LDFLAGS)" 			\
        make exeext="" target=linux all

	cd doc && mv upx.1 $(package).1
ifneq (, $(wildcard debian/dh_upx))
	pod2man -c " " -r "dh_upx" debian/dh_upx > doc/dh_upx.1
endif

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Add here commands to clean up after the build process.
	-make UPX_UCLDIR=/none \
			exeext="" \
			distclean
	rm -rf doc/*.1 doc/*.ps

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/<packagename>
	install -pm 0755 src/upx $(DESTDIR)/usr/bin/$(package)
ifneq (, $(wildcard debian/dh_upx))
	install -pm 0755 debian/dh_upx $(DESTDIR)/usr/bin/
endif

# 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_installchangelogs NEWS
	dh_installdocs
#	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installcatalogs
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
#	dh_undocumented
	dh_installman doc/*.1
#	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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