###############################################################################
# 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_uploader をコンパイル
#   - make apache-module-win: Apache (Windows) 用の mod_uploader をコンパイル
# 
#   - 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-win:
	./util/win_build.pl

apache-module:
	cd src && $(MAKE) -f GNUmakefile
	cp -f src/mod_uploader.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"
	@`@APXS2@ -q SBINDIR`/`@APXS2@ -q TARGET` -v | head -n 1
	@echo ------------------------------------------------------------
	@echo -e "\033[1;37mApache Portable Runtime:\033[0m"
	@@APRCONF@ --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"
	@@LIBTOOL@ --version 2>&1 | head -n 1
	@echo ------------------------------------------------------------
	@echo -e "\033[1;37mRuby:\033[0m"
	@@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 && make $@

test-linux:
	@./util/linux_test.pl centos | @TEE@ test/log/linux_centos.log
	@./util/linux_test.pl fedora | @TEE@ test/log/linux_fedora.log
	@./util/linux_test.pl ubuntu | @TEE@ test/log/linux_ubuntu.log
	$(MAKE) test-linux-status

test-bsd:
	@./util/bsd_test.pl freebsd | @TEE@ test/log/freebsd.log
	$(MAKE) test-bsd-status

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

test-mac:
	./util/mac_test.pl cl | @TEE@ test/log/mac_gcc.log
	$(MAKE) test-mac-status

test-linux-status:
	@@GREP@ 'All Test Status' -B1 -A100 test/log/linux_centos.log | \
	@GREP@ '==============================' -B100 || true
	@echo
	@@GREP@ 'All Test Status' -B1 -A100 test/log/linux_fedora.log | \
	@GREP@ '==============================' -B100
	@echo
	@@GREP@ 'All Test Status' -B1 -A100 test/log/linux_ubuntu.log | \
	@GREP@ '==============================' -B100

test-bsd-status:
	@@GREP@ 'All Test Status' -B1 -A100 test/log/freebsd.log | \
	@GREP@ '==============================' -B100 || true

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

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

test-all-html-status:
	@for i in linux bsd win mac; \
	do \
		$(MAKE) test-$$i-status; \
	done  | \
	./util/ansi2html.pl 'Test Status' > test/status/stat.htm
	@@CAT@ test/log/linux_centos.log | \
	./util/ansi2html.pl 'Test Log (Centos Linux, GNU Compiler Collection)' > \
	test/status/log_linux_centos.htm
	@@CAT@ test/log/linux_fedora.log | \
	./util/ansi2html.pl 'Test Log (Fedora Linux, GNU Compiler Collection)' > \
	test/status/log_linux_fedora.htm
	@@CAT@ test/log/linux_ubuntu.log | \
	./util/ansi2html.pl 'Test Log (Ubuntu Linux, GNU Compiler Collection)' > \
	test/status/log_linux_ubuntu.htm
	@@CAT@ test/log/freebsd.log | \
	./util/ansi2html.pl 'Test Log (FreeBSD, GNU Compiler Collection)' > \
	test/status/log_freebsd.htm
	@@CAT@ test/log/win_cl.log | \
	./util/ansi2html.pl 'Test Log (Windows, Microsoft C/C++ Optimizing Compiler)' > \
	test/status/log_win_cl.htm
	@@CAT@ test/log/win_cl.log | \
	./util/ansi2html.pl 'Test Log (Windows, Intel C++ Compiler)' > \
	test/status/log_win_icc.htm
	@@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 apache-module-win \
	test-linux test-linux-status \
	test-bsd test-bsd-status \
	test-win test-win-status \
	test-mac test-mac-status \
	test-all-html-status \
	env tags doc doc-api distclean clean clean-obj

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