#
# Copyright (c) 2009-2010 Ronald Kluth
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#

all: samples

#---------------------------------------------------------customizable variables

BUILD_DIR = build

SOURCE_DIR = src

# POCO_BASE_DIR = /home/ron/Develop/KDev4Projects/poco.rev.1217
POCO_BASE_DIR = ../../../poco.rev.1094

CXX_DEBUG_FLAGS = -Wall -O0 -g3 -pg -Wno-sign-compare
CXX_RELEASE_FLAGS = -Wall -O3 -Wno-sign-compare

INC_PATHS = \
-I ../../include \
-I $(POCO_BASE_DIR)/Foundation/include \
-I $(POCO_BASE_DIR)/Data/include \
-I $(POCO_BASE_DIR)/Data/SQLite/include \
-I $(POCO_BASE_DIR)/Data/ODBC/include

DEBUG_LIBS = \
-l PocoXMLd \
-l PocoSQLited \
-l PocoODBCd \
-l PocoDatad \
-l PocoFoundationd \
-l odbc \
-l pthread \
-l dl

RELEASE_LIBS = \
-l PocoXML \
-l PocoSQLite \
-l PocoODBC \
-l PocoData \
-l PocoFoundation \
-l odbc \
-l pthread \
-l dl


LIB_PATH = \
-L $(POCO_BASE_DIR)/lib
#-L $(POCO_BASE_DIR)/lib/Linux/x86_64

CXX_FLAGS = $(CXX_RELEASE_FLAGS) 
LIBS = $(RELEASE_LIBS)

#-----------------------------------------------------------------automatic part

# get all sources
VPATH := $(SOURCE_DIR)

# compute targets
TARGETS := $(patsubst $(SOURCE_DIR)/%.cpp, $(BUILD_DIR)/%, $(wildcard $(SOURCE_DIR)/*.cpp))

# create build directory
build_dir:
	@echo "Creating build directory: $(BUILD_DIR)"
	@mkdir -p $(BUILD_DIR)

# a rule to make all samples at once
samples: build_dir $(TARGETS)

# build targets from sources
$(BUILD_DIR)/%: %.cpp
	@echo "Compiling $< to target: $@"
	@$(CXX) $(CXX_FLAGS) $(INC_PATHS) $(LIB_PATH) -o $@ $< $(LIBS)

# clean build by removing
clean:
	@echo "Removing build directory: $(BUILD_DIR)"
	@rm -rf $(BUILD_DIR)
