# This project depends on the following libralies,
# openssl-devel ncurses-devel gdbm-devel.
# You may need to install then.


#If ndbm compatibillity mode isn't enabled on your machine,
#remove the prepended '#' from the following line.
#GDBM_COMPT_OPT = -DGDBM_COMPT

#Option for development
#CFLAGS = -g -Wall -DDEBUG ${CDEF} ${GDBM_COMPT_OPT} 
#Option for release
CFLAGS = -Wall ${CDEF} ${GDBM_COMPT_OPT}

CDEF = -D_REENTRANT -D_XOPEN_SOURCE_EXTENDED 
#-D_XOPEN_SOURCE

OBJS = ${OBJ_DIR}/main.o ${OBJ_DIR}/utils/nt_std_t.o \
    ${OBJ_DIR}/env.o \
    ${OBJ_DIR}/print_help.o \
    ${OBJ_DIR}/utils/base64.o \
    ${OBJ_DIR}/utils/crypt.o \
    ${OBJ_DIR}/utils/file.o \
    ${OBJ_DIR}/utils/db.o \
    ${OBJ_DIR}/utils/text.o \
    ${OBJ_DIR}/utils/zip.o \
    ${OBJ_DIR}/net/nt_socket.o \
    ${OBJ_DIR}/net/nt_ssl_socket.o \
    ${OBJ_DIR}/net/nt_http.o \
    ${OBJ_DIR}/net/nt_http_response_header.o \
    ${OBJ_DIR}/net/nt_http_utils.o \
    ${OBJ_DIR}/net/nt_cookie.o \
    ${OBJ_DIR}/html/html_string.o \
    ${OBJ_DIR}/_2ch/_2ch.o \
    ${OBJ_DIR}/_2ch/model_2ch.o \
    ${OBJ_DIR}/_2ch/parse_2ch.o \
    ${OBJ_DIR}/_2ch/maru_2ch.o \
    ${OBJ_DIR}/ui/disp_board_menu.o \
    ${OBJ_DIR}/ui/disp_threadlist.o \
    ${OBJ_DIR}/ui/disp_reslist.o \
    ${OBJ_DIR}/ui/disp_win.o \
    ${OBJ_DIR}/ui/disp_editor.o \
    ${OBJ_DIR}/ui/disp_html_result.o \
    ${OBJ_DIR}/ui/disp_string.o

INC_FILES = ${INC_DIR}/env.h \
	${INC_DIR}/error.h \
	${INC_DIR}/nt_string.h \
	${INC_DIR}/_2ch/_2ch.h \
	${INC_DIR}/_2ch/model_2ch.h \
	${INC_DIR}/_2ch/maru_2ch.h \
	${INC_DIR}/ui/disp.h \
	${INC_DIR}/ui/disp_win.h \
	${INC_DIR}/ui/disp_string.h \
	${INC_DIR}/net/nt_socket.h \
	${INC_DIR}/net/nt_http.h \
	${INC_DIR}/net/nt_cookie.h \
	${INC_DIR}/html/html_string.h \
	${INC_DIR}/utils/base64.h \
	${INC_DIR}/utils/crypt.h \
	${INC_DIR}/utils/file.h \
	${INC_DIR}/utils/zip.h \
	${INC_DIR}/utils/db.h \
	${INC_DIR}/utils/text.h \
	${INC_DIR}/utils/nt_std_t.h

SHELL = /bin/sh
TARGET = ntch


CC = @CC@
DEFS = @DEFS@
#LIBS = @LIBS@
LIBS = -lncursesw -lgdbm -lz -lm -lssl -lcrypto -lgdbm_compat
INCLUDES = -I/usr/include/gdbm -I${INC_DIR}
OBJ_DIR = ./obj
GEN_DIR = ./gen
SRC_DIR = ./src
INC_DIR = ./src/inc

all : ${TARGET}

run : 
	./${TARGET} -r -o ~/.ntch

# If you do not specify the -g (debug) option, 
# Valgrind will not work correctly.
memtest :
	valgrind --leak-check=yes --track-origins=yes -v ./${TARGET}

${TARGET} : ${OBJS}
	${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS}

clean:
	@ ${SHELL} prepare_proj.sh -d
	rm -rf ${TARGET} 

$(OBJ_DIR)/print_help.o : help.txt help_gen
	./help_gen help.txt > ${GEN_DIR}/print_help.c
	${CC} ${CFLAGS} -c -o $@ ${GEN_DIR}/print_help.c 

help_gen : help_gen.c
	${CC} -o $@ $<

$(OBJ_DIR)/main.o : ${SRC_DIR}/main.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/env.o : ${SRC_DIR}/env.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/utils/nt_std_t.o : ${SRC_DIR}/utils/nt_std_t.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/net/nt_socket.o : ${SRC_DIR}/net/nt_socket.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/net/nt_ssl_socket.o : ${SRC_DIR}/net/nt_ssl_socket.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/net/nt_http.o : ${SRC_DIR}/net/nt_http.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/net/nt_http_response_header.o : ${SRC_DIR}/net/nt_http_response_header.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/net/nt_http_utils.o : ${SRC_DIR}/net/nt_http_utils.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/net/nt_cookie.o : ${SRC_DIR}/net/nt_cookie.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/html/html_string.o : ${SRC_DIR}/html/html_string.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/utils/base64.o : ${SRC_DIR}/utils/base64.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/utils/file.o : ${SRC_DIR}/utils/file.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/utils/zip.o : ${SRC_DIR}/utils/zip.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/utils/db.o : ${SRC_DIR}/utils/db.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/utils/text.o : ${SRC_DIR}/utils/text.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/utils/crypt.o : ${SRC_DIR}/utils/crypt.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/_2ch/_2ch.o : ${SRC_DIR}/_2ch/_2ch.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/_2ch/model_2ch.o : ${SRC_DIR}/_2ch/model_2ch.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/_2ch/parse_2ch.o : ${SRC_DIR}/_2ch/parse_2ch.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/_2ch/maru_2ch.o : ${SRC_DIR}/_2ch/maru_2ch.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/ui/disp_board_menu.o : ${SRC_DIR}/ui/disp_board_menu.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/ui/disp_threadlist.o : ${SRC_DIR}/ui/disp_threadlist.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/ui/disp_reslist.o : ${SRC_DIR}/ui/disp_reslist.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/ui/disp_string.o : ${SRC_DIR}/ui/disp_string.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/ui/disp_win.o : ${SRC_DIR}/ui/disp_win.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/ui/disp_editor.o : ${SRC_DIR}/ui/disp_editor.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

$(OBJ_DIR)/ui/disp_html_result.o : ${SRC_DIR}/ui/disp_html_result.c ${INC_FILES}
	@ ${SHELL} prepare_proj.sh
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 

