#!/usr/bin/make -f
# debian/rules for Haxe.

%:
	dh $@ --with bash-completion

PKD   = $(abspath $(dir $(MAKEFILE_LIST)))
PKG   = haxe
UVER  = $(shell dpkg-parsechangelog -l$(PKD)/changelog | perl -ne 'print $$1 if m{^Version:\s+(?:\d+:)?(\d.*)(?:\-\d+.*)};')
DTYPE = +dfsg
VER  ?= $(subst $(DTYPE),,$(UVER))

override_dh_auto_configure:

override_dh_auto_build:
	# Check to see if ocamlopt exists. If not, bytecompile everything.
	command -v ocamlopt && dh_auto_build || dh_auto_build -- BYTECODE=1
	# Compile haxelib to neko
	dh_auto_build -- tools

override_dh_auto_install:

override_dh_fixperms:
	dh_fixperms
	# https://github.com/HaxeFoundation/haxe/commit/7ecbc2baaef0e2f653f43b01071ffff0050ec5d3
	cd $(CURDIR)/debian/haxe/usr/share/haxe/ && chmod a-x std/js/Boot.hx std/js/_std/Type.hx std/php/_std/haxe/ds/StringMap.hx

override_dh_strip:
	# haxelib is the neko vm appended with neko bytecode. It should not be stripped
	dh_strip --exclude=haxelib

override_dh_clean:
	dh_clean
	# https://github.com/HaxeFoundation/ocamllibs/pull/17
	rm -f $(CURDIR)/libs/extc/process.o
	rm -f $(CURDIR)/libs/objsize/objsize.a

get-orig-source:
	# create tar manually from git, in order to get submodules and remove js source files
	git clone --branch $(VER) --depth 1 --recursive https://github.com/HaxeFoundation/haxe.git orig-source
	cd orig-source && \
		rm std/js/*.js && git commit -am "removed js source files for debian" && \
		python $(CURDIR)/debian/git-archive-all ../../$(PKG)_$(VER)$(DTYPE).orig.tar.gz
	rm -rf orig-source