###############################################################################
# mod_uploader / GNUmakefile.win32.in
###############################################################################
# Copyright (C) 2005 Tetsuya Kimata <kimata@acapulco.dyndns.org>
#
# All rights reserved.
#
# This software is provided 'as-is', without any express or implied
# warranty.  In no event will the authors be held liable for any
# damages arising from the use of this software.
#
# Permission is granted to anyone to use this software for any
# purpose, including commercial applications, and to alter it and
# redistribute it freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must
#    not claim that you wrote the original software. If you use this
#    software in a product, an acknowledgment in the product
#    documentation would be appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must
#    not be misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
#    distribution.
#
# $Id: GNUmakefile.win32.in 688 2005-09-15 13:05:28Z svn $
###############################################################################

###############################################################################
# 設定
CC          := cl.exe
CXX         := $(CC)
LINK        := link.exe

MODULE_NAME := mod_uploader.so

APACHERDIR  := C:/Server/Apache2
MAGICKDIR   := C:/Application/Image/Edit/ImageMagick

HEADERDIR   := ../include

INCLUDES    := /I "$(HEADERDIR)" /I "$(APACHERDIR)/include" /I "$(MAGICKDIR)/include"
CFLAGS      := /O2 /GF /GL /MD /GX /W3 /Fo /EHc- /nologo
DEFS        := /D "WIN32" /D "_WINDOWS" /D "HAVE_CONFIG_H"
CXXFLAGS    = $(CFLAGS)
LIBS        := /LIBPATH:"$(APACHERDIR)/lib" /LIBPATH:"$(MAGICKDIR)/lib" kernel32.lib libapr.lib libaprutil.lib libapriconv.lib libhttpd.lib CORE_RL_Magick++_.lib
LDFLAGS     := /LTCG /OPT:REF /INCREMENTAL:NO /SUBSYSTEM:CONSOLE /nologo

###############################################################################
# デバッグ
ifeq (@DEBUG@,on)
DEFS        += /D "DEBUG"
CFLAGS      := $(filter-out /O2 /GF /GL /G7 /MD, $(CFLAGS)) /Od /MDd /GS /RTCsu /Zi
LDFLAGS     := $(filter-out /LTCG, $(LDFLAGS)) /DEBUG
endif

###############################################################################
# ターゲット
all: compile

compile: $(MODULE_NAME)

###############################################################################
# ソース
$(MODULE_NAME): mod_uploader.obj UploaderConfig.obj \
	RFC1867ParserImpl.obj PostReader.obj ApachePostReader.obj FileWriter.obj @WRITER_CLASS@.obj \
	TemplateParser.obj TemplateLexer.obj TemplateExecutor.obj TemplateVariableCreator.obj \
	UploadItem.obj UploadItemCreator.obj UploadItemWriter.obj UploadItemReader.obj UploadItemList.obj \
	ThumbnailWriter.obj MessageDigest5.obj \
	PageView.obj RssView.obj \
	DirectoryCleaner.obj BinString.obj CharCodeConverter.obj Auxiliary.obj
	@echo -e "\033[1;34mGenerating \033[1;31m$@\033[0m"
	$(LINK) $(LDFLAGS) $(LIBS) /DLL /OUT:$@ $^

pconv.exe: PlainConverter.obj UploadItemReader.obj CharCodeConverter.obj
	@echo -e "\033[1;34mGenerating \033[1;31m$@\033[0m"
	$(LINK) $(LDFLAGS) $(LIBS) /OUT:$@ $^

RFC1867ParserImpl.obj: RFC1867Parser.obj FileWriter.obj @WRITER_CLASS@.obj DirectoryCleaner.obj BinString.obj

###############################################################################
# テスト
BasicFileWriter.test.exe: DEFS += /D "DEBUG_BasicFileWriter"
BasicFileWriter.test.exe: FileWriter.obj

MmapFileWriter.test.exe: DEFS += /D "DEBUG_MmapFileWriter"
MmapFileWriter.test.exe: FileWriter.obj

RFC1867Parser.test.exe: DEFS += /D "DEBUG_UPLOAD" /D "DEBUG_RFC1867Parser"
RFC1867Parser.test.exe: FileWriter.obj @WRITER_CLASS@.obj DirectoryCleaner.obj BinString.obj Auxiliary.obj

UploadItem.test.exe: DEFS += /D "DEBUG_UploadItem"
UploadItem.test.exe: Auxiliary.obj

UploadItemWriter.test.exe: DEFS += /D "DEBUG_UPLOAD" /D "DEBUG_TEMPLATE" /D "DEBUG_UploadItemWriter"
UploadItemWriter.test.exe: FileWriter.obj RFC1867ParserImpl.obj @WRITER_CLASS@.obj \
	UploadItem.obj UploadItemCreator.obj \
	TemplateExecutor.obj DirectoryCleaner.obj BinString.obj CharCodeConverter.obj Auxiliary.obj

