#!/usr/bin/make -f
# $Id: rules 561 2011-02-09 07:22:31Z robert $
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.

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

DH_AUTO_OPTIONS         := -v -Smakefile --parallel
package                 := $(shell dh_listpackages)


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

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

export CC               := gcc
export CXX              := g++
export UPX_UCLDIR       := /none
export CXXFLAGS         := $(shell dpkg-buildflags --get CXXFLAGS)
export CPPFLAGS         := -DWITH_UCL $(shell dpkg-buildflags --get CPPFLAGS)
export LDFLAGS          := $(shell dpkg-buildflags --get LDFLAGS)
ifneq (,$(findstring $(DEB_BUILD_ARCH), $(BIG_ENDIAN_ARCHS)))
        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))"
	dh_auto_build $(DH_AUTO_OPTIONS) --     \
	              exeext=""                 \
	              target=linux              \
	              all
	
	cd doc && mv upx.1 $(package).1
	
	touch "$@"

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	
	dh_auto_clean $(DH_AUTO_OPTIONS) -- \
	                exeext=""
	rm -rf doc/*.1 doc/*.ps
	
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	
	install -pm 0755 src/upx $(DESTDIR)/usr/bin/$(package)


# Build architecture-dependent files here.
binary-arch: build-arch 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-indep build-indep:       # Nothing to do

binary: binary-indep binary-arch
build:  build-indep  build-arch

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

.DEFAULT_GOAL := binary
