##########################################################################
# Copyright KAZ 2021							 #
# 									 #
# contact (at) kaz.bzh							 #
# 									 #
# This software is a filter to shrink email by attachment extraction.	 #
# 									 #
# This software is governed by the CeCILL-B license under French law and #
# abiding by  the rules of distribution  of free software. You  can use, #
# modify  and/or  redistribute  the  software under  the  terms  of  the #
# CeCILL-B license as circulated by CEA, CNRS and INRIA at the following #
# URL "http://www.cecill.info".						 #
# 									 #
# As a counterpart to the access to  the source code and rights to copy, #
# modify and  redistribute granted  by the  license, users  are provided #
# only with a limited warranty and  the software's author, the holder of #
# the economic  rights, and the  successive licensors have  only limited #
# liability.								 #
# 									 #
# In this respect, the user's attention is drawn to the risks associated #
# with loading,  using, modifying  and/or developing or  reproducing the #
# software by the user in light of its specific status of free software, #
# that may  mean that  it is  complicated to  manipulate, and  that also #
# therefore means  that it  is reserved  for developers  and experienced #
# professionals having in-depth computer  knowledge. Users are therefore #
# encouraged  to load  and test  the software's  suitability as  regards #
# their  requirements  in  conditions  enabling the  security  of  their #
# systems and/or  data to  be ensured  and, more  generally, to  use and #
# operate it in the same conditions as regards security.		 #
# 									 #
# The fact that  you are presently reading this means  that you have had #
# knowledge of the CeCILL-B license and that you accept its terms.	 #
##########################################################################

# apt-get install g++ make libboost-program-options-dev libboost-system-dev libboost-filesystem-dev libssl-dev

## DIR #################################
SRC_DIR   = ./src
TST_DIR   = $(SRC_DIR)/test
CPP_DIR   = $(SRC_DIR)/cpp
HPP_DIR   = $(SRC_DIR)/include
BLD_DIR   = build
OUT_DIR   = $(BLD_DIR)/out
LIB_DIR   = $(BLD_DIR)/lib
OBJ_DIR   = $(BLD_DIR)/obj

KAZ_PRG = eMailShrinker
KAZ_MOD = eMailShrinker EmbeddedData Attachment MainAttachment SizeArg kazDebug kazMisc
KAZ_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(KAZ_MOD))
KAZ_OBJ = $(patsubst %, $(OBJ_DIR)/%.o, $(KAZ_MOD))
KAZ_OUT = $(patsubst %, $(OUT_DIR)/%, $(KAZ_PRG))

JIR_PRG = jirafeauAPI
JIR_MOD = jirafeauAPI SizeArg kazDebug kazMisc
JIR_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(JIR_MOD))
JIR_OBJ = $(patsubst %, $(OBJ_DIR)/%.o, $(JIR_MOD))
JIR_OUT = $(patsubst %, $(OUT_DIR)/%, $(JIR_PRG))

## FLAGS ###############################

#DFLAGS = -O2 -DDISABLE_LOG
DFLAGS = -g -Wall

IFLAGS = $(DFLAGS) -MMD -I$(HPP_DIR) -std=c++11

LFLAGS = -L$(LIB_DIR) -lboost_system -lboost_program_options -lboost_filesystem -lcurl -lcrypto -lstdc++
CC = g++

## RULES ###############################
$(OBJ_DIR)/%.o: $(SRC_DIR)/*/%.cpp
	$(CC) $< $(IFLAGS) -cpp -c -o $@

## ENTRIES #############################
all:	init eMailShrinker jirafeauAPI doc

eMailShrinker: $(KAZ_OUT)

$(KAZ_OUT): $(KAZ_OBJ)
	$(CC) $(KAZ_OBJ) $(IFLAGS) -cpp -L$(LIB_DIR) $(LFLAGS) -o $@

jirafeauAPI: $(JIR_OUT)

$(JIR_OUT): $(JIR_OBJ)
	$(CC) $(JIR_OBJ) $(IFLAGS) -cpp -L$(LIB_DIR) $(LFLAGS) -o $@

doc:
	doxygen src/Doxyfile

init:
	mkdir -p $(OUT_DIR) $(OBJ_DIR) $(LIB_DIR)

clean:
	find . -type f '(' -name '#*' -o -name '*~' ')' -print -exec rm -f '{}' \;

wipe: clean
	-rm -f src/*.tcpp src/*/*.tcpp
	-rm -rf $(OUT_DIR) $(LIB_DIR) $(BLD_DIR)

## DEPENDS #############################
ALL_OUT = $(KAZ_PRG) $(JIR_PRG)
ALL_OBJ = $(KAZ_OBJ) $(JIR_OBJ)

DEPENDS = ${ALL_OUT:=.d} ${ALL_OBJ:.o=.d}
-include ${DEPENDS}

########################################