UploadItemReader.test.exe: DEFS += /D "DEBUG_UPLOAD" /D "DEBUG_TEMPLATE" /D "DEBUG_UploadItemReader"
UploadItemReader.test.exe: FileWriter.obj RFC1867ParserImpl.obj @WRITER_CLASS@.obj \
	UploadItem.obj UploadItemCreator.obj UploadItemWriter.obj \
	TemplateExecutor.obj DirectoryCleaner.obj BinString.obj CharCodeConverter.obj Auxiliary.obj

UploadItemList.test.exe: DEFS += /D "DEBUG_UPLOAD" /D "DEBUG_TEMPLATE" /D "DEBUG_UploadItemList"
UploadItemList.test.exe: FileWriter.obj RFC1867ParserImpl.obj @WRITER_CLASS@.obj \
	UploadItem.obj UploadItemReader.obj TemplateExecutor.obj TemplateVariableCreator.obj \
	DirectoryCleaner.obj BinString.obj CharCodeConverter.obj Auxiliary.obj

TemplateLexer.test.exe: DEFS += /D "DEBUG_TemplateLexer"
TemplateLexer.test.exe: Auxiliary.obj

TemplateParser.test.exe: DEFS += /D "DEBUG_TemplateParser"
TemplateParser.test.exe: TemplateLexer.obj Auxiliary.obj

TemplateExecutor.test.exe: DEFS += /D "DEBUG_TEMPLATE" /D "DEBUG_TemplateExecutor"
TemplateExecutor.test.exe: UploadItem.obj UploadItemReader.obj UploadItemList.obj \
	TemplateParser.obj TemplateLexer.obj TemplateVariableCreator.obj \
	ThumbnailWriter.obj CharCodeConverter.obj Auxiliary.obj

ThumbnailWriter.test.exe: DEFS += /D "DEBUG_TEMPLATE" /D "DEBUG_ThumbnailWriter"
ThumbnailWriter.test.exe: UploadItem.obj UploadItemReader.obj TemplateExecutor.obj \
	CharCodeConverter.obj Auxiliary.obj

RssView.test.exe: DEFS += /D "DEBUG_TEMPLATE" /D "DEBUG_RssView"
RssView.test.exe: PageView.obj RssView.obj \
	UploadItem.obj UploadItemReader.obj UploadItemList.obj \
	TemplateExecutor.obj TemplateVariableCreator.obj \
	ThumbnailWriter.obj CharCodeConverter.obj Auxiliary.obj

CharCodeConverter.test.exe: DEFS += -DDEBUG_CharCodeConverter
CharCodeConverter.test.exe:

MessageDigest5.test.exe: DEFS += -DDEBUG_MessageDigest5
MessageDigest5.test.exe:

###############################################################################
# その他

clean-obj:
	@rm -f *.o *.obj *.pdb *.exp *.lib *.il *.loT

clean: clean-obj
	@rm -f mod_uploader.lo mod_uploader.slo mod_uploader.la
	@rm -f *.dot *.ps *.pdf
	@rm -f cachegrind.out.* gmon.out
	@rm -f *.log *.status *.scan *.bak
	@rm -f *.dpi *dyn *.pchi
	@rm -f *.so *.out *.test *.exe
	@rm -f *~ \#s*\#

###############################################################################
# 型ルール
%.obj: %.c $(HEADERDIR)/%.h $(HEADERDIR)/mod_uploader_config.h GNUmakefile.win32
	@echo -e "\033[0;36mCompiling \033[1;36m$<\033[0m"
	$(CXX) $(DEFS) /c $(INCLUDES) $(CFLAGS) $<
%.obj: %.cpp $(HEADERDIR)/%.h $(HEADERDIR)/mod_uploader_config.h GNUmakefile.win32
	@echo -e "\033[0;36mCompiling \033[1;36m$<\033[0m"
	$(CXX) $(DEFS) /c $(INCLUDES) $(CXXFLAGS) $<
%.obj: %.cpp $(HEADERDIR)/mod_uploader_config.h GNUmakefile.win32
	@echo -e "\033[0;36mCompiling \033[1;36m$<\033[0m"
	$(CXX) $(DEFS) /c $(INCLUDES) $(CXXFLAGS) $<

%.test.exe: DEFS += /D "DEBUG"
%.test.exe: CFLAGS := $(filter-out /O2, $(CFLAGS)) /GS /RTCsu /Wp64 /Zi
%.test.exe: LDFLAGS += /DEBUG
%.test.exe: %.obj
	@echo -e "\033[1;34mGenerating \033[1;31m$@\033[0m"
	$(LINK) $(LDFLAGS) $(LIBS) $^ /OUT:$@

.SUFFIXES: .c .cpp .in .h .obj .test.exe   
.PHONY: all compile install clean clean-obj depend

# Local Variables:
# mode: makefile
# buffer-file-coding-system: euc-japan-dos
# End:
