############################################################################################################################################## 
# libgenerics Makefile
# 
# - GTKOL - Gtk Object Layer foundations -
# Copyright (C) 2005 Jérémie Bernard
#
# This library 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 library 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 library; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
############################################################################################################################################## 

########################
# constant definitions #
########################

# installation target directory
prefix	       = /usr/local

# target library name and version
NAME	      = libgenerics
VERSION       = 1.2

# preprocessor directives -D
DEFINES       := 

# include paths
INCLUDES      := ./include
INCLUDES      += `pkg-config --cflags libxml-2.0`

# libs
LIBS	      := `pkg-config --libs libxml-2.0`

# source files directory to compile
SOURCES	      := ./source

# file objects to be linked into target library
PKGOBJS        = cstring.o			\
		 cmetaclass.o 			\
		 cclass.o 			\
		   cexception.o			\
		   cfile.o			\
		   cxml.o			\
		   cchunk.o			\
		     carchive.o			\
		   cmetamoduleimporter.o	\
		   cserialized.o 		\
		     cmetamodule.o		\
		       cobject.o			

# gcc directives
CC 	       = c++
FLAGS 	       = -Wno-multichar -O2 $(DEFINES) -I$(INCLUDES)

# makefile targets (shared and static libraries) 
TARGETS        = $(NAME)-$(VERSION).so $(NAME)-$(VERSION).a

#################
# Makefile body #
#################

# main targets
all : $(TARGETS)

# generic rules
%.o : $(SOURCES)/%.c
	@echo "Compiling $<"
	@$(CC) $(FLAGS) -c $<

# shared library target 
$(NAME)-$(VERSION).so : $(PKGOBJS)
	@echo "Linking shared library $@"
	@$(CC) -shared $(FLAGS) $^ -o $@ $(LIBS) -ldl

# static library target 
$(NAME)-$(VERSION).a : $(PKGOBJS)
	@echo "Linking static library $@"
	@ar cr  $(NAME)-$(VERSION).a $^
	@ranlib $(NAME)-$(VERSION).a

# install request
install :
	mkdir -p ${prefix}/lib/$(NAME)-$(VERSION)/include
	mkdir -p ${prefix}/share/gtk-doc/html/$(NAME)-$(VERSION)
	install -m 644 $(INCLUDES)/* ${prefix}/lib/$(NAME)-$(VERSION)/include
	install -m 755 $(NAME)-$(VERSION).so ${prefix}/lib
	install -m 644 $(NAME)-$(VERSION).a  ${prefix}/lib
	install -m 644 ./$(NAME)-$(VERSION).pc.in /usr/lib/pkgconfig/$(NAME)-$(VERSION).pc
	install -m 644 ./doc/* ${prefix}/share/gtk-doc/html/$(NAME)-$(VERSION)

# uninstall request
uninstall :
	rm -rf ${prefix}/$(NAME)-$(VERSION)* /usr/lib/pkgconfig/$(NAME)-$(VERSION).pc ${prefix}/share/gtk-doc/html/$(NAME)-$(VERSION)

# clean request
clean :
	@echo -n "Cleaning $(TARGETS) *.o *~ $(SAMPLETARGETS) *.xml "
	@rm -rf exe $(TARGETS) *.o *~ include/*~ source/*~ $(SAMPLETARGETS) *.xml
	@echo done.


#######################
# libgenerics samples #
#######################

SAMPLES	      := ./samples
SAMPLELIBS     = `pkg-config --libs libgenerics-1.2`
SAMPLETARGETS  = szd-base szd-object szd-mixed xml-reader

samples: $(SAMPLETARGETS)

szd-base: $(SAMPLES)/serialize/main.szd-base.c
	@echo "building sample $@"
	@$(CC) $(FLAGS) -o $@ $(FLAGS) $< $(SAMPLELIBS) 
szd-object: $(SAMPLES)/serialize/main.szd-object.c
	@echo "building sample $@"
	@$(CC) $(FLAGS) -o $@ $(FLAGS) $< $(SAMPLELIBS)
szd-mixed: $(SAMPLES)/serialize/main.szd-mixed.c
	@echo "building sample $@"
	@$(CC) $(FLAGS) -o $@ $(FLAGS) $< $(SAMPLELIBS)
xml-reader: $(SAMPLES)/xml/xml-reader.c
	@echo "building sample $@"
	@$(CC) $(FLAGS) -o $@ $(FLAGS) $< $(SAMPLELIBS)




