################################################################################
# File: Makefile                                                               #
################################################################################
# Makefile for the socketcc library object files.  This directory should       #
# contain all of the object files for the library, this Makefile will compile  #
# the source code in ../src to generate these files.                           #
################################################################################
# Written By: Jason But                                                        #
# Copyright:  CTIE - Monash University 2001                                    #
#                                                                              #
# Notes:                                                                       #
#    Version 1.00 - Original Version of module.                                #
################################################################################

################################################################################
# Module compile information                                                   #
################################################################################
# OBJ_FILES   - All object files to be created from corresponding .cpp files   #
#               in ../src.                                                     #
################################################################################
OBJ_FILES = socketexception.o ipaddress.o socketbase.o tcpsockets.o udpsockets.o

################################################################################
# Compiler and associated flags.                                               #
################################################################################
CC = gcc

CFLAGS = -I$/usr/include -Wall -Wstrict-prototypes -O2 -fPIC
EXTRA_CFLAGS =

################################################################################
# Descriptions of certain make tasks.                                          #
################################################################################
DESC_ALL =      "Create .depend file and object files: $(OBJ_FILES)\n"
DESC_COMPILE =  "Create object files: $(OBJ_FILES)\n"
DESC_DEPEND =   "Create .depend file listing object file dependencies.\n"
DESC_CLEAN =    "Remove any files created for a clean install.\n"

################################################################################
# ALL                                                                          #
################################################################################
# If the (.depend) file exists then make all and make module resolves to make  #
# module_compile and the (.depend) file is included, otherwise make all and    #
# make module reruns Make twice, first running make depend and then running    #
# make module_compile.                                                         #
################################################################################
ifeq (.depend, $(wildcard .depend))
all:                    depend compile
include .depend
else
all:                    depend
	$(MAKE) -s compile
endif

################################################################################
# COMPILE                                                                      #
################################################################################
# make compile resolves to making the necessary object files                   #
################################################################################
compile:                pre-compile-info $(OBJ_FILES)
	@echo Object Files Compiled...
	@echo

################################################################################
# make pre-compile-info echos pre-compilation information to the screen.       #
################################################################################
pre-compile-info:
	@echo Making Object Files...

################################################################################
# Standard GCC compiler commands to compile source files.                      #
################################################################################
%.o:                    ../src/%.cpp
	@(                                                                          \
        echo -e "\tCompiling: $< --> $@";                                       \
        $(CC) $(PRE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<; \
    )

################################################################################
# DEPEND                                                                       #
################################################################################
# make dep, fastdepend and depend depends on the .depend file.                 #
################################################################################
dep fastdep depend::    .depend

################################################################################
# make .depend depends on all files in the ../src directory.  We use gcc to    #
# output the dependencies to .tmp which is then copied to .depend.             #
################################################################################
.depend:                ../src/*
	@(                                                                                          \
        echo Generating Dependencies...;                                                        \
        $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -M $(addprefix ../src/,$(OBJ_FILES:.o=.cpp)) > .tmp ;   \
        mv -f .tmp .depend;                                                                     \
        echo                                                                                    \
    )

################################################################################
# CLEAN                                                                        #
# MRPROPER                                                                     #
################################################################################
# Remove any files created for a clean install.                                #
################################################################################
clean mrproper::
	@(                                                                          \
        echo Removing $(OBJ_FILES) and .depend...;                              \
        rm -f *.o *.a .depend;                                                  \
    )

################################################################################
# HELP                                                                         #
################################################################################
# Help messages.                                                               #
################################################################################
HLP_HELP =      "help\tthis screen.\n"
HLP_ALL =       "all\t"$(DESC_ALL)
HLP_COMPILE =   "compile\t"$(DESC_COMPILE)
HLP_DEPEND =    "depend\t"$(DESC_DEPEND)
HLP_CLEAN =     "clean\t"$(DESC_CLEAN)

HLP_COMMANDS = $(HLP_HELP)$(HLP_ALL)$(HLP_COMPILE)$(HLP_DEPEND)$(HLP_CLEAN)

################################################################################
# make help resolves to echoing available make options.                        #
################################################################################
help:
	@echo $(DRIVERNAME) - Makefile
	@echo
	@echo Usage: make [help all compile depend clean]
	@echo
	@echo -e $(HLP_COMMANDS)

################################################################################
# End of File: Makefile                                                        #
################################################################################
