#!/usr/bin/make -f

CMAKE_BUILD_DIR?=$(CURDIR)/Debug-Tizen-Device
PKG_NAME?=com.samsung.untitled
EXEC_NAME?=$(shell echo ${PKG_NAME} | cut -d '.' -f3`)

configure: configure-stamp
configure-stamp:
	dh_testdir 
	# Add here commands to configure the package.
	touch configure-stamp

build: build-stamp
build-stamp: configure-stamp
	dh_testdir 
	# Add here commands to compile the package.
	touch build-stamp

clean:
	dh_testdir
	dh_clean
	# Add here commands to clean up before the build process.
	rm -f build-stamp configure-stamp

install: build
	dh_testdir
	dh_testroot
	dh_installdirs
	# Add here commands to install the package into debian/tmp
	mkdir -p debian/tmp/opt/apps/${PKG_NAME}/bin
	mkdir -p debian/tmp/opt/apps/${PKG_NAME}/res
	mkdir -p debian/tmp/opt/share/applications
	cp -rf "$(CMAKE_BUILD_DIR)/$(EXEC_NAME)"   debian/tmp/opt/apps/${PKG_NAME}/bin/$(EXEC_NAME)
	#Installing edj files
	mkdir -p debian/tmp/opt/apps/${PKG_NAME}/res/edje
	@for edj_file in `ls "$(CMAKE_BUILD_DIR)/res/edje/" | grep ".*\.edj"`; \
	do \
	  edj_file_path="$(CMAKE_BUILD_DIR)/res/edje/$$edj_file";\
	  echo "cp \"$$edj_file_path\"  debian/tmp/opt/apps/${PKG_NAME}/res/edje/";\
	  cp "$$edj_file_path"  debian/tmp/opt/apps/${PKG_NAME}/res/edje/; done
 	#Installing locale files
	@for mo_file in `ls "$(CMAKE_BUILD_DIR)/res/locale/" | grep ".*\.mo"`; \
	do \
	  mo_file_path="$(CMAKE_BUILD_DIR)/res/locale/$$mo_file";\
	  loc="$${mo_file%%.mo}";\
	  mkdir -p debian/tmp/opt/apps/${PKG_NAME}/res/locale/$$loc/LC_MESSAGES;\
	  echo "cp -rf \"$$mo_file_path\"  debian/tmp/opt/apps/${PKG_NAME}/res/locale/$$loc/LC_MESSAGES/$(EXEC_NAME).mo";\
	  cp -rf "$$mo_file_path"  debian/tmp/opt/apps/${PKG_NAME}/res/locale/$$loc/LC_MESSAGES/$(EXEC_NAME).mo; \
	done
	cp -rf res/images   debian/tmp/opt/apps/${PKG_NAME}/res/
	cp -rf res/etc   debian/tmp/opt/apps/${PKG_NAME}/res/
	cp -rf res/icons   debian/tmp/opt/apps/${PKG_NAME}/res/
	cp -rf data   debian/tmp/opt/apps/${PKG_NAME}/
	cp -rf lib   debian/tmp/opt/apps/${PKG_NAME}/
	cp -rf debian/desktop   debian/tmp/opt/share/applications/${PKG_NAME}.desktop
	

# 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
	dh_install --sourcedir="./debian/tmp"
	#dh_strip
	#dh_installman
	#dh_link
	#dh_compress
	dh_fixperms
	#dh_makeshlibs
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb --destdir="$(CMAKE_BUILD_DIR)"

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