VERSION=0.2.0

default: all

all:
	g++ -Wall -c -o program.o program.cpp
	g++ -Wall -c -o message.o message.cpp
	g++ -Wall -c -o parser.o parser.cpp
	g++ -Wall -c -o broadcast.o broadcast.cpp
	g++ -Wall -o sapserver sapserver.cpp message.o parser.o program.o broadcast.o -DVERSION=\"$(VERSION)\"

clean:
	rm -f sapserver message.o program.o parser.o broadcast.o

distclean: clean
	rm -f miniSAPserver-${VERSION}.tar.bz2
	rm -f miniSAPserver-${VERSION}.tar.gz

dist:
	-# Check that tmp isn't in the way
	@if test -e tmp; then \
		echo "Error: please remove ./tmp, it is in the way"; false; \
	else \
	echo "Starting dist's build."; mkdir tmp; \
	fi
	mkdir tmp/miniSAPserver/
	# Copy the Makefile
	cp Makefile tmp/miniSAPserver/
	# Copy the configration file
	cp sap.cfg tmp/miniSAPserver/
	# Copy all headers and source code files
	cp *.cpp *.h tmp/miniSAPserver/
	# Copy AUTHORS and CPYING
	cp AUTHORS COPYING tmp/miniSAPserver/
	# Build archives
	F=miniSAPserver-${VERSION}; \
		mv tmp/miniSAPserver tmp/$$F; (cd tmp ; tar cf $$F.tar $$F); \
		bzip2 -f -9 < tmp/$$F.tar > $$F.tar.bz2; \
		gzip -f -9 tmp/$$F.tar ; mv tmp/$$F.tar.gz .
	# Clean up
	rm -Rf tmp
