# $USAGI: Makefile,v 1.55 2003/07/14 09:43:07 yoshfuji Exp $

# Copyright (C) 2001,2002 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 cvs-checkout co co-common \
	linux22 linux24 linux25 linux26 unspec-target 

SUBDIRS = usagi src doc

CVSROOT ?= :pserver:anoncvs@anoncvs.linux-ipv6.org:/cvsroot/usagi
CHECKOUTDIR ?= usagi
TARGET ?= unspec-target

KERNEL_SOURCE ?= ../../kernel/linux

ifneq ($(DATE),)
  STICKY ?= -D '$(DATE)'
else
 ifneq ($(TAG),)
  STICKY ?= -r '$(TAG)'
 endif
endif

all:
	@(echo "Don't run make directly.  please read INSTALL.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 -d
	cvs update kernel/Makefile usagi/Makefile.tiny
	$(MAKE) unprepare
	$(MAKE) -C kernel update
	$(MAKE) -C usagi -f Makefile.tiny update
	cvs update -d -P src doc
	@(echo run \"make prepare\" before compile. ; \
	exit 0)

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

upgrade-core:
	$(MAKE) unprepare
	( \
		if [ x"$(RELEASE)" != x"MAIN" ]; then \
			cvs update -A -r $(RELEASE); \
		else \
			cvs update -A; \
		fi; \
		$(MAKE) update\
	)
upgrade:
	( \
		if [ x"$(RELEASE)" = x"" ] && [ -f RELEASE ]; then \
			$(MAKE) -C $(CURDIR) upgrade-core RELEASE=`cat RELEASE`; \
		else \
			$(MAKE) -C $(CURDIR) upgrade-core; \
		fi; \
	)

linux22 linux24 linux25 linux26:
	$(MAKE) -C kernel prepare TARGET=$@

unspec-target:
	@(echo Please do make prepare with TARGET variable set.; \
	exit 1)

prepare: $(TARGET)
	./prepare.pl ../src usagi
	ln -sf $(KERNEL_SOURCE)/include/linux usagi/include/
	ln -sf $(KERNEL_SOURCE)/include/asm usagi/include/
	ln -sf $(KERNEL_SOURCE)/include/asm-generic usagi/include/

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

checkout-common: checkout

checkout:
	( cd $(CURDIR); \
		cvs update -l -d $(STICKY); \
		cvs update -d -P $(STICKY) $(SUBDIRS); \
		cvs update -d -P -l $(STICKY) kernel; \
		if test x$(TARGET) = xANY; then \
			cvs update -d -P $(STICKY) kernel; \
		elif test x$(TARGET) = xlinux22 -o x$(TARGET) = xlinux24 -o x$(TARGET) = xlinux25 -o x$(TARGET) = xlinux26; then \
			cvs update -d -P $(STICKY) kernel/usagi kernel/$(TARGET); \
		else \
			cvs update -d -P $(STICKY) kernel/usagi; \
		fi; \
	)

cvs-checkout:
	( cd $(CURDIR); \
		cvs -d $(CVSROOT) checkout $(STICKY) -d $(CHECKOUTDIR) usagi/Makefile; \
		$(MAKE) -C $(CHECKOUTDIR) checkout STICKY="$(STICKY)" TARGET=$(TARGET); \
	)

checkout-daily:
	$(MAKE) cvs-checkout STICKY="-D '0:00 GMT'" TARGET=ANY CHECKOUTDIR=$(CHECKOUTDIR)

co-common: checkout-common
co: checkout

