###############################################################################
# Makefile - designed to work on windows nt and all unix variants
#
# This Makefile assumes:
#
#    (a) You are using gnu make, even if you are on windows nt
#    (b) g++ version >= 2.8.1 on unix
#    (c) MS VC++ version >= 5.0 on windows nt
###############################################################################

include ../../directories.inc

###############################################################################
# Debug or Release?
###############################################################################

ifeq "${RELEASE}" "1"
   MODE := release
else
   MODE := debug
endif

###############################################################################
# Are we on windows?
###############################################################################

ifeq "${OS}" "Windows_NT"
   PLATFORM := winnt
else
   PLATFORM := ${shell uname}
endif

LIBRARY := libpersist_${MODE}.a

ifeq "${PLATFORM}" "winnt"

   ifeq "${MODE}" "release"
      OPTIMIZE := -O2
   else
      OPTIMIZE := -Zi
   endif

   PLATFORM_INCLUDE := -I${WINDOWS_VC_INCLUDE}
   CPP              := cl
   WARN             := -W3
   OUT1             :=
   OUT2             := -Fo
   MKLIB            := lib /out:${LIBRARY}
   RM               := del
else

###############################################################################
# Unix settings ...
###############################################################################

   ifeq "${MODE}" "release"
      OPTIMIZE := -O2
   else
      OPTIMIZE := -g
   endif

   CPP      := g++
   WARN     := -W -Wall
   OUT1     := -o
   OUT2     := ${shell echo " "}
   MKLIB    := ar ruv ${LIBRARY}
   RM       := rm

endif

###############################################################################
# Platform-Independent Settings
###############################################################################

INCLUDE    := ${PLATFORM_INCLUDE}
OUT        := ${OUT1}${OUT2}
CPPFLAGS   := -c ${WARN} ${OPTIMIZE} ${INCLUDE}

OBJECTS    := environment_${MODE}.o       \
              fileenvironment_${MODE}.o   \
              filterenvironment_${MODE}.o \
              kvenvironment_${MODE}.o     \
              messagehandler_${MODE}.o    \
              nocaseenvironment_${MODE}.o \
              persist_${MODE}.o

###############################################################################
# Targets
###############################################################################

${LIBRARY}: ${OBJECTS}
	${MKLIB} ${OBJECTS}

release:
	${MAKE} RELEASE=1

debug:
	${MAKE}

%_${MODE}.o:%.cpp
	${CPP} ${CPPFLAGS} ${OUT}$@ $<

clean:
	-${RM} *.a *.o

###############################################################################
# Unix specific targets
###############################################################################

depend:
	@g++ -MM ${INCLUDE} *.cpp | sed 's/\.o/_$${MODE}.o/'

###############################################################################
# Dependencies (generated by: 'make depend >> Makefile'
###############################################################################
environment_${MODE}.o: environment.cpp environment.h
fileenvironment_${MODE}.o: fileenvironment.cpp fileenvironment.h \
 filterenvironment.h environment.h persist.h
filterenvironment_${MODE}.o: filterenvironment.cpp filterenvironment.h \
 environment.h
kvenvironment_${MODE}.o: kvenvironment.cpp kvenvironment.h environment.h
main_${MODE}.o: main.cpp persist.h environment.h kvenvironment.h \
 fileenvironment.h filterenvironment.h nocaseenvironment.h
messagehandler_${MODE}.o: messagehandler.cpp messagehandler.h
nocaseenvironment_${MODE}.o: nocaseenvironment.cpp nocaseenvironment.h \
 filterenvironment.h environment.h
persist_${MODE}.o: persist.cpp persist.h environment.h messagehandler.h
