#Copyright (C) 2010 Simon Kiertscher
#
#This program is free software; you can redistribute it and/or modify it 
#under the terms of the GNU General Public License as published by the 
#Free Software Foundation; either version 3 of the License, or (at your option) 
#any later version.
#
#This program 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 General Public License for more details.
#
#You should have received a copy of the GNU General Public License along with 
#this program; if not, see <http://www.gnu.org/licenses/>.
# prefix

PREFIX=/usr

# python version
PYTHONVERSION=2.7

# directories
SYSCONFDIR=/etc
SBINDIR=$(PREFIX)/sbin
INCLUDEDIR=$(PREFIX)/include
LIBDIR=$(PREFIX)/lib

# command line tools
INSTALL=install
UPDATE=update
RM=rm -rf

# compiler and flags
CC=gcc
FLAGS= -lpython$(PYTHONVERSION)  -ldl -lrt -lpthread -lutil -lm -Wall -W -g -O0

all: compile

compile: cherub.c cherub_api.c cherub_test.c
	$(CC) $^ -I$(INCLUDEDIR)/python$(PYTHONVERSION) -L$(LIBDIR)/python$(PYTHONVERSION) $(FLAGS) -o cherub

run:
	./cherub
	
runverbose:
	./cherub -v

install:
	$(INSTALL) -m0755 cherub $(SBINDIR)
	$(INSTALL) -m0644 cherub_config.py $(SYSCONFDIR)
	$(INSTALL) -m0644 cherubim_script_*.py $(LIBDIR)/python$(PYTHONVERSION)/site-packages
	#python setup.py install

update:
	$(INSTALL) -m0755 cherub $(SBINDIR)
	$(INSTALL) -m0644 cherubim_script_*.py $(LIBDIR)/python$(PYTHONVERSION)/site-packages

uninstall:
	$(RM) $(SBINDIR)/cherub
	$(RM) $(SYSCONFDIR)/cherub.conf
	$(RM) $(LIBDIR)/python$(PYTHONVERSION)/site-packages/cherubim_script_*.py	
	#python setup.py uninstall

clean:
	$(RM) *.o

mrproper:	clean
	$(RM) cherub_test
	$(RM) cherub_api
	$(RM) cherub

.PHONY: all test compile run testrun clean mrproper install uninstall
