# Base directory to install to
PREFIX?=/usr/local/lib/gkrellm2/plugins

# Include debugging symbols in output (stripped when doing "make install")
CXXFLAGS+=-g

# Warn about a lot of things (probably g++ specific parameters)
WARNS=-Wall -W -Wpointer-arith -Wcast-align -Wconversion

# Build position independent code (i.e. shared library)
CXXFLAGS+=-fPIC

# GTK includes and libs
GTK_INCLUDES=`pkg-config --cflags gtk+-2.0`
GTK_LIBS=`pkg-config --libs gtk+-2.0`


# These are our sources
SRCS=\
wmium-gk2.cc \
DataUpdater.cc \
NetworkManager.cc \
../src/ERegEx.cc \
../src/FDHolder.cc \
../src/FDSet.cc \
../src/HistoryDataHandler.cc \
../src/Request.cc \
../src/SimpleCalendar.cc \
../src/SSLClientSocket.cc \
../src/SSLPtr.cc \
../src/SSL_CTXPtr.cc \
../src/SampleTransformer.cc \
../src/SpeedDataHandler.cc \
../src/StatsFetcher.cc \
../src/UsageDataHandler.cc \


# And here we create their .o counterpart names
OBJS=$(SRCS:.cc=.o)

# And these are the libs we need to link against, OpenSSL & crypto libs
LIBS=-lssl -lcrypto

# Here are the various targets, nothing fancy at all...

.SUFFIXES: .cc .o .so

.cc.o:
	$(CXX) $(CXXFLAGS) $(WARNS) $(GTK_INCLUDES) -I../src -c $< -o $@

.PHONY=build-gk2 clean cleandepend cleanall depend install-gk2 all wmium-gk2

all: wmium-gk2
build-gk2: wmium-gk2

wmium-gk2.so: $(OBJS)
	$(CXX) $(CXXFLAGS) $(OBJS) $(GTK_LIBS) $(LIBS) -shared -o $@

wmium-gk2: wmium-gk2.so
	@echo "" && echo "Build complete. Use 'make install-gk2' to install."
	@echo ""
	@echo "Current install path is $(PREFIX), set PREFIX to override."
	@echo 'Example: make PREFIX=$$HOME/.gkrellm2/plugins install-gk2'
	@echo ""

depend:
	makedepend -f .depend -- $(CXXFLAGS) -- $(SRCS)

clean:
	@-rm $(OBJS) *.so 2>/dev/null

cleandepend:
	@-cp /dev/null .depend

cleanall: clean cleandepend

install-gk2: wmium-gk2.so
	install -d "$(PREFIX)"
	install -s -m 0644 wmium-gk2.so "$(PREFIX)/"
	@echo ""
	@echo "Installation complete."
	@echo ""
	@echo "When you start up gkrellm2 next, you will need to enable the Internode plugin (press F1 and select the plugin options)."
	@echo ""
	@echo "This plugin uses its built-in configuration mechanism, and does not rely on ~/.wmiumrc. You will need to specify your DSL username and password in the plugin configuration options before things start working, obviously :)"
	@echo ""


# Include the dependencies file explicitly
include .depend

