# Makefile for chatter.
# Created By:
# Benjamin Ranck 
# Manpreet Lehl 
#


#
# VARIABLES:
# 

# General.
SHELL			= /bin/sh

# Compiler.
CC				= gcc
CFLAGS			= -ansi -Wall -g -pedantic

# Project.
CLIENT_EXEC		= chatter
SERVER_EXEC		= schatter
EXECUTABLES		= $(CLIENT_EXEC) $(SERVER_EXEC)

CLIENT_OBJS		= $(CLIENT_EXEC).o
SERVER_OBJS		= $(SERVER_EXEC).o schatter_x.o client.o util.o
OBJECTS			= $(CLIENT_OBJS) $(SERVER_OBJS)


#
# RULES:
# 

# Define PHONY targets, ie: those which aren't actually files to be created.
.PHONY : all client server clean

# Compile all files which make up the project.
all:    $(EXECUTABLES)

# Compile the client component of the project.
client:	$(CLIENT_EXEC)

# Compile the server component of the project.
server:	$(SERVER_EXEC)

# Compile the client executables from their source files.
$(CLIENT_EXEC): $(CLIENT_OBJS)
	$(CC) $(CFLAGS) -o $@ $(CLIENT_OBJS)

# Compile the server executables from their source files.
$(SERVER_EXEC): $(SERVER_OBJS)
	$(CC) $(CFLAGS) -o $@ $(SERVER_OBJS)

# Compile the object file from the source file without linking.
$(OBJECTS): %.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

# Remove all files which can be formed from other files.
clean:
	rm -f $(OBJECTS) $(EXECUTABLES)
		
