# $Id: Makefile.in,v 1.49.2.1 2000/10/18 07:33:06 lha Exp $

SHELL		= /bin/sh

srcdir		= @srcdir@
VPATH		= @srcdir@

@OSF1_TRUE@CC	= cc -std0
@OSF1_FALSE@CC	= @CC@
LD		= @KERNEL_LD@
SYMORDER	= @SYMORDER@
MODLOAD		= @MODLOAD@
MODUNLOAD	= @MODUNLOAD@
MKDIR		= mkdir
RMDIR		= rmdir
LN_S		= @LN_S@
RM		= rm

INSTALL		= @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA	= @INSTALL_DATA@
MKINSTALLDIRS 	= @top_srcdir@/mkinstalldirs

prefix 		= @prefix@
exec_prefix 	= @exec_prefix@
libdir 		= @libdir@
libexecdir 	= @libexecdir@
bindir 		= @bindir@
transform	= @program_transform_name@
EXECSUFFIX	= @EXECSUFFIX@

XFS_BIN		= $(MODULE)

INCDEFS		= -I. -I$(srcdir) \
		  -I../../include -I$(srcdir)/../../include \
		  -I$(srcdir)/../include \
		  @KRB4_INC_FLAGS@

DEFS		= @DEFS@ $(INCDEFS) -DXFS_DEBUG @ARLA_KNFS@
@OSF1_TRUE@CFLAGS= @KERNEL_CFLAGS@ @KERNEL_CPPFLAGS@
@OSF1_FALSE@CFLAGS	= @CFLAGS@ @KERNEL_CFLAGS@ @KERNEL_CPPFLAGS@ -Wno-unused

SYS		= @SYS@

SUBDIRS		= bin

@OSF1_TRUE@MODULE= xfs.mod
@OSF1_FALSE@MODULE= @MODULE@

MODULE_SRCS	= \
		  xfs_deb.c			\
		  xfs_message.c			\
		  xfs_common.c			\
		  @XFS_SRCS@

MODULE_OBJS	= $(MODULE_SRCS:.c=.o)

all: $(MODULE)

$(MODULE_OBJS): xfs_vopdefs.h @VNODE_IF_H@

xfs_mod.o: $(MODULE_OBJS)
	$(LD) -r -o tmp.o $(MODULE_OBJS)
	echo _xfs_mod > symb.tmp
	$(SYMORDER) -c symb.tmp tmp.o
	rm -f symb.tmp
	mv -f tmp.o xfs_mod.o

xfs.mod: $(MODULE_OBJS)
	$(LD) -r -dc -o tmp.o $(MODULE_OBJS)
	mv -f tmp.o xfs.mod

xfs.ko:	$(MODULE_OBJS)
	if test `objformat` = "elf"; then \
	  gensetdefs $(MODULE_OBJS); \
	  $(CC) $(CFLAGS) -c setdef0.c; \
	  $(CC) $(CFLAGS) -c setdef1.c; \
	  $(LD) -Bshareable -o $@ setdef0.o $(MODULE_OBJS) setdef1.o; \
	else \
	  $(LD) -Bshareable -o $@ $(MODULE_OBJS); \
	fi

load:	$(MODULE)
@OSF1_TRUE@	cp $(MODULE) /subsys
@OSF1_TRUE@	sysconfig -c xfs
@OSF1_FALSE@	if test $(MODULE) = "xfs.ko"; then \
@OSF1_FALSE@	  kldload -v ./$(MODULE); \
@OSF1_FALSE@	else \
@OSF1_FALSE@	  rm -f /var/tmp/foo; \
@OSF1_FALSE@	$(MODLOAD) -e xfs_mod -o /var/tmp/foo -p $(srcdir)/bin/xfs_makedev xfs_mod.o || $(MODLOAD) -o /var/tmp/foo xfs_mod.o; \
@OSF1_FALSE@	fi

unload:
@OSF1_TRUE@	sysconfig -u xfs
@OSF1_FALSE@	if test $(MODULE) = "xfs.ko"; then \
@OSF1_FALSE@	  kldunload -v -n $(MODULE); \
@OSF1_FALSE@	else \
@OSF1_FALSE@	  $(MODUNLOAD) -n xfs_mod; \
@OSF1_FALSE@	fi

mount:
		./bin/mount_xfs /dev/xfs0 /afs

umount:
		./bin/umount_xfs /afs

