############################################################################################################################################## 
# libgtkol Makefile
# 
# - GTKOL - Gtk Object Layer -
# Copyright (C) 2006 Hervé Commowick, Michael Aubertin, 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, may be redefined on command line "make prefix=/usr/local/lib install"
prefix	       = /usr

# target library name and version
NAME	      = libgtkol
VERSION       = 1.4

# preprocessor directives -D
DEFINES       := 
DEBUG	      := 

# library dependencies
LIBS          := `pkg-config --libs libgenerics-1.2`
LIBS	      += `pkg-config --libs gtk+-2.0`
LIBS	      += `pkg-config --libs gthread-2.0`

# include paths
INCLUDES      := ./include
INCLUDEDEPS   := `pkg-config --cflags libgenerics-1.2`
INCLUDEDEPS   += `pkg-config --cflags gtk+-2.0`

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

# file objects to be linked into target library
PKGOBJS        = cgraphics.o				\
		 citemfieldvalue.o			\
		 ccomponent.o				\
		   capplication.o			\
		   ccontrol.o				\
		     cwidget.o				\
		       ccombobox.o			\
			 ccomboboxentry.o		\
		       cseparator.o			\
			 chseparator.o			\
			 cvseparator.o			\
		       cimage.o				\
		       cprogressbar.o			\
		       clabel.o				\
		       centry.o				\
			 cspinbutton.o			\
		       crange.o				\
			cscale.o			\
		         chscale.o			\
		         cvscale.o			\
		       ccontainer.o			\
			 cform.o			\
			   cdialog.o			\
			     cmessagedialog.o		\
			     cfiledialog.o		\
			       cfilechooserdialog.o	\
			     caboutdialog.o		\
			 cmenu.o			\
			 cnotebook.o			\
			 cbutton.o			\
			   ctogglebutton.o		\
			     ccheckbutton.o		\
			       cradiobutton.o		\
			   ccolorbutton.o		\
			   cfontbutton.o		\
			 cexpander.o			\
			 ctreeview.o			\
			 cscrollview.o			\
			 ctextview.o			\
			 cframe.o			\
		    	 clayout.o			\
			   cboxlayout.o			\
			     chboxlayout.o		\
			       cstatusbar.o		\
			     cvboxlayout.o		\
			   cpaned.o			\
			     chpaned.o			\
			     cvpaned.o			\
			   ctablelayout.o		\
			   ctoolbar.o			\
			   ciconview.o			

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

# 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 "[CC] $<"
	@$(CC) $(FLAGS) -c $<

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

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

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

# uninstall request
uninstall :
	rm -rf ${prefix}/$(NAME)-$(VERSION)*

# clean request
clean :
	@echo -n "Cleaning $(TARGETS) *.o *~ *.xml $(SAMPLETARGETS) ${prefix}/share/gtk-doc/html/$(NAME)-$(VERSION) "
	@rm -rf $(TARGETS) *.o *~ *.xml ./source/*~ ./include/*~ ./samples/*~ $(SAMPLETARGETS)
	@rm -rf ${prefix}/share/gtk-doc/html/$(NAME)-$(VERSION)
	@echo done.


####################
# samples build in #
####################

SAMPLES       := ./samples
SAMPLELIBS     = ./$(NAME)-$(VERSION).so
SAMPLETARGETS  = gtkol-hello-world gtkol-dump gtkol-popup gtkol-dnd gtkol-treeview 

samples: $(SAMPLETARGETS)

gtkol-hello-world : $(SAMPLES)/gtkol-hello-world.c
	@echo "building sample $@"
	@$(CC) $(FLAGS) -o $@ $(FLAGS) $< $(SAMPLELIBS) $(LIBS)
gtkol-popup : $(SAMPLES)/gtkol-popup.c
	@echo "building sample $@"
	@$(CC) $(FLAGS) -o $@ $(FLAGS) $< $(SAMPLELIBS) $(LIBS)
gtkol-dump: $(SAMPLES)/gtkol-dump.c
	@echo "building sample $@"
	@$(CC) $(FLAGS) -o $@ $(FLAGS) $< $(SAMPLELIBS) $(LIBS)
gtkol-dnd : $(SAMPLES)/gtkol-dnd.c
	@echo "building sample $@"
	@$(CC) $(FLAGS) -o $@ $(FLAGS) $< $(SAMPLELIBS) $(LIBS)
gtkol-treeview : $(SAMPLES)/gtkol-treeview.c
	@echo "building sample $@"
	@$(CC) $(FLAGS) -o $@ $(FLAGS) $< $(SAMPLELIBS) $(LIBS)
gtkol-paned: $(SAMPLES)/gtkol-paned.c
	@echo "building sample $@"
	@$(CC) $(FLAGS) -o $@ $(FLAGS) $< $(SAMPLELIBS) $(LIBS)

