#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# define package name
COMMON_PKG=cnijfilter2

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

LNGBITS := $(shell getconf LONG_BIT)
ifeq ($(LNGBITS),32)
	_arc=32
else
	_arc=64
endif

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

	### configure 
	@echo "######## configure cmdtocanonij2"; \
	cd ./cmdtocanonij2; ./autogen.sh --prefix=/usr --datadir=/usr/share LDFLAGS="-L../../com/libs_bin${_arc}"
	@echo "######## configure cmdtocanonij3"; \
	cd ./cmdtocanonij3; ./autogen.sh --prefix=/usr --datadir=/usr/share LDFLAGS="-L../../com/libs_bin${_arc}"
	@echo "######## configure cnijbe2"; \
	cd ./cnijbe2; ./autogen.sh --prefix=/usr --enable-progpath=/usr/bin
	@echo "######## configure lgmon3"; \
	cd ./lgmon3; ./autogen.sh --prefix=/usr --enable-progpath=/usr/bin --enable-libpath=/usr/lib/bjlib2 --datadir=/usr/share LDFLAGS="-L../../com/libs_bin${_arc}"
	@echo "######## rastertocanonij"; \
	cd ./rastertocanonij; ./autogen.sh --prefix=/usr --enable-progpath=/usr/bin
	@echo "######## tocanonij"; \
	cd ./tocanonij; ./autogen.sh --prefix=/usr --enable-progpath=/usr/bin
	@echo "######## tocnpwg"; \
	cd ./tocnpwg; ./autogen.sh --prefix=/usr --enable-progpath=/usr/bin

	touch configure-stamp


build: build-stamp
build-stamp: configure-stamp 
	dh_testdir
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	-$(MAKE) clean

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	### install common package
	@echo "######## make install cmdtocanonij2"; \
	cd ./cmdtocanonij2; make clean; make; make install DESTDIR=$(CURDIR)/debian/${COMMON_PKG}
	@echo "######## make install cmdtocanonij3"; \
	cd ./cmdtocanonij3; make clean; make; make install DESTDIR=$(CURDIR)/debian/${COMMON_PKG}
	@echo "######## make install cnijbe2"; \
	cd ./cnijbe2; make clean; make; make install DESTDIR=$(CURDIR)/debian/${COMMON_PKG}
	@echo "######## make install lgmon3"; \
	cd ./lgmon3; make clean; make; make install DESTDIR=$(CURDIR)/debian/${COMMON_PKG} 
	@echo "######## make install rastertocanonij"; \
	cd ./rastertocanonij; make clean; make; make install DESTDIR=$(CURDIR)/debian/${COMMON_PKG}
	@echo "######## make install tocanonij"; \
	cd ./tocanonij; make clean; make; make install DESTDIR=$(CURDIR)/debian/${COMMON_PKG}
	@echo "######## make install tocnpwg"; \
	cd ./tocnpwg; make clean; make; make install DESTDIR=$(CURDIR)/debian/${COMMON_PKG}

	@echo "######## install library ini ppd"; \
	mkdir -p $(CURDIR)/debian/${COMMON_PKG}/usr/lib/bjlib2; \
	install -c -m 644 -o lp -g lp com/ini/cnnet.ini $(CURDIR)/debian/${COMMON_PKG}/usr/lib/bjlib2; \
	mkdir -p $(CURDIR)/debian/${COMMON_PKG}/usr/lib; \
	install -c -m 755 com/libs_bin${_arc}/libcnnet2.so.* $(CURDIR)/debian/${COMMON_PKG}/usr/lib; \
	install -c -m 755 com/libs_bin${_arc}/libcnbpnet20.so.* $(CURDIR)/debian/${COMMON_PKG}/usr/lib; \
	install -c -m 755 com/libs_bin${_arc}/libcnbpnet30.so.* $(CURDIR)/debian/${COMMON_PKG}/usr/lib; \
	install -c -m 755 com/libs_bin${_arc}/libcnbpcnclapicom2.so.* $(CURDIR)/debian/${COMMON_PKG}/usr/lib; \
	mkdir -p $(CURDIR)/debian/${COMMON_PKG}/usr/share/ppd; \
	install -c -m 644 -o lp -g lp ppd/*.ppd $(CURDIR)/debian/${COMMON_PKG}/usr/share/ppd; \

	# Add here commands to install the package into debian/cnijfilter-common.
	#$(MAKE) install DESTDIR=$(CURDIR)/debian/cnijfilter-common


	touch $@

# 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_installchangelogs 
	dh_installdocs
	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress -X.txt
	dh_fixperms --exclude=bscc --exclude=cnnet.ini
#	dh_perl
#	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 configure
