#  Authors     [Robert Meolic (meolic@uni-mb.si)]
#  Revision    [$Revision: 27 $]
#  Date        [$Date: 2010-07-22 12:55:07 +0200 (Thu, 22 Jul 2010) $]
#
#  Copyright   [This file is part of Biddy.
#               Copyright (C) 2006, 2007, 2008, 2009, 2010 UM-FERI
#               UM-FERI, Smetanova ulica 17, SI-2000 Maribor, Slovenia
#
#               Biddy 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.
#
#               Biddy 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., 51 Franklin Street, Fifth Floor,
#               Boston, MA 02110-1301 USA.]

# -----------------------------------------------------------------------
# When compiling biddyMain.c you have to use the following switches:
#   MAINFLAGS = -DMINGARBAGE | -DMAXGARBAGE
#   MAINFLAGS = -DMINACC | -DMAXACC
# -----------------------------------------------------------------------

LIBNAME = LIBNAME

MAINFLAGS = -DMINGARBAGE -DMAXACC

OS = $(shell uname | sed "s/_.*//;s/[0-9]//g")

RM = rm -f
CP = cp
MKDIR = mkdir -p

all: dynamic

dynamic: start make_dynamic ok

static: start make_static ok

lib: $(BINDIR) $(BINDIR)/$(LIBNAME)

install:
	$(MKDIR) $(DESTDIR)/lib
	$(MKDIR) $(DESTDIR)/share/biddy
	$(CP) -d $(BINDIR)/lib*.so.* $(DESTDIR)/lib
	$(CP) -d $(BINDIR)/README $(DESTDIR)/share/biddy

installdev:
	$(MKDIR) $(DESTDIR)/lib
	$(MKDIR) $(DESTDIR)/include
	$(CP) -d $(BINDIR)/lib*.so $(DESTDIR)/lib
	$(CP) ./biddy.h $(DESTDIR)/include

# -----------------------------------------------------------------------
# initialization

make_dynamic:
	@$(MAKE) --no-print-directory dynamic -f Makefile.$(OS)
	@$(RM) $(BINDIR)/libbiddy.a

make_static:
	@$(MAKE) --no-print-directory static -f Makefile.$(OS)

# -----------------------------------------------------------------------
# help

start:
	@echo "------------------------------"
	@echo "| Building Biddy package ... |"
	@echo "------------------------------"

ok:
	@echo "---------------------------------------"
	@echo "| Biddy package successfully compiled |"
	@echo "---------------------------------------"

# -----------------------------------------------------------------------
# create a directory for binary files

$(BINDIR):
	$(MKDIR) $(BINDIR)

# -----------------------------------------------------------------------
# make library

$(BINDIR)/biddyMain.o: biddyMain.c biddy.h biddyInt.h
	$(CC) $(MAINFLAGS) -o $(BINDIR)/biddyMain.o -c biddyMain.c -D'BIDDYVERSION="$(BIDDYVERSION)"'

$(BINDIR)/biddyStat.o: biddyStat.c biddy.h biddyInt.h
	$(CC) -o $(BINDIR)/biddyStat.o -c biddyStat.c

$(BINDIR)/$(LIBNAME): $(BINDIR)/biddyMain.o $(BINDIR)/biddyStat.o
	$(LN) $(BINDIR)/$(LIBNAME) $(BINDIR)/biddyMain.o $(BINDIR)/biddyStat.o

# -----------------------------------------------------------------------
# purge = purify source directory, clean = purify bin directory

purge:
	@$(RM) *~
	@$(RM) */*~

clean:
	@$(RM) $(BINDIR)/biddyMain.o
	@$(RM) $(BINDIR)/biddyStat.o
