#
#  Copyright (C) 2004, 2005 Ingo Berg
#
#  Permission is hereby granted, free of charge, to any person obtaining a 
#  copy of this software and associated documentation files (the "Software"), 
#  to deal in the Software without restriction, including without limitation 
#  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
#  and/or sell copies of the Software, and to permit persons to whom the 
#  Software is furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included 
#  in all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
#  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
#  DEALINGS IN THE SOFTWARE. 
#

CC	=	g++

#Release Version
#CFLAGS	=	-mcpu=pentium -O3 -ffast-math -fomit-frame-pointer -fexpensive-optimizations

#Debug-Version
CFLAGS	=	-g -Wall 

DIR_SRC      = ../ParserLib
DIR_APP      = ../Example1
OBJ_LIB      = 	$(DIR_SRC)/muParser.o \
                $(DIR_SRC)/muParserInt.o \
                $(DIR_SRC)/muParserBase.o \
                $(DIR_SRC)/muParserTest.o \
                $(DIR_SRC)/muParserError.o \
                $(DIR_SRC)/muParserCallback.o \
                $(DIR_SRC)/muParserTokenReader.o \
                $(DIR_SRC)/muParserBytecode.o

OBJ_APP	     =  $(DIR_APP)/Example1.o
TARGET_MAIN  =	example
TARGET_LIB   =  muParser

LIBS	     =  -L. -lm -l$(TARGET_LIB) 
INCDIR	     =  -I. -I../ParserLib

###  Parser - list of targets ###################################################

all:	$(TARGET_MAIN) 

###  Parser - main compile targets  #############################################

splash_main:
	@echo ""
	@echo "Creating muParser main"
	@echo "----------------------"
	@echo ""

$(TARGET_MAIN):	splash_main $(TARGET_LIB) $(OBJ_APP)
	$(CC) $(CFLAGS) -o $@ $(OBJ_APP) $(INCDIR) $(LIBS)
	@rm -f $(OBJ_APP)
	@rm -f $(TARGET_LIB)


###  Parser - library  ##########################################################
#
# generate the parser library
#

splash_lib:
	@echo ""
	@echo "Creating muParser library";
	@echo "-------------------------"
	@echo ""

		
$(TARGET_LIB): splash_lib $(OBJ_LIB)
	@ar ru lib$(TARGET_LIB).a $(OBJ_LIB)
	@ranlib lib$(TARGET_LIB).a
	@rm -f $(OBJ_LIB)
	


###  Parser - secondary compile targets #########################################

%.o:	%.cpp
	$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@

clean:
	@echo -n "cleaning up..."	
	@rm -f $(TARGET_MAIN) $(TARGET_LIB) *.[ao] *~ &> /dev/null
	@rm -f DEADJOE core &> /dev/null
	@rm -f $(OBJ_LIB)
	@rm -f $(OBJ_APP)
	@echo    "done"

new:	
	$(MAKE) clean
	$(MAKE) $(TARGET_MAIN)
