#! /usr/bin/make -f

include /usr/share/cdbs/1/rules/utils.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/scons.mk

DEB_BUILDDIR=common

# Add here any variable or target overrides you need.
DEB_DH_INSTALL_SOURCEDIR=debian/tmp
export CDBS_NO_DOC_SYMLINKING:=1

# Do not enable parallel building: scons cannot handle parallel
# builds when the chdir option is used in any command
# DEB_BUILD_PARALLEL = 1

DEB_INSTALL_DOCS_supercollider             = "README LINUX" common/build/README
DEB_INSTALL_DOCS_supercollider-server      = "README LINUX" common/build/README
DEB_INSTALL_DOCS_supercollider-emacs       = editors/scel/README
DEB_INSTALL_DOCS_supercollider-vim         = editors/scvim/README editors/scvim/SCVim.scd
DEB_INSTALL_CHANGELOGS_ALL                 = common/build/ChangeLog

DEB_INSTALL_MANPAGES_supercollider-server  = debian/scsynth.1
DEB_INSTALL_MANPAGES_supercollider         = debian/sclang.1
DEB_INSTALL_MANPAGES_supercollider-vim     = debian/scvim.1 debian/scvim_make_help.1 debian/sclangpipe_app.1

# recent SVN revisions also install examples to $(DEB_DESTDIR)/usr/share
DEB_INSTALL_EXAMPLES_supercollider         = common/build/examples/*
DEB_INSTALL_DIRS_supercollider             = usr/share/SuperCollider/Extensions

# SCVIM/SCED=0 here, because we install them by hand below
# (so that the build won't break)
# Also STRIP=0 since we let cdbs (dh_strip) decide whether to strip
DEB_SCONS_OPTIONS = DEVELOPMENT=yes PREFIX=/usr CROSSCOMPILE=1 CURL=0 SCVIM=0 SCED=0 STRIP=0
# Handle DEB_BUILD_OPTIONS (see policy 4.9.1)
ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
	DEB_SCONS_OPTIONS += "DEBUG=1"
endif

DEB_SCONS_INSTALL_TARGET = DESTDIR=$(DEB_DESTDIR) install

# The build system apparently can't handle this
CXXFLAGS =

clean:: scons-clean
scons-clean::
	dh_testdir
	scons -C common $(SCONS_FLAGS) --clean scrub
	rm -f common/.sconsign.dblite
	rm -f editors/scvim/.sconsign.dblite
	rm -f editors/sced/.sconsign.dblite
	# also remove some files, that SCons forgets about
	rm -f editors/scel/el/sclang-vars.el
	rm -f linux/libsclang.pc
	rm -f linux/libscplugin.pc
	rm -f linux/libscsynth.pc

common-install-arch common-install-indep:: common-install-impl
common-install-impl::
	scons --install-sandbox=$(DEB_DESTDIR) --directory=editors/scvim PREFIX=/usr VIMFILE_DIR=/usr/share/vim/addons install-all
	scons --install-sandbox=$(DEB_DESTDIR) --directory=editors/sced PREFIX=/usr install
	# fixing some executables in class library and docs for happier lintian
	find $(DEB_DESTDIR)/usr/share/SuperCollider -type d -exec chmod 755 {} \;; \
	find $(DEB_DESTDIR)/usr/share/SuperCollider -type f -exec chmod 644 {} \;; \
	# vim-addon-manager stuff
	install -d $(DEB_DESTDIR)/usr/share/vim/registry
	install -m 644 debian/supercollider-vim.yaml $(DEB_DESTDIR)/usr/share/vim/registry
	# lintian overrides
	install -m 644 debian/README.extensions $(DEB_DESTDIR)/usr/share/SuperCollider/Extensions/README
	# icons and metadata for freedesktop-style menu entries
	install -d $(DEB_DESTDIR)/usr/share/applications
	install -m 644 debian/*.desktop $(DEB_DESTDIR)/usr/share/applications
	install -d $(DEB_DESTDIR)/usr/share/pixmaps
	install -m 644 linux/icons/supercollider.xpm $(DEB_DESTDIR)/usr/share/pixmaps
	install -m 644 linux/icons/supercollider.png $(DEB_DESTDIR)/usr/share/pixmaps

