# Comment/uncomment the following line to disable/enable build options
DEBUG = n
SMPSUPP = auto
MODVERSIONS = auto

CC = gcc

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

ifeq ($(SMPSUPP),auto)
#  SMPSUPP = $(shell if [ `grep processor /proc/cpuinfo | wc -l` -gt 1 ]; then echo "y" ; else echo "n"; fi)
  SMPSUPP = $(shell if grep -q 'define CONFIG_SMP' $(INCLUDEDIR)/linux/autoconf.h ; then echo "y" ; else echo "n"; fi)
endif

ifeq ($(MODVERSIONS),auto)
  MODVERSIONS = $(shell if grep -q 'define CONFIG_MODVERSIONS' $(INCLUDEDIR)/linux/autoconf.h ; then echo "y" ; else echo "n"; fi)
endif

ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DMEMTEST -DEMU10K1_DEBUG # "-O" is needed to expand inlines
else
  DEBFLAGS = -O2 
endif

CFLAGS = -D__KERNEL__ -DMODULE -Wall -Wstrict-prototypes -fomit-frame-pointer $(DEBFLAGS)
CFLAGS += -I$(INCLUDEDIR) -I.

ifeq ($(SMPSUPP),y)
  CFLAGS += -D__SMP__ 
endif

VER=$(shell uname -r)

ifeq ($(MODVERSIONS),y)
  CFLAGS += -DMODVERSIONS -include $(INCLUDEDIR)/linux/modversions.h
endif


TARGET = emu10k1
OBJS = $(TARGET).o
SRC = $(wildcard *.c)

all: .depend $(TARGET).o


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

install:
	mkdir -p /lib/modules/$(VER)/misc 
	install -c $(TARGET).o /lib/modules/$(VER)/misc
	/sbin/depmod -a $(VER)
	/sbin/modprobe -r emu10k1

clean:
	rm -f *.o *~ core .depend

depend .depend dep:
	@echo "Building with SMPSUPP=$(SMPSUPP)  MODVERSIONS=$(MODVERSIONS)"
	$(CC) $(CFLAGS) -M $(SRC) > $@


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