# @package		hubzero-vncproxy2
# @file			Makefile
# @author		Nicholas J. Kisseberth <nkissebe@purdue.edu>
# @copyright	Copyright (c) 2011 Purdue University. All rights reserved.
# @license		http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
#
# Copyright (c) 2011 Purdue University
# All rights reserved.
#
# This file is part of: The HUBzero(R) Platform for Scientific Collaboration
#
# The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
# software: you can redistribute it and/or modify it under the terms of
# the GNU Lesser General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# HUBzero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# HUBzero is a registered trademark of Purdue University.
#

INSTDIR=$(DESTDIR)/usr/lib
BASEDIR=$(DESTDIR)
OWNER=root
GROUP=root

all: vncproxy2 vncproxy2-helper

clean:
	rm -f vncproxy2.o vncproxy2-helper.o a.out vncproxy2 vncproxy2-helper

vncproxy2-helper: vncproxy2.c
	cc -g -D_LARGEFILE64_SOURCE -I/usr/include/apr-1.0 vncproxy2.c -L/usr/lib/debug/usr/lib -lapr-1 -laprutil-1 -o vncproxy2-helper

vncproxy2: vncproxy2.c
	cc -g -D_LARGEFILE64_SOURCE -I/usr/include/apr-1.0 vncproxy2.c -L/usr/lib/debug/usr/lib -lapr-1 -laprutil-1 -o vncproxy2

install: vncproxy2 vncproxy2-helper
	#mkdir -p /usr/lib/hubzero/bin
	install -d $(INSTDIR)/hubzero --owner $(OWNER) --group $(GROUP) --mode 0755
	install -d $(INSTDIR)/hubzero/bin --owner $(OWNER) --group $(GROUP) --mode 0755
	#rm -f /usr/lib/hubzero/bin/vncproxy2
	rm -f $(INSTDIR)/hubzero/bin/vncproxy2
	#rm -f /usr/lib/hubzero/bin/vncproxy2-helper
	rm -f $(INSTDIR)/hubzero/bin/vncproxy2-helper
	#cp vncproxy2 /usr/lib/hubzero/bin/vncproxy2
	install vncproxy2 $(INSTDIR)/hubzero/bin/vncproxy2 --owner $(OWNER) --group $(GROUP) --mode 0755
	#cp vncproxy2-helper /usr/lib/hubzero/bin/vncproxy2-helper
	install vncproxy2-helper $(INSTDIR)/hubzero/bin/vncproxy2-helper --owner $(OWNER) --group $(GROUP) --mode 0755
	#cp vncproxy2.rc /etc/init.d/vncproxy2
	install -d $(BASEDIR)/etc --owner $(OWNER) --group $(GROUP) --mode 0755
	install -d $(BASEDIR)/etc/init.d --owner $(OWNER) --group $(GROUP) --mode 0755
	install -d $(BASEDIR)/etc/default --owner $(OWNER) --group $(GROUP) --mode 0755
	install vncproxy2.rc $(BASEDIR)/etc/init.d/vncproxy2 --owner $(OWNER) --group $(GROUP) --mode 0700
	#chmod +x /etc/init.d/vncproxy2
	#chmod +x /usr/lib/hubzero/bin/vncproxy2
	#chmod +x /usr/lib/hubzero/bin/vncproxy2-helper
	if [ ! -e /etc/default/vncproxy2 ] ; then install vncproxy2.defaults $(BASEDIR)/etc/default/vncproxy2 --owner $(OWNER) --group $(GROUP) --mode 0644 ; fi

stop:
	/etc/init.d/vncproxy2 stop

reload: stop install
	/etc/init.d/vncproxy2 restart
