VERSION=0.2.2
CFLAGS= -Wall -Wstrict-prototypes -g

FILES=program message parser broadcast
FILES_O=$(FILES:%=%.o)

GPP= g++ $(CFLAGS)

all: default

default: sapserver

# Main target. Build .o files from every.cpp files and build the final
# executable
sapserver: $(FILES_O) sapserver.cpp sapserver.h
	$(GPP) -o sapserver $(FILES_O) sapserver.cpp -DVERSION=\"$(VERSION)\"

# Target that builds a .o from each .cpp
$(FILES_O): %.o: %.cpp %.h
	$(GPP) -c $*.cpp

# Delete the .o files and the executable
clean:
	rm -f $(FILES_O)
	rm -f sapserver 

# Cleans and remove the dists
distclean: clean
	rm -f miniSAPserver-${VERSION}.tar.bz2
	rm -f miniSAPserver-${VERSION}.tar.gz

# Makes the dists.
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
