#  This file is part of YYYSOUND
#  Copyright (C) 1997 Erik Thiele
#  see README for details and contact adresses.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


# Don't forget to do "make clean" after changing this file !!!



# ------------------------------------------------------------------
#                    User configurable area
# ------------------------------------------------------------------

# Code generation mode "debug","quickcompile" or "optimized"
COMPILEMODE = optimized
# Warning handling mode
#   "kick"   -   Generate useless code to avoid warnings
#                Every Warning is an error and stops compilation
#   "final"  -   Create useless warnings
#                Do not stop compilation on warnings
WARNMODE = final

# Options for both C and C++ Compiler
CC_CPPC_OPTIONS =
# Options specific for C Compiler
CC = gcc
CC_OPTIONS =
# Options specific for C++ Compiler
CPPC = g++
CPPC_OPTIONS =
# Options for the linking process
LINK_OPTIONS =
# Options for the stripping process
STRIP = strip
# Options for doc++
DOCPP = doc++
DOCPP_OPTIONS =
# Defines
DEFINES =


# ------------------------------------------------------------------
#            !! Do not change anything below this line !!
# ------------------------------------------------------------------

STATUS = ok

# --------- COMPILEMODE parsing
ifeq ($(COMPILEMODE),debug)
  # debug compile mode
  CC_CPPC_OPTIONS += -O0 -ggdb
  STRIP = @true
else
  ifeq ($(COMPILEMODE),quickcompile)
    # quick compile mode
    STRIP = @true
  else
    ifeq ($(COMPILEMODE),optimized)
      # optimized compile mode
      CC_CPPC_OPTIONS += -O9
    else
      # error
      STATUS = COMPILEMODE is not correctly set in Makefile.
    endif
  endif
endif

# --------- WARNMODE parsing
ifeq ($(WARNMODE),kick)
  # kick warnmode
  DEFINES += -Dkickwarn
  CC_CPPC_OPTIONS += -Wall -Werror
else
  ifeq ($(WARNMODE),final)
    # final warnmode
    CC_CPPC_OPTIONS += -Wall
  else
    # error
    STATUS = WARNMODE ist not correctly set in Makefile
  endif
endif

# --------- General Options setting
DEFINES += -D_REENTRANT
CPPC_OPTIONS += $(CC_CPPC_OPTIONS)
CC_OPTIONS += $(CC_CPPC_OPTIONS)
LINK_OPTIONS += -Wall -Werror
DOCPP_OPTIONS += -G -B banner.html -j -d html

# Erase all implicit rules
.SUFFIXES:

# Declare Targets that are no files
.PHONY: all clean depend configtest documentation compile edit view everything

# Define Target "all"
all: help

# Include dependencies, if available
ifeq (dependfile,$(wildcard dependfile))
include dependfile
endif

# Define Target "compile"
compile: comptest yyys yyytestclient standalone noexcept

# Define Target "depend"
depend:
	-@rm -f dependfile
# *.c
	$(CPPC) -MM *.cpp >dependfile

# Define Target "configtest"
configtest:
ifneq ($(STATUS),ok)
	@echo
	@echo _____________________ ERROR _____________________
	@echo
	@echo $(STATUS)
	@echo _________________________________________________
	@echo
	@false
endif
	@echo Configuration correct.

# Define Target "help"
help:
	@echo 1. make configtest
	@echo 2. make clean
	@echo 3. make depend
	@echo 4. make compile
	@echo 5. make documentation
	@echo optional make edit, make view
	@echo alternative: make everything

# Define Compilation Rules
%.o: %.c
	$(CC) $(CC_OPTIONS) $(DEFINES) -c $< -o $@

%.o: %.cpp
	$(CPPC) $(CPPC_OPTIONS) $(DEFINES) -c $< -o $@

# Define the Object File Collections of the various programs
yyysOBJ = yyys.o sampleholder.o fatal.o sounddevice.o soundserver.o \
          yyylownet.o waechter.o parser.o datei.o yyythread.o
yyysLIB = -lpthread

comptestOBJ = comptest.o fatal.o yyythread.o sampleholder.o datei.o parser.o
comptestLIB = -lpthread

yyytestclientOBJ = yyytestclient.o yyylownet.o fatal.o datei.o
yyytestclientLIB =

standaloneOBJ = standalone.o fatal.o
standaloneLIB =

noexceptOBJ = noexcept.o yyysound_client_noexception.o
noexceptLIB =

# yyys Linking rule
yyys: $(yyysOBJ)
	$(CPPC) $(LINK_OPTIONS) $(yyysLIB) $^ -o $@
	$(STRIP) $@

comptest: $(comptestOBJ)
	$(CPPC) $(LINK_OPTIONS) $(comptestLIB) $^ -o $@
	$(STRIP) $@

yyytestclient: $(yyytestclientOBJ)
	$(CPPC) $(LINK_OPTIONS) $(yyytestclientLIB) $^ -o $@
	$(STRIP) $@

standalone: $(standaloneOBJ)
	$(CPPC) $(LINK_OPTIONS) $(standaloneLIB) $^ -o $@
	$(STRIP) $@

noexcept: $(noexceptOBJ)
	$(CPPC) $(LINK_OPTIONS) $(noexceptLIB) $^ -o $@
	$(STRIP) $@

documentation:
	$(DOCPP) $(DOCPP_OPTIONS) doc.dxx
	rm html/gifs.db html/dxxgifs.tex html/logo.gif html/HIERjava.html

# Define cleaning rule
clean:
	rm -f $(comptestOBJ) comptest
	rm -f $(yyysOBJ) yyys
	rm -f $(yyytestclientOBJ) yyytestclient
	rm -f $(standaloneOBJ) standalone
	rm -f $(noexceptOBJ) noexcept
	rm -f *.swp *.bak *~ \#*\# dependfile .gdb_history core
	rm -rf doc.ps doc.tex doc.aux doc.toc doc.dvi doc.log html
	rm -f view.ps
	rm -f samples/*~

# Define viewing rule
view:
	mpage -2Hc *.hpp *.cpp >view.ps
	gv -seascape view.ps&

# Define editing rule
edit:
	xemacs *.cpp *.hpp Makefile doc.dxx HOWTORELEASE TODO& 