#
# Makefile (pxc: driver for ImageNation's pxc200)
#
# Copyright 1998   rubini@linux.it
#
##########
#

# Comment/uncomment the following line to enable/disable debugging
#DEBUG = y

# Change it here or specify it on the "make" commandline
INCLUDEDIR = /usr/include


INSTALL = install -c
INSTALLBIN = $(INSTALL) -m 755
INSTALLLIB = $(INSTALL) -m 644

ifndef PREFIX
  PREFIX = /usr/local
endif

MODDIR = /lib/modules/$(shell uname -r)/misc
LIBDIR = $(PREFIX)/lib
BINDIR = $(PREFIX)/bin
INCDIR = $(PREFIX)/include
MANDIR = $(PREFIX)/man
MAN1DIR = $(MANDIR)/man1
MAN3DIR = $(MANDIR)/man3
MAN4DIR = $(MANDIR)/man4

INFODR = $(PREFIX)/info

############## no more editing...

INSTALLDIRS =  $(MODDIR) $(BINDIR) $(LIBDIR) $(INCDIR) \
        $(MANDIR) $(MAN1DIR) $(MAN3DIR) $(MAN4DIR)

CLIENTOBJS = pxc_status.o pxc_control.o pxc_show.o mapper.o pxc_grab.o
CLIENTS =  $(CLIENTOBJS:.o=)  
SCRIPTS = pxc_load pxc_unload pxc_xgrab
LIBOBJS = empty.o
LIBRARY = libpxc.a

ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DPX_DEBUG # "-O" is needed to expand inlines
  LDFLAGS =
else
  DEBFLAGS =  -O3 -fomit-frame-pointer
  LDFLAGS = -s
endif

%: %.o
	$(CC) $(CFLAGS) $^ -o $@ -L. 
#-l$(TARGET)

%.i: %.c
	$(CC) $(CFLAGS) -E $^ -o $@

%.S: %.c
	$(CC) $(CFLAGS) -S $^ -o $@

CFLAGS = -Wall $(DEBFLAGS)
CFLAGS += -I$(INCLUDEDIR)

# Extract version number from headers.
VER = $(shell awk -F\" '/REL/ {print $$2}' $(INCLUDEDIR)/linux/version.h)

TARGET = pxc
OBJS = $(TARGET).o
SRC = main.c allocator.c

# force make depend
ifneq (.depend,$(wildcard .depend))
all: depend
endif



all: $(TARGET).o $(LIBRARY) $(CLIENTOBJS) $(CLIENTS) check-cfg

$(TARGET).o: $(SRC:.c=.o)
	$(LD) -r $^ -o $@

ifndef RANLIB
  RANLIB = ranlib
endif

$(LIBRARY): $(LIBOBJS)
	$(AR) r $(LIBRARY) $(LIBOBJS)
	$(RANLIB) $(LIBRARY)

install: all
	mkdir -p /lib/modules/$(VER)/misc /lib/modules/misc /usr/local/bin
	install -c $(TARGET).o /lib/modules/$(VER)/misc
	install -c $(TARGET).o /lib/modules/misc
	@-depmod -a 2> /dev/null
	install -c $(CLIENTS) $(SCRIPTS) /usr/local/bin

clean:
	rm -f *.o *.i *.S *~ */*~ */*/*~ core $(LIBRARY) $(CLIENTS)

tar:
	n=`basename \`pwd\``; cd ..; tar cvf - $$n | gzip > $$n.tar.gz

distrib: clean tar

depend dep:
	$(CC) -MM *.c > .depend

DEPEND DEP:
	$(CC) -M *.c > .depend

check-cfg:
	@grep define.\*CONFIG_PCI $(INCLUDEDIR)/linux/autoconf.h > /dev/null \
	|| echo "********** Warning: CONFIG_PCI undefined: insmod will fail" \
	     "with this kernel"


ifeq (.depend,$(wildcard .depend))
include .depend
endif


