###############################################################################
# mod_uploader / GNUmakefile.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.in 687 2005-09-15 11:08:15Z svn $
###############################################################################
#
# * 動作
#   - make config   : configure スクリプトを実行
#   - make configure: configure スクリプトを生成
#   - make compile  : mod_uploader をコンパイル
#   - make pconv    : pconv をコンパイル
#   - make env      : コンピュータの環境を表示
#   - make apidoc   : API ドキュメントを生成 (要 Doxygen)
#   - make clean    : 生成ファイルおよび中間生成ファイルを削除
#
###############################################################################

###############################################################################
# 設定
PACKAGE     := @PACKAGE_NAME@
VERSION     := @PACKAGE_VERSION@

TARGET      := $(PACKAGE).so
PKGDIR   	:= $(PACKAGE)-$(VERSION)
DISTFILE 	:= $(PKGDIR).tgz
DDISTFILE   := $(PACKAGE).so-$(VERSION).zip

SVN         := @SVN@
TAR         := @TAR@

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

configure: configure.in aclocal.m4
	autoheader -W all
	autoconf -W all

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

config: config.status
	./config.status

depend:
	cd src && $(MAKE) $@

compile: depend
	cd src && $(MAKE) $@

rubyext: compile
	cd bin && $(MAKE)

install: compile
	@APXS2@ -i -a -n "uploader" @PACKAGE_NAME@.so

start:
	@APACHE2CTL@ -f @PWD@/conf/httpd.conf -k start

restart:
	@APACHE2CTL@ -f @PWD@/conf/httpd.conf -k restart

stop:
	@APACHE2CTL@ -f @PWD@/conf/httpd.conf -k stop

pconv:
	cd src && $(MAKE) $@

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

doc:
	perl -I util util/update.pl < doc/index.htm > doc/index.tmp
	mv doc/index.tmp doc/index.htm

apidoc:
	cd doc && make $@

dist: TMPDIR := $(shell mktemp -d -t @PACKAGE_NAME@.XXXXXX 2>/dev/null)
dist:
	svn export . $(TMPDIR)/$(PKGDIR)
	cd $(TMPDIR) && touch -t `date "+%m%d"`0000 `find ./` && \
	tar zcvf $(DISTFILE) $(PKGDIR)
	mv $(TMPDIR)/$(DISTFILE) ./
	rm -Rf $(TMPDIR)

dist-sf: DIST_FILE = $(shell ls -t | grep -E 'mod_uploader-.*\.tgz' | head -n 1)
dist-sf: DIST_VERSION = $(shell echo $(DIST_FILE) | sed 's/mod_uploader-\(.*\)\.tgz/\1/')
dist-sf: dist
	perl -I util util/update.pl --mode=release --package=mod_uploader --version=$(DIST_VERSION) --file=$(DIST_FILE)

bdist:
	(file src/@PACKAGE_NAME@.so | grep -q 'MS-DOS executable') && \
	cd src && zip -D $(DDISTFILE) $(PACKAGE).so && mv $(DDISTFILE) ..

bdist-sf: DIST_FILE = $(shell ls -t | grep -E 'mod_uploader\.so-.*\.zip' | head -n 1)
bdist-sf: DIST_VERSION := $(shell echo $(DIST_FILE) | sed 's/mod_uploader.so-\(.*\)\.zip/\1/')
bdist-sf: bdist
	perl -I util util/update.pl --mode=release --package=mod_uploader-win32-bin --version=$(DIST_VERSION) --file=$(DIST_FILE)

distclean: clean
	@rm -rf GNUmakefile src/GNUmakefile src/Makefile.win32 bin/GNUmakefile
	@rm -rf include/RFC1867ParserImpl.h
	@rm -rf src/RFC1867Parser.cpp src/RFC1867ParserImpl.cpp
	@rm -rf tmpl/index.htm tmpl/thumbnail.htm tmpl/error.htm
	@rm -rf conf/httpd.conf
	@rm -rf doc/doxygen.conf
	@rm -rf autom4te.cache autoscan.log config.log config.status
	@ls -1 | egrep '$(PACKAGE)-.*\.tgz' | xargs rm -f
	@ls -1 | egrep '$(PACKAGE).so-.*\.zip' | xargs rm -f
	@rm -f $(PKGNAME).tgz

clean:
	cd include && $(MAKE) $@
	cd src && $(MAKE) $@
	cd bin && $(MAKE) $@
	cd doc && $(MAKE) $@
	@rm -f *.so
	@rm -f pconv
	@rm -f *~ \#*\#
	@find /tmp -name "@PACKAGE_NAME@.*" -user `whoami` -maxdepth 1 -mmin +5 | xargs rm -rf {}

.SUFFIXES: 
.PHONY: config depend compile rubyext install start restart stop pconv \
	env doc apidoc dist bdist dist-sf bdist-sf distclean clean

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