#MakeFile 
# for compile any pidgin plugin
# By Danilo Lacoste
# danilo@lacosox.org
# www.lacosox.org

CC := gcc
LIBTOOL := libtool

ifeq ($(PREFIX),)
# LIB_INSTALL_DIR = $(PREFIX)/lib/pidgin
 LIB_INSTALL_DIR = /usr/local/lib/pidgin
else
  LIB_INSTALL_DIR = $(HOME)/.purple/plugins
endif

#replace by name.c 
PIDGIN_PLUGIN = Repetidgin

#cflags need for compilation
PIDGIN_CFLAGS = $(shell pkg-config pidgin --cflags)
GTK_CFLAGS = $(shell pkg-config gtk+-2.0 --cflags)

#libflags need for compilation
PIDGIN_LIBS = $(shell pkg-config pidgin --libs)
GTK_LIBS = $(shell pkg-config gtk+-2.0 --libs)

#pidgin libs directory
PIDGIN_LIBDIR  = $(shell pkg-config --variable=libdir pidgin)/pidgin

all: note
	@make compilation

note:
	@echo
	@echo "######### \033[7m\033[1m COMPILING NOTES by Lacosox.org \033[0m #########"
	@echo "--------------------------------------------------------------------------------"
	@echo "You need GTK 2.x and Pidgin 2.x to compile this plugin!"
	@echo " ON LINUX USE MAKE ON BSD USE GMAKE  !!!!!!!!!!!!!!!!!!!!"
	@echo "If there is any errors please contact with me at danilo@lacosox.org"
	@echo    "--------------------------------------------------------------------------------"
	@echo

#compilation
compilation:
	@echo
	@echo "Compiling now..."
	@echo
	@make $(PIDGIN_PLUGIN).so

#making	
$(PIDGIN_PLUGIN).so: $(PIDGIN_PLUGIN).o
	$(CC) -D_FILE_OFFSET_BITS=64 -shared $(CFLAGS) $< -o $@ $(PIDGIN_LIBS) $(GTK_LIBS) -Wl,--export-dynamic -Wl,-soname

	@echo 
	@echo
	@echo  "\033[7m\033[1mCompiling finished\033[0m"
	@echo
	
$(PIDGIN_PLUGIN).o:$(PIDGIN_PLUGIN).c #$(PIDGIN_PLUGIN).h
	$(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -O2 -fPIC -c $< -o $@ $(PIDGIN_CFLAGS) $(GTK_CFLAGS) -DHAVE_CONFIG_H

#do install
install: all
	@echo
	@echo "Installing now..."
	@echo
	mkdir -p $(LIB_INSTALL_DIR)
	cp $(PIDGIN_PLUGIN).so $(LIB_INSTALL_DIR)

#do clean
clean:
	@echo
	@echo Cleaning up...
	rm -rf *.o *.c~ *.h~ *.so *.la .libs
