#================================ rand =================================
#Name: rand
#e-mail: gulyan89@yahoo.com
#Start date: 30 November - 2008
#
#Copyright (c)  2008		Guduleasa Alexandru Ionut
#				<gulyan89@yahoo.com>
#
#
#    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/>.

CC=gcc
package=rand
#`cat src/rand.c | grep -i "^#define" | grep VERSION | cut -d '"' -f 2`
version=1.0.4
CFLAGS=-Wall -O2
prefix=/usr/bin
mandir=/usr/share/man

test:
	$(CC) -c src/$(package).c -Wall
	$(CC) -o $(package) $(package).o

build:
	$(CC) -c src/$(package).c -Wall
	$(CC) -o $(package) $(package).o $(CFLAGS)

install:isroot build man clean
	@#copy the program
	mv $(package) $(prefix)/$(package)
	chmod +x $(prefix)/$(package)
	@#copy manual
	mv $(package).1.gz $(mandir)/man1/$(package).1.gz
	@echo "......................\nInstalled successfully";

man:
	gzip -9 -c debian/$(package).1 > $(package).1.gz

tarball:clean
	tar -czvf ../$(package)-$(version).tar.gz --exclude .bzr ../$(package)
	@echo "........................\n$(package)_$(version).tar.gz created";

orig:clean
	tar -czvf ../$(package)_$(version).orig.tar.gz --exclude .bzr --exclude debian ../$(package)
	@echo "........................\n$(package)_$(version).orig.tar.gz created";

remove: isroot
	@#remove the program
	rm -f $(prefix)/$(package)
	@#remove manual
	rm -f $(mandir)/man1/$(package).1.gz

uninstall:isroot isinstaled remove
	@echo "........................\nUninstalled successfully";

clean:
	rm -f *.o *~ src/*~ debian/*~
	@echo "Project is now clean";

isroot:
	@(bash -c 'if test 0 -ne $$UID;then echo "Bad UID($$UID), user must be root.";exit 1;else echo "User is root.";fi');

isinstaled:
	@(bash -c 'if test -f $(prefix)/$(package); then echo "Unsintalling...";else echo -e "Program is not installed\nUser target <remove> to force removal of any residual files.";exit 1;fi');

.PHONY: isroot install unisntall remove 

