###############################################################################
# Copyright (C) 2006 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.in 1012 2006-04-11 15:32:28Z svn $
###############################################################################
#
# * 動作
#   - make config           : configure スクリプトを実行
#   - make configure        : configure スクリプトを生成
# 
#   - make apache-module    : Apache 用の mod_mbbs をコンパイル
# 
#   - make env              : コンピュータの環境を表示
#
#   - make test-win         : Windows でテストを実行
#   - make test-win-status  : Windows でのテスト結果を表示
#
#   - make TAGS             : TAGS ファイルを作成
#   - make doc              : ドキュメントを生成 (要 docutils)
#   - make doc-api          : API ドキュメントを生成 (要 Doxygen)
#   - make clean            : 生成ファイルおよび中間生成ファイルを削除
#
###############################################################################

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

configure: configure.in acinclude.m4
	./autogen.sh

config.status: configure
	CC=$(CC) ./configure --cache-file=config.cache --no-create

config: config.status
	./config.status

compile: apache-module

apache-module:
	cd src && $(MAKE) -f GNUmakefile
	cp -f src/mod_fast_bbs.so ./

env:
	@echo ------------------------------------------------------------
	@echo -e "\033[1;37mmod_uploader:\033[0m"
	@echo $(VERSION)
	@echo ------------------------------------------------------------
	@echo -e "\033[1;37mOperatin System:\033[0m"
	@uname -a
	@echo ------------------------------------------------------------
	@echo -e "\033[1;37mApache:\033[0m"
	@`/usr/sbin/apxs2 -q SBINDIR`/`/usr/sbin/apxs2 -q TARGET` -v | head -n 1
	@echo ------------------------------------------------------------
	@echo -e "\033[1;37mApache Portable Runtime:\033[0m"
	@/usr/bin/apr-config --version
	@echo ------------------------------------------------------------
	@echo -e "\033[1;37mGNU Compiler Collection:\033[0m"
	@gcc -v 2>&1 | tail -n 1
	@echo ------------------------------------------------------------
	@echo -e "\033[1;37mGNU Libtool:\033[0m"
	@/usr/bin/libtool --version 2>&1 | head -n 1
	@echo ------------------------------------------------------------
	@echo -e "\033[1;37mRuby:\033[0m"
	@/usr/bin/ruby --version 2>&1 | head -n 1
	@echo ------------------------------------------------------------

###############################################################################
# その他
GNUmakefile: GNUmakefile.in config.status
	./config.status

tags:
	gtags

doc:
	cd doc && make $@

doc-api:
	cd doc-api && make $@

test-win:
	@echo -n "pass: "; \
	read -s PASS; \
	echo; \
	env WIN_PASS=$$PASS ./util/win_make.pl cl  | /bin/tee test/log/win_cl.log; \
	env WIN_PASS=$$PASS ./util/win_make.pl icc | /bin/tee test/log/win_icc.log
	$(MAKE) test-win-status

test-mac:
	./util/mac_make.pl cl | /bin/tee test/log/mac_gcc.log
	$(MAKE) test-mac-status

test-win-status:
	@/bin/grep 'All Test Status' -B1 -A100 test/log/win_cl.log | \
	/bin/grep '==============================' -B100
	@echo
	@/bin/grep 'All Test Status' -B1 -A100 test/log/win_icc.log | \
	/bin/grep '==============================' -B100 || true

test-mac-status:
	@echo
	@/bin/grep 'All Test Status' -B1 -A100 test/log/mac_gcc.log | \
	/bin/grep '==============================' -B100 || true

test-all-html-status:
	@for i in win mac; \
	do \
		$(MAKE) test-$$i-status; \
	done  | \
	./util/ansi2html.pl 'Test Status' > test/status/stat.htm
	@/bin/cat test/log/win_cl.log | \
	./util/ansi2html.pl 'Test Log (Windows, Microsoft C/C++ Optimizing Compiler)' > \
	test/status/log_win_cl.htm
	@/bin/cat test/log/win_cl.log | \
	./util/ansi2html.pl 'Test Log (Windows, Intel C++ Compiler)' > \
	test/status/log_win_icc.htm
	@/bin/cat test/log/mac_gcc.log | \
	./util/ansi2html.pl 'Test Log (Mac OSX Tiger, GNU Compiler Collection)' > \
	test/status/log_mac_gcc.htm

distclean: clean
	@rm -rf GNUmakefile GNUmakefile.apache GNUmakefile.dist
	@rm -rf src/GNUmakefile bin/GNUmakefile
	@rm -rf doc/doxygen.conf
	@rm -rf autom4te.cache autoscan.log config.log config.status

clean-obj:
	cd src && $(MAKE) $@

clean:
	cd src && $(MAKE) $@
	@rm -f *.so
	@rm -f *~ \#*\#

.SUFFIXES: 
.PHONY: config compile apache-module \
	test-win test-win-status test-all-html-status \
	test-mac test-mac-status \
	env tags doc doc-api distclean clean clean-obj

# Local Variables:
# mode: makefile
# coding: utf-8-unix
# End:
