# -*-makefile-*-
#
# ident $Id: Makefile-module,v 1.1.1.1 2003/09/29 06:49:09 raven Exp $
#
# Makefile for the Linux 2.4 autofs4 kernel module
#

# Include configuration for this system
TOPDIR:= $(shell pwd)
include Makefile.conf

.PHONY: all install uninstall clean

# Common CFLAGS
CFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer

include $(TOPDIR)/Makefile.rules

MODDIR = $(INSTALLDIR)/fs/autofs4

CFLAGS := -I. -I./include $(CFLAGS)

ifeq ($(REDHAT), yes)
CFLAGS += -DREDHAT_KERNEL
endif

O_HDRS   = autofs_i.h
L_HDRS   = include/linux/auto_fs4.h include/linux/auto_fs.h
O_SRCS   = init.c root.c inode.c symlink.c waitq.c expire.c
O_OBJS   = init.o root.o inode.o symlink.o waitq.o expire.o

O_TARGET = autofs4.o

all: include-test config-test $(O_TARGET)

$(O_TARGET): $(O_OBJS)
	$(LD) -o $@ -r $^

$(O_OBJS): $(O_HDRS) $(L_HDRS)

BACKUP  = $(shell test -e $(MODDIR)/autofs4.o.orig || echo "-b --suffix=.orig")

install: all
	-@install -o root -g root -m 755 -d $(MODDIR)
	install -o root -g root -m 644 $(BACKUP) $(O_TARGET) $(MODDIR)
	-depmod -ae

uninstall:
	if test -e $(MODDIR)/autofs4.o.orig; then \
		mv -f $(MODDIR)/autofs4.o.orig $(MODDIR)/autofs4.o; \
	fi

.PHONY: include-test
include-test:
	@# INCLUDEDIR must point to a valid tree of header files.
	@#   We just test for one we know should be there and must
	@#   fail if it can't be found.
	@if ! test -e $(INCLUDEDIR)/linux/module.h; then \
		echo "ERROR: include files directory does not seem to be valid"; \
		exit 1; \
	fi

.PHONY: config-test
config-test:
	@# KERNELCFG must point to a valid kernel config file.
	@if ! (test -e $(KERNELCFG) -o -e $(KERNELDIR)/.config); then \
		echo "ERROR: kernel config file cannot be found"; \
		exit 1; \
	fi

clean:
	rm -f $(O_TARGET) $(O_OBJS) *.d .*.flags \#* *~
	-@rm -rf tmp
	-@rm -f tags
