#
# $Id: Makefile,v 1.19 1999/12/09 22:38:24 fox Exp $
#
# If you got the binary distribution and want to install the
# precompiled binaries, use
# make install.bin install.man
#
# Define this if you want to abort on resource dump error
#
PNPDUMPFLAGS += -DABORT_ONRESERR
#
# Define REALTIME if you want to run with realtime scheduling, this
# cuts down the isolation and configuration time for a single card
# from 6s to less than 100ms.
# NOTE though, if it hangs, no other process will get processor time.
# You can still use ^C to kill it though.
# This can only be used with recent kernels, and I have only tested
# it on Linux.2.0.10. It certainly won't work on 1.2.13.
# nanosleep only went into the kernel at 1.3.67, but whether it
# worked or not, I know not.
#
# Depending on your libraries, you may need to define the NEED*s.
# For libc-5.2.18, you'll need them both.
# For libc-5.3.12, I suspect you may not want NEEDNANOSLEEP.
# For glibc-2.0, you don't want NEEDSETSCHEDULER or NEEDNANOSLEEP, and
#                the code will ignore these defines if it detects
#                glibc 2.0 or later.
# For cross-compiling for DOS, you don't want NEEDSETSCHEDULER or NEEDNANOSLEEP, and
#                the code will ignore these defines if it detects
#                glibc 2.0 or later. You will need NEEDSNPRINTF though.
#
#PNPFLAGS += -DREALTIME -DNEEDSETSCHEDULER -DNEEDNANOSLEEP -DNEEDSNPRINTF
PNPFLAGS += -DREALTIME -DNEEDSETSCHEDULER
#
# Linux on ALPHA/AXP should already define this, but just in case..
#
#PNPFLAGS += -D_AXP_
#
# Set this if cross-compiling for DOS using djgpp
#
#CC = gcc -b i386-go32-msdos

prefix          =
installdir      =
# insert the path to your non-root install directory above (if you need one)
installprefix   =       $(installdir)/$(prefix)

CONFDIR = etc
GONEFILE = isapnp.gone

INSTALLBINDIR = $(installprefix)sbin
INSTALLLIBDIR = $(installprefix)usr/lib
INSTALLMANDIR = $(installprefix)usr/man
INSTALLSHAREDIR=$(installprefix)usr/share
INSTALLSCRIPTDIR=$(INSTALLSHAREDIR)/pnp/config-scripts/isa

CFLAGS = -O2 -Wall -DYY_NO_UNPUT $(PNPDUMPFLAGS) $(PNPFLAGS) -DGONEFILE=\"/$(CONFDIR)/$(GONEFILE)\"

all:	pnpdump isapnp

install: pnpdump isapnp install.bin install.lib install.man
	mkdir -p $(INSTALLSCRIPTDIR) $(INSTALLSHAREDIR) $(INSTALLMANDIR) $(INSTALLBINDIR)
	install config-scripts/* $(INSTALLSCRIPTDIR)/
	if test ! -f $(installdir)/$(CONFDIR)/$(GONEFILE);\
	then\
		install $(GONEFILE) $(installdir)/$(CONFDIR);\
		echo -e "\nSample preallocated resource file copied to $(installdir)/$(CONFDIR)/$(GONEFILE), edit to suit\n";\
	fi

install.bin:
	mkdir -p $(INSTALLBINDIR)
	install -s -m 0755 pnpdump $(INSTALLBINDIR)
	install -s -m 0755 isapnp $(INSTALLBINDIR)

install.lib:
	mkdir -p $(INSTALLLIBDIR)
	install -m 0644 libisapnp.a $(INSTALLLIBDIR)

install.man:
	mkdir -p $(INSTALLMANDIR)
	install -m 0644 isapnp.8 $(INSTALLMANDIR)/man8
	install -m 0644 isapnp.conf.5 $(INSTALLMANDIR)/man5
	install -m 0644 pnpdump.8 $(INSTALLMANDIR)/man8

TAGS: pnpdump.c resource.c pnp-select.c pnp.h isapnp.y realtime.c \
	res-access.c pnp-access.c callbacks.c demo.c demo2.c iopl.c \
	release.c mysnprtf.c
	etags $^

PNPDUMPOBJS = pnpdump.o
DEMOOBJS = demo.o
DEMO2OBJS = demo2.o

pnpdump: $(PNPDUMPOBJS) libisapnp.a
	$(CC) $(LDFLAGS) $(TARGET_ARCH) $(PNPDUMPOBJS) -o $@ -L. -lisapnp

demo: $(DEMOOBJS) libisapnp.a
	$(CC) $(LDFLAGS) $(TARGET_ARCH) $(DEMOOBJS) -o $@ -L. -lisapnp

demo2: $(DEMO2OBJS) libisapnp.a
	$(CC) $(LDFLAGS) $(TARGET_ARCH) $(DEMO2OBJS) -o $@ -L. -lisapnp

# demo,demo2 are not built by make all, because they are not necessary for
# normal usage.

libisapnp.a: realtime.o res-access.o pnp-access.o pnp-select.o callbacks.o \
	iopl.o resource.o cardinfo.o release.o mysnprtf.o
	ar rc libisapnp.a $^
	ranlib libisapnp.a

pnpdump.o: pnp.h Makefile release.h realtime.h res-access.h iopl.h

realtime.o: release.h realtime.h callbacks.h

res-access.o: pnp.h release.h res-access.h mysnprtf.h

resource.o: resource.h pnp.h callbacks.h errenum.h mysnprtf.h

pnp-select.o: resource.h pnp.h

callbacks.o: release.h callbacks.h

mysnprtf.o: callbacks.h mysnprtf.h

iopl.o: iopl.h callbacks.h

cardinfo.o: res-access.h resource.h pnp.h errenum.h

isapnp: isapnp.o libisapnp.a

isapnp.c: isapnp.y pnp.h Makefile
	flex -i -t isapnp.y > isapnp.c

isapnp.o: pnp.h Makefile release.h

isapnp.8.html: isapnp.8
	man2html isapnp.8

pnpdump.8.html: pnpdump.8
	man2html pnpdump.8

isapnp.conf.5.html: isapnp.conf.5
	man2html isapnp.conf.5

html: isapnp.8.html pnpdump.8.html isapnp.conf.5.html

semiclean:
	rm -f *.o *.a *.so isapnp.c *~

clean:
	rm -f *.o *.a *.so isapnp.c *~ pnpdump isapnp demo demo2

dosclean: clean
	rm -f *.exe

spotless: clean
	rm -f pnpdump isapnp demo demo2 *.exe

