#!/usr/bin/make -f

DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_ARCH_CPU ?=$(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)

JAVAARCH :=$(DEB_HOST_ARCH_CPU)

ifeq ($(DEB_HOST_ARCH_CPU),powerpc)
  JAVAARCH :=ppc
endif

ifeq ($(DEB_HOST_ARCH_CPU),sh4)
  JAVAARCH :=sh
endif

ifeq ($(DEB_HOST_ARCH_CPU),arm64)
  JAVAARCH :=aarch64
endif

ifeq ($(DEB_HOST_ARCH_CPU),ppc64el)
  JAVAARCH :=ppc64le
endif

JAVA_LIB_PATH := /usr/lib/jvm/default-java/jre/lib/$(JAVAARCH)

export JCC_ARGSEP=;
export JCC_LFLAGS := -L$(JAVA_LIB_PATH);-ljava;-L$(JAVA_LIB_PATH)/server;-ljvm;-Wl,-rpath=$(JAVA_LIB_PATH):$(JAVA_LIB_PATH)/server

export JCC_CFLAGS := -fdollars-in-identifiers
export JCC_JDK := /usr/lib/jvm/default-java

# For shared mode we need patch http://bugs.python.org/setuptools/issue43 for setuptools to be applied
export NO_SHARED=1

%:
	dh $@ --with python2 --buildsystem=python_distutils

override_dh_auto_install:
	dh_auto_install
	rm -rf debian/jcc/usr/share/pyshared/jcc/patches

override_dh_strip:
	# _jcc.so does not seem to contain the debug section, so disable
	# building of a debug package, for now.
	dh_strip --no-automatic-dbgsym

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build/*
	rm -f jcc/config.py
	$(RM) JCC.egg-info/SOURCES.txt
