# Generated automatically from Makefile.in by configure.
# Makefile
#
# Copyright (C)  1997 - 2000  Heinz Mauelshagen, Germany
#
# February 1997
# May 1998
#
# lvm is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# 
# lvm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with GNU CC; see the file COPYING.  If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. 
#

# The following 3 vars are set up by autoconf
KERNEL_DIR=/usr/src/linux
LVM_VERSION=0.9.1_beta6
KERNEL_VERSION=2.4.2

DRIVER_DIR=../kernel
CLEANED_DIR=cleaned
CLEANER=../scripts/select_version
PATCHER=../scripts/patch_fragment
FRAGGER=../scripts/select_fragments
LVM_PATCH=./lvm-$(LVM_VERSION)-$(KERNEL_VERSION).patch

ifneq (,$(findstring 2.2,$(KERNEL_VERSION)))
K_DRIVER_DIR=$(KERNEL_DIR)/drivers/block
ifneq (,$(findstring RAID,$(KERNEL_VERSION)))
GENERIC_PATCH=fragments/generic-map-new-raid-2.2.patch
else
GENERIC_PATCH=fragments/generic-map-2.2.patch
endif
else
K_DRIVER_DIR=$(KERNEL_DIR)/drivers/md
endif

$(LVM_PATCH): \
	check_rawio \
	$(CLEANED_DIR)/lvm.h \
	$(CLEANED_DIR)/lvm-internal.h \
	$(CLEANED_DIR)/lvm.c	\
	$(CLEANED_DIR)/lvm-snap.c \
	$(CLEANED_DIR)/lvm-fs.c 
	$(PATCHER) $(KERNEL_DIR) $(KERNEL_DIR)/include/linux/lvm.h $(CLEANED_DIR)/lvm.h > $@
	$(PATCHER) $(KERNEL_DIR) $(K_DRIVER_DIR)/lvm.c $(CLEANED_DIR)/lvm.c >> $@
	$(PATCHER) $(KERNEL_DIR) $(K_DRIVER_DIR)/lvm-internal.h $(CLEANED_DIR)/lvm-internal.h >> $@
	$(PATCHER) $(KERNEL_DIR) $(K_DRIVER_DIR)/lvm-snap.c $(CLEANED_DIR)/lvm-snap.c >> $@
	$(PATCHER) $(KERNEL_DIR) $(K_DRIVER_DIR)/lvm-fs.c $(CLEANED_DIR)/lvm-fs.c >> $@
	$(FRAGGER) $(KERNEL_VERSION) >> $@
	if [ -e "$(GENERIC_PATCH)" ]; \
	then \
	  cat $(GENERIC_PATCH) >> $@; \
	fi;

$(CLEANED_DIR)/lvm.h: $(DRIVER_DIR)/lvm.h cleaned
	$(CLEANER) $(KERNEL_VERSION) < $< > $@

$(CLEANED_DIR)/lvm.c: $(DRIVER_DIR)/lvm.c cleaned
	$(CLEANER) $(KERNEL_VERSION) < $< > $@

$(CLEANED_DIR)/lvm-internal.h: $(DRIVER_DIR)/lvm-internal.h cleaned
	$(CLEANER) $(KERNEL_VERSION) < $< > $@

$(CLEANED_DIR)/lvm-snap.c: $(DRIVER_DIR)/lvm-snap.c cleaned
	$(CLEANER) $(KERNEL_VERSION) < $< > $@

$(CLEANED_DIR)/lvm-fs.c: $(DRIVER_DIR)/lvm-fs.c cleaned
	$(CLEANER) $(KERNEL_VERSION) < $< > $@

cleaned:
	mkdir cleaned

clean:
	rm -f $(CLEANED_DIR)/*
	rm -f $(LVM_PATCH)

distclean: clean
	rm -f Makefile

check_rawio:
	@[ -e $(KERNEL_DIR)/include/linux/iobuf.h ] || \
	(echo "You haven't applied the rawio patch, please see the README";\
	 exit 1;)

