#Makefile for C alice
OBJECTS = alice_stuff.o alice_core.o alice_preproc.o alice_respond.o
CGI_OBJECTS = cgi_main.o
#IRC_OBJECTS = irc_net.o irc_main.o alice_gadgets.o
PLAIN_OBJECTS = plain_main.o alice_gadgets.o
COMMAND_OBJECTS = alice_gadgets.o command_main.o
TCP_OBJECTS=mts_server.o mts_connection.o
LIBS = -lnsl
SUNLIBS = -lsocket -lnsl
FLAGS = -Wall -g
CC = g++
OS = $(shell uname -s)
DIST =

help :
	@echo "This makefile supports the following:"
	@echo "make all - creates all executables."
	@echo "make command - creates the command line version of alice."
	@echo "make plain - creates the single user version of alice."
	@echo "make cgi - creates the cgi-version."
#	@echo "make irc - creates the irc version."
	@echo "make tcp - creates the tcp c/s version."
	@echo "make clean - deletes *.o binary and core files."
	@echo "make help - duh, your reading it."
	@echo "make install DIST=installdir - This installs all compiled"
	@echo "  versions of alice compiled to the installdir."

install : *alice
ifeq ($(DIST),)
	@echo "Error, you must do 'make install DIST=installdir'"
	@echo "For example : 'make install DIST=~/Alice"
else
	- mkdir -p $(DIST)
	cp -f *alice irc_alice.pl irc_alice.tcl $(DIST)
	- cp -r ../aiml/ $(DIST)/aiml
	- cp -r ../data/ $(DIST)/data
	- cp -r ../log/ $(DIST)/log
	- cp -r ../text/ $(DIST)/text
endif

clean :
	- rm -f *.o core plain_alice irc_alice cgi_alice command_alice TCP_Alice TCP_Client

#all : cgi irc plain command

all : cgi plain command tcp

command : $(OBJECTS) $(COMMAND_OBJECTS)
	$(CC) $(FLAGS) $(OBJECTS) $(COMMAND_OBJECTS) -o command_alice

cgi : $(OBJECTS) $(CGI_OBJECTS)
	$(CC) $(FLAGS) $(OBJECTS) $(CGI_OBJECTS) -o cgi_alice

plain : $(OBJECTS) $(PLAIN_OBJECTS)
	$(CC) $(FLAGS) $(OBJECTS) $(PLAIN_OBJECTS) -o plain_alice

#irc : $(OBJECTS) $(IRC_OBJECTS)
#ifeq ($(OS),SunOS)
#	$(CC) $(FLAGS) $(OBJECTS) $(IRC_OBJECTS) -o irc_alice $(SUNLIBS)
#else
#	$(CC) $(FLAGS) $(OBJECTS) $(IRC_OBJECTS) -o irc_alice $(LIBS)
#endif

plain_main.o : plain_main.cpp
	$(CC) $(FLAGS) -c plain_main.cpp

command_main.o : command_main.cpp
	$(CC) $(FLAGS) -c command_main.cpp

cgi_main.o : cgi_main.cpp
	$(CC) $(FLAGS) -c cgi_main.cpp

#irc_net.o : irc_net.cpp
#	$(CC) $(FLAGS) -c irc_net.cpp

#irc_main.o : irc_main.cpp
#	$(CC) $(FLAGS) -c irc_main.cpp

alice_respond.o : alice_respond.cpp
	$(CC) $(FLAGS) -c alice_respond.cpp

alice_preproc.o : alice_preproc.cpp
	$(CC) $(FLAGS) -c alice_preproc.cpp

alice_core.o : alice_core.cpp
	$(CC) $(FLAGS) -c alice_core.cpp

alice_gadgets.o : alice_gadgets.cpp
	$(CC) $(FLAGS) -c alice_gadgets.cpp

alice_stuff.o : alice_stuff.cpp
	$(CC) $(FLAGS) -c alice_stuff.cpp


tcp	: $(OBJECTS) $(TCP_OBJECTS) alice_gadgets.o 
	$(CC) $(FLAGS) $(OBJECTS) $(TCP_OBJECTS) -lpthread -lc_nonshared \
	alice_gadgets.o tcp_alice_server.cpp -o TCP_Alice
	$(CC) $(FLAGS) $(OBJECTS) alice_gadgets.o tcp_alice_client.cpp -o TCP_Client

mts_server.o: mts_server.cpp mts_server.h
	g++ -Wall -O2 -c mts_server.cpp

mts_connection.o: mts_connection.cpp mts_connection.h
	g++ -Wall -O2 -c mts_connection.cpp
