PREFIX      =
SBINDIR     = $(PREFIX)/sbin
MANDIR      = $(PREFIX)/usr/man
CONFIG_FILE = $(PREFIX)/etc/devfsd.conf

nsl_libs := $(wildcard /lib/libnsl.*)
ifneq ($(nsl_libs),)
LIBS := -lnsl
endif

all:	devfsd


OBJECTS = devfsd.o expression.o compat_name.o

ifdef KERNEL_DIR
CFLAGS = -O2 -I. -I$(KERNEL_DIR)/include -Wall $(CEXTRAS)
else
CFLAGS = -O2 -I. -Wall $(CEXTRAS)
endif

devfsd:	$(OBJECTS)
	cc -O2 -o devfsd $(OBJECTS) $(CFLAGS) -export-dynamic -ldl $(LIBS)

install: devfsd
	@if fgrep -q "Generic section: do not change" /etc/modules.conf ; then\
		echo "First remove the generic devfs entries from /etc/modules.conf"; exit 1; \
	fi
	rm -f $(SBINDIR)/devfsd
	install -s devfsd $(SBINDIR)/devfsd
	-rm -f $(MANDIR)/*/devfsd.*
	cp -p devfsd.8 $(MANDIR)/man8
	cp -p devfsd.conf.5 $(MANDIR)/man5
	if [ ! -e $(CONFIG_FILE) ]; then cp -p devfsd.conf $(CONFIG_FILE); fi
	@echo "Installing /etc/modules.devfs"
	@sed "s/DEVFSD-VERSION/`grep '#define DEVFSD_VERSION' version.h | cut -d'"' -f 2`/" modules.devfs > $(PREFIX)/etc/modules.devfs

clean:
	-rm -f *~ *.o *.orig *.rej


distclean: clean
	-rm -f devfsd


# Dependencies: made by hand
devfsd.o: devfsd.h version.h
