# Makefile

VERSION=$(shell grep package_version src/version.h | cut -f2)

all: 
	cd src ; $(MAKE)

install: 
	if [ ! -f bin/smsd ]; then echo 'Please run "make compile" first.'; exit 1; fi;
	echo "Installing"
	echo "- binaries"
	cp bin/smsd* bin/getsms* bin/putsms* /usr/local/bin
	echo "- scripts"
	if [ ! -f /usr/local/bin/smsevent ]; then cp bin/smsevent /usr/local/bin; else echo "  skipped smsevent"; fi
	if [ ! -f /usr/local/bin/mysmsd ]; then cp bin/mysmsd /usr/local/bin; else echo "  skipped mysmsd"; fi
	if [ ! -f /usr/local/bin/email2sms ]; then cp bin/email2sms /usr/local/bin; else echo "  skipped email2sms"; fi
	if [ ! -f /usr/local/bin/sendsms ]; then cp bin/sendsms /usr/local/bin; else echo "  skipped sendsms"; fi
	echo "- config files"
	if [ ! -f /etc/smsd.conf ]; then cp examples/smsd.conf.easy /etc; else echo "  skipped smsd.conf"; fi
	if [ ! -f /etc/smsd.black ]; then cp examples/smsd.black /etc; else echo "  skipped smsd.black"; fi
	if [ ! -f /etc/smsd.white ]; then cp examples/smsd.white /etc; else echo "  skipped smsd.white"; fi
	echo "- startup script"
	if [ -d /etc/init.d ]; then cp bin/sms /etc/init.d; else mkdir /etc/init.d; cp bin/sms /etc/init.d; fi;
	if [ -d /sbin/init.d ]; then cp  bin/sms /sbin/init.d; fi;
	echo "- queue directories"
	if [ ! -d /var/spool/sms ]; then mkdir /var/spool/sms; fi;
	if [ ! -d /var/spool/sms/incoming ]; then mkdir /var/spool/sms/incoming; chmod 777 /var/spool/sms/incoming; fi;
	if [ ! -d /var/spool/sms/outgoing ]; then mkdir /var/spool/sms/outgoing; chmod 777 /var/spool/sms/outgoing; fi;
	if [ ! -d /var/spool/sms/OTHER ]; then  mkdir /var/spool/sms/OTHER; chmod 700 /var/spool/sms/OTHER; fi;
	echo Installation finished
	echo 'Please dont forget to edit /etc/smsd.conf and create the provider queue directories.'

clean:
	cd src ; make clean
	rm -f bin/getsms bin/putsms bin/smsd

compile:
	cd src ; $(MAKE)

package: clean
	chmod -R a+rX *
	cd ..;tar -chzf smstools/doc/html/packages/smstools-$(VERSION).tar.gz --exclude=smstools/doc/html/packages smstools
	cp doc/html/packages/smstools-$(VERSION).tar.gz doc/html/packages/smstools.tar.gz
	rm "../../buecher/SMS Anwendungen/CD/Windows/SMS Server Tools/smstools"*.tar.gz
	cp "doc/html/packages/smstools-$(VERSION).tar.gz" "../../buecher/SMS Anwendungen/CD/Windows/SMS Server Tools"
	rm "../../buecher/SMS Anwendungen/CD/Linux/Source/smstools"*.tar.gz
	cp "doc/html/packages/smstools-$(VERSION).tar.gz" "../../buecher/SMS Anwendungen/CD/Linux/Source"
	rm "../../buecher/SMS Anwendungen/CD/Solaris6/Source/smstools"*.tar.gz
	cp "doc/html/packages/smstools-$(VERSION).tar.gz" "../../buecher/SMS Anwendungen/CD/Solaris6/Source"
	rm "../../buecher/SMS Anwendungen/CD/Solaris7/Source/smstools"*.tar.gz
	cp "doc/html/packages/smstools-$(VERSION).tar.gz" "../../buecher/SMS Anwendungen/CD/Solaris7/Source"
	rm "../../buecher/SMS Anwendungen/CD/Solaris8/Source/smstools"*.tar.gz
	cp "doc/html/packages/smstools-$(VERSION).tar.gz" "../../buecher/SMS Anwendungen/CD/Solaris8/Source"
	rm "../../buecher/SMS Anwendungen/CD/Solaris9/Source/smstools"*.tar.gz
	cp "doc/html/packages/smstools-$(VERSION).tar.gz" "../../buecher/SMS Anwendungen/CD/Solaris9/Source"


