#!/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


# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


CFLAGS = -Wall -g

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

CFLAGS += -DWWWUID=33	# uid of www-data
CFLAGS += -DMINUID=500	# uid of nwberater

WRAPPER_SOURCES = $(wildcard src/util/*.c)
WRAPPER_BINARIES= $(patsubst src/util/%.c, debian/tmp/usr/lib/schulkonsole/bin/%, $(WRAPPER_SOURCES))
WRAPPER_PERMS   = $(patsubst src/util/%.c, -X/usr/lib/schulkonsole/bin/%, $(WRAPPER_SOURCES))

build:
	make

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	# Add here commands to clean up after the build process.

	dh_clean 

install:
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs -i etc/linuxmuster/schulkonsole/menus.d etc/linuxmuster/schulkonsole/permissions.d
	dh_installdirs -a var/run

	# Add here commands to install the package into DESTDIR
	mkdir -p $(CURDIR)/debian/tmp
	make install DESTDIR=$(CURDIR)/debian/tmp
	install -d -o www-data -g root -m 700 debian/linuxmuster-schulkonsole/var/lib/schulkonsole

# Build architecture-independent files here.
binary-indep: install
	dh_testdir -i
	dh_testroot -i
	dh_installchangelogs -i
	dh_installdocs -i
	dh_installcron -i
#	dh_installman
	dh_install -i
	dh_lintian -i
	dh_link -i
	dh_compress -i
	dh_fixperms -i -X/var/lib/schulkonsole -X/usr/lib
	dh_perl -i /usr/share/schulkonsole /usr/lib/schulkonsole
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: install
	dh_testdir -a
	dh_testroot -a
	dh_installchangelogs -a
	dh_installdocs -a
#	dh_installman -a
	dh_install --autodest -a $(WRAPPER_BINARIES)
	dh_lintian -a
	dh_link -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a -X/usr/lib $(WRAPPER_PERMS)
	dh_compress -a
	dh_fixperms -a -X/usr/lib $(WRAPPER_PERMS)
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

# We have nothing to do by default.

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