install: all
	$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
	PROG_BIN='$(XFS_BIN)'; for x in $$PROG_BIN; do \
		f=`echo $$x | sed '$(transform)'`; \
		$(INSTALL_PROGRAM) $$x $(DESTDIR)$(bindir)/$$f; \
	done
	for i in lkm subsys modules; do \
		if test -d /$$i; then \
			$(INSTALL_PROGRAM) $(MODULE) $(DESTDIR)/$$i/$(MODULE); \
		fi; \
	done
	cd bin && $(MAKE) $(MFLAGS) install

uninstall:
	PROG_BIN='$(XFS_BIN)'; for x in $$PROG_BIN; do \
		f=`echo $$x | sed '$(transform)'`; \
		rm -f $(DESTDIR)$(bindir)/$$f; \
	done
	for i in lkm subsys modules; do \
		if test -d /$$i; then \
			rm -f $(DESTDIR)/$$i/$(MODULE); \
		fi; \
	done
	cd bin && $(MAKE) $(MFLAGS) uninstall

@OSF1_TRUE@xfs_vopdefs.h: /usr/include/sys/vnode.h
@OSF1_TRUE@	sed -n -e 's/.*(\*vn_\([a-z_]*\).*/\1/p' /usr/include/sys/vnode.h | awk '{print "#define HAVE_VOP_" toupper($$1) " 1" }' > $@
@OSF1_TRUE@	-$(MKDIR) xfs 
@OSF1_TRUE@	test -d xfs && ( test -f xfs/xfs_vopdefs.h || $(LN_S) ../xfs_vopdefs.h xfs/xfs_vopdefs.h )

@OSF1_FALSE@xfs_vopdefs.h: stamp-xfs_vopdefs.h
@OSF1_FALSE@stamp-xfs_vopdefs.h: @VNODE_IF_H@
@OSF1_FALSE@	for i in /usr/include/sys/vnode_if.h vnode_if.h; do \
@OSF1_FALSE@	  if test -r $$i; then \
@OSF1_FALSE@	    awk '/^struct vop_[a-z]*_args/ { printf("#define HAVE_%s 1\n", toupper(substr($$2,1,length($$2)-5))); }' $$i > xfs_vopdefs.h; \
@OSF1_FALSE@	    break; \
@OSF1_FALSE@	  fi; \
@OSF1_FALSE@	done
@OSF1_FALSE@	-$(MKDIR) xfs
@OSF1_FALSE@	test -d xfs && ( test -f xfs/xfs_vopdefs.h || $(LN_S) ../xfs_vopdefs.h xfs/xfs_vopdefs.h )
@OSF1_FALSE@	touch stamp-xfs_vopdefs.h

# try to create vnode_if.h (we only depend on this if this file is actually
# needed)

vnode_if.h: $(SYS)/kern/vnode_if.src
	-$(MKDIR) ../sys
	if test -f $(SYS)/kern/vnode_if.pl; then \
	  perl $(SYS)/kern/vnode_if.pl -h $(SYS)/kern/vnode_if.src; \
	elif test -f $(SYS)/kern/vnode_if.sh; then \
	  $(SHELL) $(SYS)/kern/vnode_if.sh $(SYS)/kern/vnode_if.src; \
	  if ! test -f vnode_if.h; then \
	    if test -f ../sys/vnode_if.h ;then \
	      ln -s ../sys/vnode_if.h vnode_if.h; \
            else \
              echo "unable to create vnode_if.h"; exit 1; \
            fi; \
          fi; \
	else \
	  echo "cannot find any vnode_if script"; exit 1; \
	fi

.c.o:
	$(CC) -c $(CPPFLAGS) $(DEFS) $(CFLAGS) $<

Makefile: Makefile.in ../../config.status
	cd ../.. ; CONFIG_FILES=xfs/bsd/Makefile CONFIG_HEADERS= $(SHELL) config.status

clean: doclean

# This is a workaround so subdirs can be made. 
# You can't have two command-sets for one target
doclean:
	$(RM) -f $(MODULE) *.o *~ vnode_if.h vnode_if.c xfs_vopdefs.h xfs/xfs_vopdefs.h stamp-xfs_vopdefs.h

mostlyclean: clean

distclean: clean

realclean: distclean

all clean mostlyclean distclean realclean:
	SUBDIRS='$(SUBDIRS)'; \
	for i in $$SUBDIRS; \
	do (cd $$i && $(MAKE) $(MFLAGS) $@); done

.PHONY: all load clean mostlyclean distclean realclean install uninstall

