#!/usr/bin/make -f
# export DH_VERBOSE=1

#if is_distribution?('>= precise') || is_distribution?('>= wheezy')
    export USE_VENDORED_LIBEV=false
#endif

#if ['1', 'true', 'on', 'yes'].include?(ENV['USE_CCACHE'])
	export USE_CCACHE=1
#endif

%:
	dh $@

override_dh_auto_configure:
	# Do nothing

override_dh_auto_build:
	/usr/bin/ruby1.8 /usr/bin/rake fakeroot
	mv pkg/fakeroot pkg/fakeroot1.8
	/usr/bin/ruby1.9.1 /usr/bin/rake fakeroot
	mv pkg/fakeroot pkg/fakeroot1.9.1
	cd nginx-<%= PhusionPassenger::PREFERRED_NGINX_VERSION %> && \
		./configure --prefix=/tmp \
		<%= PhusionPassenger::STANDALONE_NGINX_CONFIGURE_OPTIONS %> \
		--add-module=`pwd`/../ext/nginx && \
		make

override_dh_auto_install:
	mkdir debian/tmp/
	# Merge Ruby 1.8 and 1.9 files into a single directory.
	cp -a pkg/fakeroot1.8/* debian/tmp/
	cp -a pkg/fakeroot1.9.1/* debian/tmp/
	sed -i 's|## Magic comment: set locations\.ini ##|ENV["PASSENGER_LOCATION_CONFIGURATION_FILE"] = "/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini"|' debian/tmp/usr/bin/* debian/tmp/usr/sbin/*
	touch debian/tmp/usr/share/<%= PhusionPassenger::GLOBAL_NAMESPACE_DIRNAME %>/release.txt

override_dh_auto_clean:
	/usr/bin/rake clean CLEAN_DOCS=false
	rm -rf pkg/fakeroot1.8
	rm -rf pkg/fakeroot1.9.1
	cd nginx-<%= PhusionPassenger::PREFERRED_NGINX_VERSION %> && if test -f Makefile; then make clean; fi
	# Hack to prevent HTML files from being renegerated
	touch doc/*.html
