#!/usr/bin/make -f
# 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

DUMMY			:= 1

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

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	 LDFLAGS 	:= -s
endif

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


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

build: build-stamp
build-stamp:
	dh_testdir
ifneq ($(DUMMY), 1)

	# Add here commands to compile the package.
	@echo "Starting build process ($(DEB_BUILD_ARCH))"
	  UPX_UCLDIR=/none CC=$(CC) CXX=$(CXX) 	\
	  CXXFLAGS="$(CXXFLAGS)" 		\
	  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

endif # DUMMY
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Add here commands to clean up after the build process.
ifneq ($(DUMMY), 1)
	-make UPX_UCLDIR=/none \
			exeext="" \
			distclean
	rm -rf doc/*.{1,ps}
endif # DUMMY	

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

ifneq ($(DUMMY), 1)
	# 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
endif # DUMMY

# 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
ifneq ($(DUMMY), 1)
	dh_installchangelogs NEWS
else
	dh_installchangelogs
endif # DUMMY 	

	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
ifneq ($(DUMMY), 1)
	dh_installman doc/*.1
else	
	dh_link
endif # DUMMY	
	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
