# $USAGI: Makefile,v 1.34 2002/02/06 09:37:11 yoshfuji Exp $

# Copyright (C) 2001 USAGI/WIDE Project.
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of the project nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

.PHONY: all clean distclean update update-all prepare checkout checkout-common co co-common

COMMON = usagi src doc README.USAGI RELNOTES.USAGI INSTALL.USAGI prepare.pl kernel/Makefile kernel/usagi \
	 CHANGELOG.USAGI CHANGELOG.USAGI.2001 CHANGELOG.USAGI.OLD \

KERNEL_SOURCE ?= ../../kernel/$(TARGET)

all:
	@(echo "Don't run make directly.  please read README.USAGI first." ; \
	exit 1)

clean:
	$(MAKE) -C kernel clean
	$(MAKE) -C usagi clean

distclean: clean
	$(MAKE) -C usagi distclean
	$(MAKE) -C usagi -f Makefile.tiny unprepare

update:
	cvs update -l
	cvs update kernel/Makefile usagi/Makefile.tiny
	$(MAKE) unprepare
	$(MAKE) -C kernel update
	$(MAKE) -C usagi -f Makefile.tiny update
	cvs update src doc
	@echo run \"make prepare\" before compile.

update-all:
	cvs update -l
	cvs update kernel/Makefile usagi/Makefile.tiny
	$(MAKE) unprepare
	cvs update -d -P
	@(echo run \"make prepare\" before compile. ;
	exit 1)

prepare:
	@(if test x$(TARGET) == x; then					\
		echo Please do make prepare with TARGET variable set.;	\
		exit 1;							\
	fi)
	@test x$(TARGET) != x
	$(MAKE) -C kernel prepare TARGET=$(TARGET)
	./prepare.pl ../src usagi
	ln -sf $(KERNEL_SOURCE)/include/linux usagi/include/
	ln -sf $(KERNEL_SOURCE)/include/asm usagi/include/

unprepare:
	$(MAKE) -C kernel unprepare
	$(MAKE) -C usagi -f Makefile.tiny unprepare

checkout-common:
	( cd ..; \
	if test x$(CVSROOT) != x; then \
		cvsroot="$(CVSROOT)"; \
	else \
		cvsroot=":pserver:anoncvs@anoncvs.linux-ipv6.org:/cvsroot/usagi"; \
	fi; \
	for i in $(COMMON); do \
		if test x$(TAG) != x; then \
			cvs -d $$cvsroot checkout -r $(TAG) usagi/$$i; \
		else \
			cvs -d $$cvsroot checkout usagi/$$i; \
		fi; \
	done; )

checkout: checkout-common
	( cd ..; \
	if test x$(CVSROOT) != x; then \
 		cvsroot="$(CVSROOT)"; \
	else \
		cvsroot=":pserver:anoncvs@anoncvs.linux-ipv6.org:/cvsroot/usagi"; \
	fi; \
	if test x$(TARGET) = xlinux22 -o x$(TARGET) = xlinux24 -o x$(TARGET) = xlinux25; then \
		if test x$(TAG) != x; then \
			cvs -d $$cvsroot checkout \
				-r $(TAG) \
				usagi/kernel/$(TARGET); \
		else \
			cvs -d $$cvsroot checkout \
				usagi/kernel/$(TARGET); \
		fi; \
	fi; )

checkout-daily:
	( cd ..; \
	if test x$(CVSROOT) != x; then \
		cvsroot="$(CVSROOT)"; \
	else \
		cvsroot=":pserver:anoncvs@anoncvs.linux-ipv6.org:/cvsroot/usagi"; \
	fi; \
	for i in $(COMMON); do \
		if test x$(DATE) != x; then \
			cvs -d $$cvsroot checkout \
				-D "$(DATE)" \
				usagi/$$i; \
		else \
			cvs -d $$cvsroot checkout \
				-D "0:00 GMT" \
				usagi/$$i; \
		fi; \
	done; \
	for i in linux22 linux24 linux25; do \
		if test x$(DATE) != x; then \
			cvs -d $$cvsroot checkout \
				-D "$(DATE)" \
				usagi/kernel/$$i; \
		else \
			cvs -d $$cvsroot checkout \
				-D "0:00 GMT" \
				usagi/kernel/$$i; \
		fi; \
	done; )

co-common: checkout-common
co: checkout

